mlsanityData to 14 Oct 2026

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

arXiv 2504.04699 ↗First posted 7 Apr 2025cs.SE cs.AI cs.CLcited by 7

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

  1. 2024Qwen2.5-Coder Technical Report18 Sep
  2. 2024To Err is Machine: Vulnerability Detection Challenges LLM Reasoning25 Mar
  3. 2024LLM4Vuln: A Unified Evaluation Framework for Decoupling and Enhancing LLMs' Vulnerability Reasoning29 Jan

Other references · 30

  1. 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,380
  2. 2024DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Modelscited by 9,379
  3. 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,330
  4. 2022Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedbackcited by 3,720
  5. 2019Fine-Tuning Language Models from Human Preferencescited by 2,150
  6. 2017Towards A Rigorous Science of Interpretable Machine Learningcited by 1,416
  7. 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Modelscited by 1,407
  8. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
  9. 2023Open Problems and Fundamental Limitations of Reinforcement Learning from Human Feedbackcited by 759
  10. 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 744
  11. 2023WizardMath: Empowering Mathematical Reasoning for Large Language Models via Reinforced Evol-Instructcited by 625
  12. 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
18 more
  1. 2023Zephyr: Direct Distillation of LM Alignmentcited by 506
  2. 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
  3. 2023LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarkscited by 97
  4. 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 68
  5. 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
  6. 2024CodeUltraFeedback: An LLM-as-a-Judge Dataset for Aligning Large Language Models to Coding Preferencescited by 57
  7. 2024Finetuning Large Language Models for Vulnerability Detectioncited by 40
  8. 2024CodeDPO: Aligning Code Models with Self Generated and Verified Source Codecited by 34
  9. 2024Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilitiescited by 31
  10. 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
  11. 2024Does RLHF Scale? Exploring the Impacts From Data, Model, and Methodcited by 23
  12. 2024Comparison of Static Application Security Testing Tools and Large Language Models for Repo-level Vulnerability Detectioncited by 18
  13. 2024Security Vulnerability Detection with Multitask Self-Instructed Fine-Tuning of Large Language Modelscited by 14
  14. 2023Transformer-based Vulnerability Detection in Code at EditTime: Zero-shot, Few-shot, or Fine-tuning?cited by 13
  15. 2024Investigating Large Language Models for Code Vulnerability Detection: An Experimental Studycited by 12
  16. 2024Your Instructions Are Not Always Helpful: Assessing the Efficacy of Instruction Fine-tuning for Software Vulnerability Detectioncited by 6
  17. 2024CleanVul: Automatic Function-Level Vulnerability Detection in Code Commits Using LLM Heuristicscited by 4
  18. 2024Towards Explainable Vulnerability Detection with Large Language Modelscited by 3

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 2; 2026: 5.

7 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026Three Heads Are Better Than One: A Multi-perspective Reasoning Framework for Enhanced Vulnerability Detection
  2. 2025Boosting Vulnerability Detection of LLMs via Curriculum Preference Optimization with Synthetic Reasoning Data
  3. 2025VulnLLM-R: Specialized Reasoning LLM with Agent Scaffold for Vulnerability Detection
  4. 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
  5. 2025Improving LLM Reasoning for Vulnerability Detection via Group Relative Policy Optimization
  6. 2025Reasoning with LLMs for Zero-Shot Vulnerability Detection
  7. 2026VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection
  8. 2026VulWeaver: Weaving Broken Semantics for Grounded Vulnerability Detection