Skip to main content
QUICK REVIEW

[论文解读] Towards Explainable Vulnerability Detection with Large Language Models

Qiheng Mao, Zhenhao Li|arXiv (Cornell University)|Jun 14, 2024
Topic ModelingComputer Science被引用 3
一句话总结

本文提出 LLMVulExp 框架,利用微调后的大型语言模型(LLMs)检测软件漏洞,并生成详细解释——包括根本原因、位置和修复建议。通过使用 LoRA 和基于提示的注释进行专业化微调,LLMVulExp 在 SeVC 数据集上的 F1 分数超过 90%,在漏洞检测与可解释性方面均表现出色。

ABSTRACT

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.

研究动机与目标

  • 解决现有漏洞检测方法缺乏详细解释的问题,从而限制对漏洞的理解与缓解。
  • 探索大型语言模型(LLMs)在联合检测与解释软件漏洞方面的潜力。
  • 开发一种框架,使 LLM 能够生成超越简单检测的全面、上下文感知的解释。
  • 研究微调质量、模型规模以及推理策略(如思维链 CoT)对漏洞解释性能的影响。
  • 提出新的评估指标和基于 LLM 的自动化评审方法,以评估生成的漏洞解释质量。

提出的方法

  • 使用基于提示的技术,利用专有 LLM 对开源漏洞数据集进行注释,结构化地标注解释信息(位置、原因、修复方法)。
  • 应用低秩适应(LoRA)对特定代码的 LLM(如 CodeLlama-13B-Instruct)进行微调,以实现漏洞检测与解释。
  • 集成思维链(CoT)提示,引导 LLM 在推理过程中聚焦于易产生漏洞的代码段。
  • 设计并实现一个多指标评估框架,结合人工与基于 LLM 的自动化评审,以评估解释质量(准确性、清晰度、建设性)。
  • 使用两个基准数据集——SeVC 和 DiverseVul——进行全面评估,涵盖多种漏洞类型与模型规模。
  • 采用混合注释流程,结合 LLM 生成的初始标签与专家评审,以确保高质量的训练数据。

实验结果

研究问题

  • RQ1在应用专业化微调时,LLM 是否能有效检测多种类型的软件漏洞,且具备高精确率与高召回率?
  • RQ2LLM 在检测到漏洞后,能在多大程度上生成有意义、准确且可操作的解释(如根本原因、修复方法)?
  • RQ3LLMVulExp 的性能在不同 LLM 架构与规模(如 7B、13B、8B)之间如何变化?
  • RQ4使用思维链(CoT)提示是否能提升模型聚焦并解释易产生漏洞代码段的能力?
  • RQ5所提出的评估指标与基于 LLM 的自动化评审方法在评估生成漏洞解释质量方面有多有效?

主要发现

  • LLMVulExp 在 SeVC 数据集上实现超过 90% 的 F1 分数,用于多类型漏洞检测,表现出极高的检测准确率。
  • 该框架成功生成包括漏洞原因、位置和修复建议在内的详细解释,人工评估者报告显著一致性(Cohen’s Kappa = 0.76)。
  • 在不同 LLM 规模下性能依然强劲,其中 CodeLlama-13B-Instruct 和 CodeLlama-7B-Instruct 在检测任务中优于 Llama3-8B-Instruct。
  • 思维链(CoT)提示增强了模型聚焦于易产生漏洞代码段的能力,提升了推理与解释质量。
  • 所提出的评估框架结合人工与基于 LLM 的自动化评审,提供了一种可靠且可扩展的解释质量评估方法。
  • 高质量注释对有效微调至关重要,混合注释方法(LLM + 专家评审)确保了训练数据的一致性与准确性。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。