[Paper Review] To Err is Machine: Vulnerability Detection Challenges LLM Reasoning
The paper evaluates 11 state-of-the-art LLMs on vulnerability detection, finding poor reasoning performance (0.5–0.63 Balanced Accuracy) and frequent errors in locating and explaining vulnerabilities, with limited alignment to human experts.
In this paper, we present a challenging code reasoning task: vulnerability detection. Large Language Models (LLMs) have shown promising results in natural-language and math reasoning, but state-of-the-art (SOTA) models reported only 54.5% Balanced Accuracy in our vulnerability detection evaluation, even those models pre-trained on large amounts of source code. Our error analysis on LLM responses shows that the models struggle to reason about the code semantics relevant to identifying vulnerabilities, especially subtle semantic differences caused by small textual changes. We explored prominent models and training settings to understand their effects on vulnerability detection performance -- including better prompts, larger models, more pre-training data, and fine-tuning -- but none led to significant improvements. This raises the question of whether simply scaling training data and model size will allow us to "solve" complex code reasoning tasks like vulnerability detection, or if a fundamental shift in modeling and training techniques is required. We also explored adding domain knowledge to prompts; although it helped certain models understand some code semantics, vulnerability detection requires multi-step reasoning, and these models still failed in steps, such as reasoning about variable relations. Our results suggest that new models, new training methods, or more execution-specific pretraining data may be needed to conquer vulnerability detection. We speculate that auto-regressive pre-training on source code may not effectively extract code semantics, especially on the current pretraining mixtures, in which execution data is scarce. Success on vulnerability detection as a code reasoning task can benefit many areas of software engineering such as debugging, test input generation, and program repair. Our code and data are available at https://doi.org/10.6084/m9.figshare.27368025.
Motivation & Objective
- Assess the capability of state-of-the-art LLMs to detect software vulnerabilities from code.
- Investigate how prompting techniques (basic, in-context, chain-of-thought) affect vulnerability detection.
- Characterize error types in LLM explanations of vulnerabilities.
- Compare LLM localization of vulnerabilities with human performance on a standard benchmark.
Proposed method
- Survey 11 code-generation–oriented LLMs and evaluate them with five prompt templates, including three novel techniques.
- Use the SVEN dataset (100 function pairs of buggy and fixed code) to create a binary classification task for vulnerability detection.
- Systematically search for high-performing prompts and configurations, including Basic, IC-Random, IC-Embedding, CoT-CVE, and CoT-SA prompts.
- Analyze 287 LLM responses to categorize errors into Code Understanding, Hallucination/Memorization/Repetition, Logic, and Common Knowledge.
- Evaluate fault localization on the DbgBench benchmark and compare with human performance.
Experimental results
Research questions
- RQ1RQ1: What are the most successful and least successful prompt designs for LLM-based vulnerability detection?
- RQ2RQ2: How well do state-of-the-art LLMs perform on vulnerability detection?
- RQ3RQ3: What kinds of errors do LLMs make when explaining the vulnerabilities?
- RQ4RQ4: How do LLMs compare to human developers for localizing vulnerabilities?
Key findings
- Balanced Accuracy of 0.5–0.63 across models, close to random guessing.
- 76% of buggy-vs-fixed pairs could not be distinguished by the models.
- LLMs correctly located only 6 of 27 DbgBench bugs; GPT-3 performed best with 4/27.
- 57% of responses contained errors in code understanding, logic, or common knowledge, with bounds/null checks frequently misidentified.
- Explanations showed substantial drops in accuracy when reporting bug location, type, and root cause (18–100% drop).
- Human performance on localization in DbgBench indicates higher reliability in fault localization compared to the evaluated LLMs.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.