[Paper Review] Towards Explainable Vulnerability Detection with Large Language Models
This paper proposes LLMVulExp, a framework that leverages fine-tuned large language models (LLMs) to detect software vulnerabilities and generate detailed explanations—including root cause, location, and repair suggestions. Using specialized fine-tuning with LoRA and prompt-based annotation, LLMVulExp achieves over 90% F1 score on the SeVC dataset, demonstrating strong performance in both detection and explainability.
Software vulnerabilities pose significant risks to the security and integrity of software systems. Although prior studies have explored vulnerability detection using deep learning and pre-trained models, these approaches often fail to provide the detailed explanations necessary for developers to understand and remediate vulnerabilities effectively. The advent of large language models (LLMs) has introduced transformative potential due to their advanced generative capabilities and ability to comprehend complex contexts, offering new possibilities for addressing these challenges. In this paper, we propose LLMVulExp, an automated framework designed to specialize LLMs for the dual tasks of vulnerability detection and explanation. To address the challenges of acquiring high-quality annotated data and injecting domain-specific knowledge, LLMVulExp leverages prompt-based techniques for annotating vulnerability explanations and finetunes LLMs using instruction tuning with Low-Rank Adaptation (LoRA), enabling LLMVulExp to detect vulnerability types in code while generating detailed explanations, including the cause, location, and repair suggestions. Additionally, we employ a Chain-of-Thought (CoT) based key code extraction strategy to focus LLMs on analyzing vulnerability-prone code, further enhancing detection accuracy and explanatory depth. Our experimental results demonstrate that LLMVulExp achieves over a 90% F1 score on the SeVC dataset, effectively combining high detection accuracy with actionable and coherent explanations. This study highlights the feasibility of utilizing LLMs for real-world vulnerability detection and explanation tasks, providing critical insights into their adaptation and application in software security.
Motivation & Objective
- Address the lack of detailed explanations in existing vulnerability detection methods, which limits understanding and mitigation.
- Explore the potential of large language models (LLMs) to jointly detect and explain software vulnerabilities.
- Develop a framework that enables LLMs to generate comprehensive, context-aware explanations beyond simple detection.
- Investigate the impact of fine-tuning quality, model size, and reasoning strategies like Chain-of-Thought (CoT) on vulnerability explanation performance.
- Propose new evaluation metrics and an automated LLM-based review method to assess the quality of generated vulnerability explanations.
Proposed method
- Use prompt-based techniques to annotate open-source vulnerability datasets with structured explanatory information (location, cause, fix) using proprietary LLMs.
- Apply Low-Rank Adaptation (LoRA) to fine-tune code-specific LLMs (e.g., CodeLlama-13B-Instruct) for vulnerability detection and explanation.
- Integrate Chain-of-Thought (CoT) prompting to guide LLMs in focusing on vulnerability-prone code segments during reasoning.
- Design and implement a multi-metric evaluation framework combining manual and automated LLM-based reviews to assess explanation quality (accuracy, clarity, constructiveness).
- Utilize two benchmark datasets—SeVC and DiverseVul—for comprehensive evaluation across multiple vulnerability types and model sizes.
- Employ a hybrid annotation pipeline combining LLM-generated initial labels with expert review to ensure high-quality training data.
Experimental results
Research questions
- RQ1Can LLMs effectively detect multiple types of software vulnerabilities with high precision and recall when specialized fine-tuning is applied?
- RQ2To what extent can LLMs generate meaningful, accurate, and actionable explanations (e.g., root cause, fix) for detected vulnerabilities?
- RQ3How does the performance of LLMVulExp vary across different LLM architectures and sizes (e.g., 7B, 13B, 8B)?
- RQ4Does the use of Chain-of-Thought (CoT) prompting improve the model’s ability to focus on and explain vulnerability-prone code?
- RQ5How effective are the proposed evaluation metrics and automated LLM-based review method in assessing the quality of generated vulnerability explanations?
Key findings
- LLMVulExp achieves an F1 score exceeding 90% on the SeVC dataset for multi-type vulnerability detection, demonstrating high detection accuracy.
- The framework successfully generates detailed explanations including vulnerability cause, location, and repair suggestions, with human evaluators reporting substantial agreement (Cohen’s Kappa = 0.76).
- Performance remains strong across different LLM sizes, with CodeLlama-13B-Instruct and CodeLlama-7B-Instruct outperforming Llama3-8B-Instruct in detection tasks.
- Chain-of-Thought (CoT) prompting enhances the model’s ability to focus on vulnerable code segments, improving reasoning and explanation quality.
- The proposed evaluation framework, combining manual and automated LLM-based reviews, provides a reliable and scalable method for assessing explanation quality.
- High-quality annotations are critical for effective fine-tuning, and a hybrid annotation approach (LLM + expert review) ensures consistency and accuracy in training data.
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.