TL;DR
This paper investigates ChatGPT's capabilities for four critical software vulnerability tasks: detection, classification, severity estimation, and repair. Despite its massive scale, ChatGPT significantly underperforms compared to specialized, fine-tuned models, suggesting that domain-specific knowledge and fine-tuning are crucial for effective vulnerability handling.
What Problem Does This Paper Address?
The rapid advancement of Large Language Models (LLMs) like ChatGPT has shown promise in various software engineering tasks, including code generation and review. However, their effectiveness in the specialized and critical domain of software vulnerability management remains largely unexplored. This paper aims to bridge this gap by comprehensively evaluating ChatGPT's performance on four key vulnerability-related tasks: identifying vulnerable code (function and line-level), classifying the type of vulnerability (using CWE-IDs), estimating the severity of vulnerabilities (using CVSS scores), and automatically repairing them. The authors seek to understand how ChatGPT, even without task-specific fine-tuning, stacks up against existing, specialized models that have been meticulously trained for these purposes.
Methods
The researchers employed a prompt-based approach to interact with ChatGPT (both gpt-3.5-turbo and gpt-4). They designed specific prompts for each of the four vulnerability tasks:
- Vulnerability Prediction (Function & Line-Level): ChatGPT was prompted to classify functions as vulnerable or not, and for vulnerable functions, to identify the most prone lines of code.
- Vulnerability Classification: ChatGPT was asked to identify the Common Weakness Enumeration (CWE) ID for a given vulnerable function, with a constrained list of potential CWE-IDs provided for fair comparison.
- Severity Estimation: ChatGPT was instructed to predict a Common Vulnerability Scoring System (CVSS) score (0-10) for vulnerable functions.
- Vulnerability Repair: ChatGPT was presented with examples of vulnerable functions and their corresponding repair patches, then asked to generate patches for new vulnerable functions.
The performance of ChatGPT was then compared against several state-of-the-art, fine-tuned baseline models, including AIBugHunter, CodeBERT, GraphCodeBERT, and VulExplainer.
Datasets
The study utilized two primary datasets:
- Big-Vul: This dataset, comprising over 190,000 C/C++ functions from GitHub projects, was used for evaluating vulnerability prediction, classification, and severity estimation. It includes CWE-IDs and CVSS severity scores for each vulnerable function.
- Big-Vul and CVEFixes: These datasets, pre-processed by Chen et al., were used for the automated vulnerability repair task, containing approximately 5.5k pairs of vulnerable functions and their repair patches.
The datasets were split into training, validation, and testing sets according to standard practices for each task.
Key Insights and Ideas
- Scale Isn't Everything (Without Specialization): The most striking finding is that ChatGPT, despite its colossal parameter count (up to 1.7 trillion for GPT-4, vastly exceeding specialized models), performs poorly on these vulnerability tasks. This strongly suggests that raw scale and general pre-training are insufficient for complex, domain-specific challenges like security.
- Domain Expertise is Paramount: The results highlight that vulnerability analysis requires deep, specialized knowledge of security patterns and nuances. ChatGPT, trained on a broad internet corpus, lacks this fine-grained understanding.
- Fine-tuning is Imperative: The paper strongly advocates for fine-tuning LLMs on vulnerability-specific data. This process is essential for ChatGPT to generalize and achieve competitive performance in this domain.
- Repair is the Toughest Challenge: Automated vulnerability repair proved to be the most difficult task for ChatGPT, with the model failing to generate any correct repair patches in the study. This indicates that understanding the intent of a fix and generating syntactically and semantically correct code changes is a significant hurdle.
Key Results
- Vulnerability Prediction (RQ1): ChatGPT achieved an F1-measure of only 10% (gpt-3.5-turbo) and 29% (gpt-4) for function-level prediction, and a top-10 accuracy of 25% and 65% for line-level prediction, respectively. These are significantly lower than AIBugHunter's 94% F1 and 99% top-10 accuracy.
- Vulnerability Classification (RQ2): ChatGPT's multiclass accuracy for identifying CWE-IDs was a mere 13% (gpt-3.5-turbo) and 20% (gpt-4), far below the 62%-65% achieved by fine-tuned baselines.
- Severity Estimation (RQ3): ChatGPT produced the most inaccurate severity estimations, with Mean Squared Errors (MSE) of 5.4 and 5.85, compared to the baselines' MSE of 1.8-1.86.
- Vulnerability Repair (RQ4): ChatGPT failed to generate any correct repair patches, while baselines achieved 7%-30% perfect prediction rates. BLEU and METEOR scores also indicated that ChatGPT's generated patches were less similar to actual fixes.
Limitations and Future Work
The primary limitation acknowledged is that ChatGPT's parameters are proprietary, preventing the researchers from fine-tuning it directly. Their evaluation relies solely on prompting. The study also notes that while ChatGPT's scale is immense, its pre-training data might not adequately cover the specific nuances of software security.
The authors emphasize that a fine-tuning stage is crucial for ChatGPT to effectively generalize and perform well on vulnerability tasks. Future work could involve exploring different prompting strategies, investigating the impact of larger, more curated datasets for fine-tuning, and potentially exploring hybrid approaches that combine LLMs with traditional security analysis tools. The paper also makes its dataset, prompts, and results publicly available to facilitate further research.
Summary updated