[Paper Review] Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilities
The paper introduces Vulnerability-Semantics-guided Prompting (VSP), a chain-of-thought prompting approach that enables LLMs to identify, discover, and patch software vulnerabilities with significantly higher F1 scores than baselines on synthetic and CVE datasets.
Security vulnerabilities are increasingly prevalent in modern software and they are widely consequential to our society. Various approaches to defending against these vulnerabilities have been proposed, among which those leveraging deep learning (DL) avoid major barriers with other techniques hence attracting more attention in recent years. However, DL-based approaches face critical challenges including the lack of sizable and quality-labeled task-specific datasets and their inability to generalize well to unseen, real-world scenarios. Lately, large language models (LLMs) have demonstrated impressive potential in various domains by overcoming those challenges, especially through chain-of-thought (CoT) prompting. In this paper, we explore how to leverage LLMs and CoT to address three key software vulnerability analysis tasks: identifying a given type of vulnerabilities, discovering vulnerabilities of any type, and patching detected vulnerabilities. We instantiate the general CoT methodology in the context of these tasks through VSP , our unified, vulnerability-semantics-guided prompting approach, and conduct extensive experiments assessing VSP versus five baselines for the three tasks against three LLMs and two datasets. Results show substantial superiority of our CoT-inspired prompting (553.3%, 36.5%, and 30.8% higher F1 accuracy for vulnerability identification, discovery, and patching, respectively, on CVE datasets) over the baselines. Through in-depth case studies analyzing VSP failures, we also reveal current gaps in LLM/CoT for challenging vulnerability cases, while proposing and validating respective improvements.
Motivation & Objective
- Motivate vulnerability analysis with limited task-specific data by leveraging LLMs and CoT prompting.
- Propose VSP to map vulnerability semantics to chain-of-thought reasoning for focused analysis.
- Evaluate VSP on three tasks—identification, discovery, and patching—across multiple LLMs and datasets.
Proposed method
- Introduce Vulnerability Semantics that capture vulnerable statements and their contextual data/control-flow relations.
- Instantiate CoT-based few-shot prompting around vulnerability semantics (VSP) as the unified strategy.
- Provide task-specific prompting schemes for identification (binary), discovery (multi-class), and patching (text-to-text) within VSP.
- Use exemplars built around five CWEs in C/C++ and test on SARD (synthetic) and CVE (real-world) datasets with GPT-3.5, Llama2, and Falcon.
- Compare VSP against Standard Prompting, Standard Few-shot, Naive CoT, Zero-Shot VSP, and Other-Type VSP baselines.

Experimental results
Research questions
- RQ1Can LLMs perform vulnerability identification, discovery, and patching effectively when guided by vulnerability semantics?
- RQ2Does CoT prompting with vulnerability-semantics guidance improve performance over standard prompting and naive CoT across diverse LLMs and datasets?
- RQ3How well do these prompts transfer across different vulnerability types (CWEs) and real-world CVE data?
Key findings
- VSP prompting yields the best F1 on vulnerability identification across models and datasets (e.g., 65.29% on SARD with GPT-3.5).
- On CVE data, VSP achieves 58.48% F1 (GPT-3.5) for identification, outperforming standard prompting substantially.
- For vulnerability discovery, VSP improves macro-averaged F1 to 36.34% (GPT-3.5) on CVE and 55.83% on SARD (macro) with GPT-3.5.
- For vulnerability patching, VSP achieves 97.65% F1 on synthetic data and 20.00% on CVE with GPT-3.5, outperforming baselines.
- VSP enables discovery of 22 true zero-day CVE vulnerabilities (40.00% accuracy) vs baselines with 9 (16.36% accuracy).
- Failure analyses identify insufficient context, CWE forgetting, incomplete control/data-flow analysis, and propose targeted improvements.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.