用上下文增强的训练数据和强化学习优化,提升代码漏洞检测的准确性。
VULPO: Context-Aware Vulnerability Detection via On-Policy LLM Optimization
- 构建含上下文信息的漏洞推理数据集,支持更精准的漏洞分析。
- 提出VULPO框架,通过多维奖励机制提升漏洞定位与因果推理能力。
- 在小模型上实现超越大模型的漏洞检测效果,适合安全开发场景。
大型语言模型(LLMs)在漏洞检测(VD)中展现出巨大潜力,但真实代码库中的漏洞检测需处理复杂的上下文交互。现有方法受限于数据集缺乏完整上下文信息与高质量推理监督,且优化方式依赖粗粒度的结果导向信号,无法建模漏洞推理过程。为此,我们构建了ContextVul数据集,补充高精度函数级漏洞基准与仓库级上下文信息,并标注了精心设计的漏洞推理轨迹。基于此,我们提出两阶段优化框架:轻量级冷启动监督微调,随后采用漏洞自适应的在策略优化(VULPO)。VULPO引入多维度奖励,联合评估漏洞识别、相关位置定位与因果推理质量,并采用难度自适应奖励缩放以缓解奖励欺骗,提升强化学习效果。大量实验表明,VULPO在上下文感知漏洞检测中表现卓越。我们的VULPO-4B是首个专用漏洞推理大模型,相比Qwen3-4B在Pairwise Pass@1上提升203%,性能媲美150%更大的DeepSeek-V3.1。
原文摘要 · Abstract (English)
Large language models (LLMs) have recently shown strong potential in vulnerability detection (VD). However, accurately detecting vulnerabilities in real-world repositories requires reasoning over complex contextual interactions. Existing LLM-based VD approaches remain limited because current datasets lack complete contextual information and high-quality reasoning supervision, while existing optimization methods primarily rely on coarse outcome-centric supervision signals that fail to model the vulnerability reasoning process. To address these limitations, we first construct ContextVul, a new dataset that augments high-quality function-level vulnerability benchmarks with repository-level contextual information and curated vulnerability reasoning traces. Building upon ContextVul, we introduce a two-stage optimization framework consisting of lightweight cold-start supervised fine-tuning followed by vulnerability-adaptive on-policy optimization (VULPO). VULPO incorporates multidimensional rewards that jointly evaluate vulnerability identification, vulnerability-relevant localization, and causal reasoning quality, along with difficulty-adaptive reward scaling to mitigate reward hacking and improve RL effectiveness. Extensive experiments demonstrate the superiority of VULPO for context-aware VD. Our VULPO-4B, the first specialized vulnerability reasoning LLM, substantially outperforms existing VD baselines, improving Pairwise Pass@1 by 203% relative to Qwen3-4B and achieving competitive performance against a 150% larger-scale LLM, DeepSeek-V3.1.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。