NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

M2CVD: Multi-Model Collaboration for Code Vulnerability Detection

Ziliang Wang, Ge Li, Jia Li, Meng Yan, Yingfei Xiong, Zhi JinarXiv 2024 · DOI

Introduction

Automated code vulnerability detection is a critical component of modern software security. However, existing approaches often struggle to balance project-specific efficiency with deep semantic understanding. M2CVD (Multi-Model Collaborative Vulnerability Detection) addresses this by orchestrating a collaboration between specialized code models and Large Language Models (LLMs). By leveraging a feedback loop to generate and refine natural language descriptions of vulnerabilities, M2CVD significantly enhances the accuracy and interpretability of security audits.

The Challenge of Code Vulnerability Detection

Current vulnerability detection methods typically fall into two categories, each with distinct limitations:

  1. Specialized Code Models: Models like CodeBERT and UniXcoder are efficient and easy to fine-tune on specific codebases. However, they often function as "black boxes," learning superficial correlations (e.g., variable names) rather than the underlying logic, leading to a "semantic gap."
  2. Large Language Models (LLMs): Models like ChatGPT possess superior reasoning capabilities but are prohibitively expensive to fine-tune for specific projects. They also suffer from "alignment issues," frequently producing false positives because they lack context regarding a project's specific coding standards or business logic.
Comparison of existing vulnerability detection methods: (a) fine-tuning based and (b) prompting based.

The goal of M2CVD is to bridge this gap, providing specialized models with the semantic depth of an LLM without the overhead of full-scale LLM fine-tuning.

The M2CVD Framework

The M2CVD framework operates through a structured three-phase workflow designed to harmonize the strengths of both model types.

The three-phase workflow of M2CVD: Initial Detection, Refinement, and Integrated Detection.

Phase I: Initial Detection and Description

In the first phase, a fine-tuned specialized code model and an LLM (accessed via API) independently analyze the target code. If the LLM identifies a potential vulnerability, it generates a natural language description explaining the flaw.

Phase II: Vulnerability Description Refinement

The "secret sauce" of M2CVD lies in its collaborative refinement process. When the specialized model and the LLM disagree, a second interaction is triggered. The LLM is prompted with the expert model's disagreement, forcing it to re-evaluate its initial judgment. This grounding mechanism reduces hallucinations and aligns the LLM's reasoning with the project's specific context.

Phase III: Integrated Vulnerability Detection

The refined natural language descriptions are appended to the original code snippets, creating "semantically enriched" data. This data is then used to train a final Validation Model. By learning from both the raw code and the expert-refined explanation, the model captures the actual logic of the vulnerability rather than just statistical patterns.

Experimental Evaluation

The researchers evaluated M2CVD using two real-world benchmarks:

  • Devign: A balanced dataset featuring C/C++ functions from major open-source projects like QEMU and FFmpeg.
  • Reveal: A more realistic, imbalanced dataset (10:1 safe-to-vulnerable ratio) derived from the Linux kernel and Chromium, representing the "needle in a haystack" challenge of real-world security.

M2CVD consistently outperformed state-of-the-art baselines. On the Devign dataset, it achieved 68.33% accuracy, surpassing standalone UniXcoder (64.82%). More impressively, on the challenging Reveal dataset, M2CVD reached an F1-score of 48.10%, a significant improvement over UniXcoder’s 39.47%.

Key Insights

  • Semantics as a Feature: Natural language descriptions serve as a superior bridge for learning compared to binary labels. Understanding why code is vulnerable allows models to generalize better.
  • Collaborative Correction: LLMs tend to be overly aggressive in detection. Informing the LLM of a specialized model's judgment effectively "tempers" its output, reducing false positives.
  • The GPT-4o Paradox: High-end models like GPT-4o can be too sensitive, initially flagging nearly all code as vulnerable. The M2CVD refinement process is essential to making these powerful models practical for security tasks.

Conclusion and Future Work

While M2CVD offers a powerful new paradigm, it faces challenges regarding inference costs due to API dependencies and limited context windows for very long functions. Future research will focus on optimizing prompt engineering (e.g., Chain-of-Thought) and expanding the framework's ability to handle cross-file vulnerabilities. Nonetheless, M2CVD demonstrates that the future of code security lies in the collaborative synergy between specialized efficiency and general-purpose intelligence.

Summary updated

BibTeX
@misc{wang2024m,
  author = {Ziliang Wang and Ge Li and Jia Li and Meng Yan and Yingfei Xiong and Zhi Jin},
  title = {{M2CVD: Multi-Model Collaboration for Code Vulnerability Detection}},
  year = {2024},
  eprint = {2406.05940},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.05940},
}
Figure