Skip to main content
QUICK REVIEW

[Paper Review] LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Reward

Nafis Tanveer Islam, Joseph Khoury|arXiv (Cornell University)|Jan 7, 2024
Software Engineering ResearchComputer Science5 citations
TL;DR

SecRepair uses CodeGen2-7B with reinforcement learning and a semantic reward to automatically identify, repair, describe vulnerabilities, and generate concise code comments, plus an instruction-based vulnerability dataset InstructVul.

ABSTRACT

In software development, the predominant emphasis on functionality often supersedes security concerns, a trend gaining momentum with AI-driven automation tools like GitHub Copilot. These tools significantly improve developers' efficiency in functional code development. Nevertheless, it remains a notable concern that such tools are also responsible for creating insecure code, predominantly because of pre-training on publicly available repositories with vulnerable code. Moreover, developers are called the "weakest link in the chain" since they have very minimal knowledge of code security. Although existing solutions provide a reasonable solution to vulnerable code, they must adequately describe and educate the developers on code security to ensure that the security issues are not repeated. Therefore we introduce a multipurpose code vulnerability analysis system exttt{SecRepair}, powered by a large language model, CodeGen2 assisting the developer in identifying and generating fixed code along with a complete description of the vulnerability with a code comment. Our innovative methodology uses a reinforcement learning paradigm to generate code comments augmented by a semantic reward mechanism. Inspired by how humans fix code issues, we propose an instruction-based dataset suitable for vulnerability analysis with LLMs. We further identify zero-day and N-day vulnerabilities in 6 Open Source IoT Operating Systems on GitHub. Our findings underscore that incorporating reinforcement learning coupled with semantic reward augments our model's performance, thereby fortifying its capacity to address code vulnerabilities with improved efficacy.

Motivation & Objective

  • Motivate secure code repair beyond functionality in AI-assisted development tools.
  • Develop an end-to-end system that identifies, repairs, and describes vulnerabilities in C/C++ code.
  • Create an instruction-based vulnerability dataset (InstructVul) tailored to security concerns.
  • Enable generation of concise code comments suitable as commit messages.
  • Demonstrate zero-day and N-day vulnerability analysis in real OSS IoT operating systems.

Proposed method

  • Leverage CodeGen2-based LLMs fine-tuned for security analysis to identify, repair, and describe vulnerabilities.
  • Train with an instruction-based dataset (InstructVul) comprising vulnerability identification, repair, description, and code-comment generation tasks.
  • Modify the encoder-decoder architecture by dropping the encoder to enable longer code sequences and train the input-output as a single LM-like sequence.
  • Fine-tune for vulnerability description (code-to-text) using a causal decoder to ensure sequential, context-aware generation.
  • Apply reinforcement learning with a semantically aware reward (BERTScore-based) and PPO to optimize concise, semantically-preserving code comments.
  • Evaluate using BLEU, Rouge-L, and human judgments; use Cross-Entropy for vulnerability detection and stabilization of repair quality.

Experimental results

Research questions

  • RQ1RQ1: Can the system automatically identify vulnerabilities and accurately repair code?
  • RQ2RQ2: Can the system provide comprehensive vulnerability descriptions to developers?
  • RQ3RQ3: Can the system optimize and summarize descriptions and generate concise code comments?

Key findings

  • SecRepair (7B) achieves F1 0.82, Precision 0.80, Recall 0.70, and Accuracy 0.88 on vulnerability identification/repair tasks (Table 1).
  • On the InstructVul dataset, SecRepair (7B) attains BLEU 0.82 and Rouge-L 0.80 for repair tasks, outperforming several baselines at comparable parameter scales.
  • For vulnerability description quality in the developer-facing task, SecRepair (7B) reaches BLEU 0.76, Rouge-L 0.98, and Human score 5.
  • Reinforcement learning with semantic reward improves code-comment generation (SecRepair 7B: BLEU 0.60, Rouge-L 0.72, Human 5) compared to plain fine-tuning.
  • Ablation studies show temperature and beam size influence on performance, with a sweet spot around temperature 0.5 and larger beam sizes offering gains at higher inference costs.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.