LLM-Enhanced Software Patch Localization

Jinhong Yu, Yi Chen, Di Tang, Xiaozhong Liu, XiaoFeng Wang, Chen Wu, Haixu TangarXiv 2024

Abstract

Open source software (OSS) is integral to modern product development, and any vulnerability within it potentially compromises numerous products. While developers strive to apply security patches, pinpointing these patches among extensive OSS updates remains a challenge. Security patch localization (SPL) recommendation methods are leading approaches to address this. However, existing SPL models often falter when a commit lacks a clear association with its corresponding CVE, and do not consider a scenario that a vulnerability has multiple patches proposed over time before it has been fully resolved. To address these challenges, we introduce LLM-SPL, a recommendation-based SPL approach that leverages the capabilities of the Large Language Model (LLM) to locate the security patch commit for a given CVE. More specifically, we propose a joint learning framework, in which the outputs of LLM serves as additional features to aid our recommendation model in prioritizing security patches. Our evaluation on a dataset of 1,915 CVEs associated with 2,461 patches demonstrates that LLM-SPL excels in ranking patch commits, surpassing the state-of-the-art method in terms of Recall, while significantly reducing manual effort. Notably, for vulnerabilities requiring multiple patches, LLM-SPL significantly improves Recall by 22.83%, NDCG by 19.41%, and reduces manual effort by over 25% when checking up to the top 10 rankings.

The Challenge of Security Patch Localization

Open Source Software (OSS) is the backbone of modern tech, but it’s also a major source of security vulnerabilities. When a vulnerability (tracked as a CVE) is discovered, developers need to find the specific "patch commit" in a sea of thousands of updates to ensure their systems are protected. This task, called Security Patch Localization (SPL), is surprisingly difficult for two primary reasons:

  1. Complexity of Content: CVE descriptions are written in natural language, while patches are raw code diffs. Traditional models struggle to bridge the semantic gap between a description like "buffer overflow" and a specific line of code change. Furthermore, commit messages are often uninformative, sometimes containing only an ellipsis ("..."), making keyword-based matching impossible.
  2. The 1-N Relationship: About 21% of vulnerabilities aren't fixed in a single commit. They require multiple patches—perhaps an initial fix followed by a regression fix or a secondary patch for a different component. Existing tools usually look for a one-to-one match and often miss these "follow-up" commits.
Figure 1: An example of the semantic gap in SPL. The CVE description mentions an "off-by-one read vulnerability," which corresponds to a code change adding '+1' to a buffer size. Note the commit message is just an ellipsis, rendering traditional text-based search ineffective.

Methodology: The LLM-SPL Framework

To overcome these hurdles, we introduce LLM-SPL, a joint learning framework that treats SPL as a recommendation problem. The core innovation lies in using a Large Language Model (LLM) not as a final decision-maker, but as a sophisticated feature extractor that feeds into a downstream ranking model.

The framework utilizes three main types of features:

  • $F_0$ (Standard Features): Traditional metrics like textual similarity and code behavior, derived from existing state-of-the-art methods like VCMatch.
  • $F_1$ (LLM Relevance): We prompt an LLM (GPT-3.5) to act as a security analyst, judging whether a specific commit likely patches a given CVE based on the code diff and description.
  • $F_2$ (Inter-Commit Graph): This addresses the 1-N relationship. The LLM identifies relationships between different commits (e.g., "Do these two commits collaboratively fix the same bug?"). These relationships form a graph that helps the model "pull up" related patches that might otherwise rank low.

The "Top-k" Cost-Saving Strategy

Querying an LLM for every possible commit-CVE pair is prohibitively expensive. To make this practical, LLM-SPL uses a two-step "pseudo-relevance feedback" approach. An initial, cheaper model ranks candidates, and the LLM is only asked to evaluate the top 100 candidates. This reduced the estimated cost for our dataset from $620,000 to just $880.

Figure 5: The LLM-SPL joint learning framework. It uses an initial ranking to select top-k candidates, which are then processed by an LLM to generate relevance and graph features for the final joint learning model.

Key Insights and Results

Our evaluation on a dataset of 1,915 CVEs and 2,461 patches revealed several key insights:

  • LLMs as Feature Providers: When used alone, LLMs have a high false-positive rate. However, as feature providers, they offer invaluable semantic context that traditional models lack.
  • Contextual Inference: LLMs can infer the intent of a code change by looking at the logic of the diff, even when commit messages are missing or vague.
  • Superior 1-N Performance: LLM-SPL significantly outperformed the previous state-of-the-art (VCMatch) in complex scenarios. For 1-N vulnerabilities, it improved Recall@10 by 22.83% and NDCG by 19.41%.
  • Reduced Manual Effort: For 1-N vulnerabilities, the model reduced the number of commits a human needs to check by over 25%. Overall, LLM-SPL successfully ranked the correct patches within the top 10 results for over 92% of CVEs.

Conclusion and Future Work

LLM-SPL demonstrates that combining the reasoning capabilities of LLMs with traditional recommendation frameworks can drastically improve security patch localization. While limited by current LLM context windows and a dependency on the initial ranking model's performance, future iterations using more advanced models like GPT-4 or specialized security LLMs hold promise for even greater accuracy and efficiency in securing the OSS ecosystem.

Summary updated

BibTeX
@misc{yu2024llm,
  author = {Jinhong Yu and Yi Chen and Di Tang and Xiaozhong Liu and XiaoFeng Wang and Chen Wu and Haixu Tang},
  title = {{LLM-Enhanced Software Patch Localization}},
  year = {2024},
  eprint = {2409.06816},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.06816},
}
Figure