Skip to main content
QUICK REVIEW

[Paper Review] Understanding the Effectiveness of Large Language Models in Detecting Security Vulnerabilities

Avishree Khare, Saikat Dutta|arXiv (Cornell University)|Nov 16, 2023
Software Engineering ResearchComputer Science12 citations
TL;DR

The paper benchmarks pre-trained LLMs (GPT-4, GPT-3.5, CodeLlama) on five vulnerability datasets across Java and C/C++, develops prompting strategies to detect vulnerabilities and provide explanations, compares against static analysis and deep learning tools, and analyzes robustness to adversarial code and fine-tuning effects.

ABSTRACT

While automated vulnerability detection techniques have made promising progress in detecting security vulnerabilities, their scalability and applicability remain challenging. The remarkable performance of Large Language Models (LLMs), such as GPT-4 and CodeLlama, on code-related tasks has prompted recent works to explore if LLMs can be used to detect vulnerabilities. In this paper, we perform a more comprehensive study by concurrently examining a higher number of datasets, languages and LLMs, and qualitatively evaluating performance across prompts and vulnerability classes while addressing the shortcomings of existing tools. Concretely, we evaluate the effectiveness of 16 pre-trained LLMs on 5,000 code samples from five diverse security datasets. These balanced datasets encompass both synthetic and real-world projects in Java and C/C++ and cover 25 distinct vulnerability classes. Overall, LLMs across all scales and families show modest effectiveness in detecting vulnerabilities, obtaining an average accuracy of 62.8% and F1 score of 0.71 across datasets. They are significantly better at detecting vulnerabilities only requiring intra-procedural analysis, such as OS Command Injection and NULL Pointer Dereference. Moreover, they report higher accuracies on these vulnerabilities than popular static analysis tools, such as CodeQL. We find that advanced prompting strategies that involve step-by-step analysis significantly improve performance of LLMs on real-world datasets in terms of F1 score (by upto 0.18 on average). Interestingly, we observe that LLMs show promising abilities at performing parts of the analysis correctly, such as identifying vulnerability-related specifications and leveraging natural language information to understand code behavior (e.g., to check if code is sanitized). We expect our insights to guide future work on LLM-augmented vulnerability detection systems.

Motivation & Objective

  • Assess whether pre-trained LLMs can detect security vulnerabilities in code across multiple datasets and languages.
  • Design prompting strategies that elicit reasoning and explanations from LLMs for vulnerability detection.
  • Compare LLM performance with static analysis (CodeQL) and deep learning (LineVul) approaches.
  • Evaluate robustness to data leakage and adversarial code attacks and explore fine-tuning effects on performance.
  • Provide insights and recommendations for leveraging LLMs in vulnerability detection.

Proposed method

  • Evaluate GPT-4, GPT-3.5, CodeLlama-7B, and CodeLlama-13B on five datasets (OWASP, Juliet Java, Juliet C/C++, CVEFixes Java, CVEFixes C/C++).
  • Develop four prompting strategies: Basic, CWE-specific, Dataflow analysis-based, and Dataflow with Self Reflection.
  • Compare LLM results against CodeQL (static analysis) and LineVul (deep learning).
  • Assess data leakage via semantics-preserving adversarial attacks and measure performance impact.
  • Examine fine-tuning of smaller models and its effect on synthetic versus real-world datasets.

Experimental results

Research questions

  • RQ1Can pre-trained LLMs detect security vulnerabilities in code across diverse datasets and languages?
  • RQ2How do prompting strategies affect LLM vulnerability detection performance and explainability?
  • RQ3How do LLMs compare to CodeQL and LineVul on standard vulnerability benchmarks?
  • RQ4Are LLMs robust to adversarial code modifications and data leakage?
  • RQ5Do fine-tuning smaller LLMs improve performance, and is generalization preserved across datasets?

Key findings

  • GPT-4 with Dataflow analysis-based prompt + Self Reflection achieves F1 scores of 0.79 (OWASP), 0.86 (Juliet Java), and 0.89 (Juliet C/C++) on synthetic datasets.
  • GPT-4 attains up to 0.48 (CVEFixes Java) and 0.62 (CVEFixes C/C++) on real-world datasets with the same prompt.
  • CodeLlama models yield lower F1 scores (e.g., 0.69–0.77 on synthetic datasets; up to 0.65 on CVEFixes C/C++).
  • Self Reflection tends to push GPT-4 toward predicting “not vulnerable” on real-world datasets, reducing performance; CodeLlama shows better resilience in these cases.
  • LineVul achieves 1.0 F1 on Juliet C/C++ with data trained on large data, but lacks interpretable CWE-level explanations; GPT-4 provides more interpretable reasoning.
  • Adversarial code attacks cause mild degradation (average up to 12.67% for certain attacks); fine-tuning smaller models improves synthetic results but has limited gains on real-world data.

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.