arXiv:2504.04699cs.SEcs.AI2025-04被引 13

用强化学习教小模型精准识别漏洞并生成可信解释。

R2Vul: Learning to Reason about Software Vulnerabilities with Reinforcement Learning and Structured Reasoning Distillation

  • 结合强化学习与结构化推理蒸馏,提升小模型漏洞检测能力。
  • 1.5B模型性能超32B教师模型和Claude-4-Opus等主流大模型。
  • 支持多语言,且可降低不平衡数据下的误报率,适合安全研发使用。

大型语言模型在软件漏洞检测中表现良好,但其推理能力仍不可靠。本文提出R2Vul,结合从AI反馈中进行强化学习(RLAIF)与结构化推理蒸馏,训练小型代码LLM在检测漏洞的同时生成安全相关解释。不同于以往的思维链与指令微调方法,R2Vul通过RLAIF奖励合理解释,抑制表面合理但错误的推断,从而实现更精准的检测与高质量推理生成。为支持RLAIF,我们构建了首个多语言漏洞检测偏好数据集,包含C#、JavaScript、Java、Python和C共18,000条高质量样本。我们在五种编程语言上评估R2Vul,对比四款静态分析工具、八种先进LLM基线及多种微调方法。结果表明,1.5B规模的R2Vul模型超越32B教师模型及包括Claude-4-Opus在内的领先商用大模型。此外,引入轻量校准步骤,有效降低不同数据分布下误报率。定性分析显示,无论是模型还是人工评估者,均一致认为R2Vul的推理质量优于其他基于推理的基线。

原文摘要 · Abstract (English)

Large language models (LLMs) have shown promising performance in software vulnerability detection, yet their reasoning capabilities remain unreliable. We propose R2Vul, a method that combines reinforcement learning from AI feedback (RLAIF) and structured reasoning distillation to teach small code LLMs to detect vulnerabilities while generating security-aware explanations. Unlike prior chain-of-thought and instruction tuning approaches, R2Vul rewards well-founded over deceptively plausible vulnerability explanations through RLAIF, which results in more precise detection and high-quality reasoning generation. To support RLAIF, we construct the first multilingual preference dataset for vulnerability detection, comprising 18,000 high-quality samples in C\#, JavaScript, Java, Python, and C. We evaluate R2Vul across five programming languages and against four static analysis tools, eight state-of-the-art LLM-based baselines, and various fine-tuning approaches. Our results demonstrate that a 1.5B R2Vul model exceeds the performance of its 32B teacher model and leading commercial LLMs such as Claude-4-Opus. Furthermore, we introduce a lightweight calibration step that reduces false positive rates under varying imbalanced data distributions. Finally, through qualitative analysis, we show that both LLM and human evaluators consistently rank R2Vul model's reasoning higher than other reasoning-based baselines.

漏洞检测强化学习代码推理小模型

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。