Skip to main content
QUICK REVIEW

[Paper Review] Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAG

Xueying Du, Geng Zheng|arXiv (Cornell University)|Jun 17, 2024
Web Application Security VulnerabilitiesComputer Science16 citations
TL;DR

Vul-RAG uses a knowledge-level retrieval-augmented generation framework to detect vulnerabilities by constructing a multi-dimension vulnerability knowledge base from CVEs, retrieving relevant knowledge by functional semantics, and performing knowledge-guided reasoning with LLMs. It outperforms baselines on PairVul and provides high-quality explanations to aid manual detection.

ABSTRACT

Although LLMs have shown promising potential in vulnerability detection, this study reveals their limitations in distinguishing between vulnerable and similar-but-benign patched code (only 0.06 - 0.14 accuracy). It shows that LLMs struggle to capture the root causes of vulnerabilities during vulnerability detection. To address this challenge, we propose enhancing LLMs with multi-dimensional vulnerability knowledge distilled from historical vulnerabilities and fixes. We design a novel knowledge-level Retrieval-Augmented Generation framework Vul-RAG, which improves LLMs with an accuracy increase of 16% - 24% in identifying vulnerable and patched code. Additionally, vulnerability knowledge generated by Vul-RAG can further (1) serve as high-quality explanations to improve manual detection accuracy (from 60% to 77%), and (2) detect 10 previously-unknown bugs in the recent Linux kernel release with 6 assigned CVEs.

Motivation & Objective

  • Motivate the need to capture high-level vulnerability semantics beyond lexical code patterns.
  • Construct a vulnerability knowledge base from CVE instances with three dimensions: functional semantics, causes, and fixing solutions.
  • Develop a knowledge-level RAG pipeline to retrieve and reason over vulnerability knowledge for code snippets.
  • Evaluate Vul-RAG against state-of-the-art baselines and assess impact on automated and manual vulnerability detection.

Proposed method

  • Construct a three-dimension vulnerability knowledge representation (functional semantics, causes, fixing solutions) from CVEs using LLM-driven extraction.
  • Build a vulnerability knowledge base by abstracting and generalizing extracted knowledge across CVEs, including knowledge abstraction to remove code-specific identifiers.
  • Online retrieval retrieves top knowledge items using code semantics and BM25-based similarity on three query elements (code, abstract purpose, detailed behavior) and fuses rankings with Reciprocal Rank Fusion.
  • Iteratively reason over retrieved knowledge items with LLMs to detect vulnerability causes and fixing solutions, stopping once vulnerability is identified or items exhausted.
  • Provide prompts for two-step extraction of causes and fixes, with few-shot demonstrations to guide LLMs in knowledge summarization.
Figure 1. A pair of vulnerable code and similar non-vulnerable code (the patched code)
Figure 1. A pair of vulnerable code and similar non-vulnerable code (the patched code)

Experimental results

Research questions

  • RQ1How does Vul-RAG perform compared to representative learning-based vulnerability detectors and static analysis on PairVul?
  • RQ2Does incorporating vulnerability knowledge improve automated vulnerability detection (accuracy, pairwise accuracy) and human analyst performance?
  • RQ3What is the impact of knowledge-level retrieval on identifying vulnerable versus similar-but-patched code pairs?
  • RQ4How useful are the generated vulnerability explanations for improving manual detection?

Key findings

  • Vul-RAG substantially outperforms baselines by 12.96% in accuracy and 110% in pairwise accuracy on PairVul.
  • GPT-4 variants with code-level RAG are consistently outperformed by Vul-RAG across metrics.
  • A user study shows vulnerability knowledge raised manual detection accuracy from 0.60 to 0.77.
  • The PairVul benchmark contains 4,314 vulnerable-vs-patched pairs across 2,073 CVEs, split into 896 CVEs/training and 373 CVEs/testing."],
  • table_headers
  • table_rows
  • table_headers
  • table_rows
  • table_rows
  • table_rows
  • table_headers
  • table_rows
  • table_headers
  • table_rows
  • table_rows
  • table_headers
  • table_rows
  • table_rows
  • table_headers
  • table_rows
  • table_headers
  • table_rows
Figure 2. Overview of Vul-RAG
Figure 2. Overview of Vul-RAG

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.