R2Vul: Learning to Reason about Software Vulnerabilities with Reinforcement Learning and Structured Reasoning Distillation
On the map: LLM reasoning → Reasoning for agents, planning and code
also in 2 more
Abstract (arXiv)
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.
Key facts. Cited by 7 papers in the map (data through 14 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 33 of its 61 references that are in the map. First posted on arXiv 7 Apr 2025.
Builds on
33 of 61 references.
Closest ancestors · 3
Same direction, newest first
- 2024Qwen2.5-Coder Technical Report18 Sep
- 2024To Err is Machine: Vulnerability Detection Challenges LLM Reasoning25 Mar
- 2024LLM4Vuln: A Unified Evaluation Framework for Decoupling and Enhancing LLMs' Vulnerability Reasoning29 Jan
Other references · 30
- 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,380
- 2024DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Modelscited by 9,379
- 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,330
- 2022Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedbackcited by 3,720
- 2019Fine-Tuning Language Models from Human Preferencescited by 2,150
- 2017Towards A Rigorous Science of Interpretable Machine Learningcited by 1,416
- 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Modelscited by 1,407
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2023Open Problems and Fundamental Limitations of Reinforcement Learning from Human Feedbackcited by 759
- 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 744
- 2023WizardMath: Empowering Mathematical Reasoning for Large Language Models via Reinforced Evol-Instructcited by 625
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
18 more
- 2023Zephyr: Direct Distillation of LM Alignmentcited by 506
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
- 2023LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarkscited by 97
- 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 68
- 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
- 2024CodeUltraFeedback: An LLM-as-a-Judge Dataset for Aligning Large Language Models to Coding Preferencescited by 57
- 2024Finetuning Large Language Models for Vulnerability Detectioncited by 40
- 2024CodeDPO: Aligning Code Models with Self Generated and Verified Source Codecited by 34
- 2024Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilitiescited by 31
- 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
- 2024Does RLHF Scale? Exploring the Impacts From Data, Model, and Methodcited by 23
- 2024Comparison of Static Application Security Testing Tools and Large Language Models for Repo-level Vulnerability Detectioncited by 18
- 2024Security Vulnerability Detection with Multitask Self-Instructed Fine-Tuning of Large Language Modelscited by 14
- 2023Transformer-based Vulnerability Detection in Code at EditTime: Zero-shot, Few-shot, or Fine-tuning?cited by 13
- 2024Investigating Large Language Models for Code Vulnerability Detection: An Experimental Studycited by 12
- 2024Your Instructions Are Not Always Helpful: Assessing the Efficacy of Instruction Fine-tuning for Software Vulnerability Detectioncited by 6
- 2024CleanVul: Automatic Function-Level Vulnerability Detection in Code Commits Using LLM Heuristicscited by 4
- 2024Towards Explainable Vulnerability Detection with Large Language Modelscited by 3
Built on by
Citing papers per year: 2025: 2; 2026: 5.
7 papers.
- 2025VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specificationscited by 4
- 2026From SFT to RL: Demystifying the Post-Training Pipeline for LLM-based Vulnerability Detectioncited by 4
- 2025VULPO: Context-Aware Vulnerability Detection via On-Policy LLM Optimizationcited by 3
- 2026DREA: Decoupled Reasoning and Exploration Agents for Repository-Level Vulnerability Detectioncited by 3
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
- 2026VulReaD: Knowledge-Graph-guided Software Vulnerability Reasoning and Detectioncited by 0
- 2026Neuro-Symbolic Reasoning for Vulnerability Detectioncited by 0
- 2026DREA: Decoupled Reasoning and Exploration Agents for Repository-Level Vulnerability Detection15 Jul 2026
- 2026Neuro-Symbolic Reasoning for Vulnerability Detection4 Jul 2026
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoring1 May 2026
- 2026From SFT to RL: Demystifying the Post-Training Pipeline for LLM-based Vulnerability Detection15 Feb 2026
- 2026VulReaD: Knowledge-Graph-guided Software Vulnerability Reasoning and Detection11 Feb 2026
- 2025VULPO: Context-Aware Vulnerability Detection via On-Policy LLM Optimization14 Nov 2025
- 2025VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specifications6 Nov 2025
Similar, not cited
Close in wording, no citation either way
- 2026Three Heads Are Better Than One: A Multi-perspective Reasoning Framework for Enhanced Vulnerability Detection
- 2025Boosting Vulnerability Detection of LLMs via Curriculum Preference Optimization with Synthetic Reasoning Data
- 2025VulnLLM-R: Specialized Reasoning LLM with Agent Scaffold for Vulnerability Detection
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
- 2025Improving LLM Reasoning for Vulnerability Detection via Group Relative Policy Optimization
- 2025Reasoning with LLMs for Zero-Shot Vulnerability Detection
- 2026VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection
- 2026VulWeaver: Weaving Broken Semantics for Grounded Vulnerability Detection