Skip to main content
QUICK REVIEW

[论文解读] Software Vulnerability and Functionality Assessment using LLMs

Rasmus Ingemann Tuffveson Jensen, Vali Tawosi|arXiv (Cornell University)|Mar 13, 2024
Software Reliability and Analysis Research被引用 4
一句话总结

本文研究了大型语言模型(LLMs)在自动化代码审查中的应用,重点关注漏洞检测与功能正确性验证。通过在HumanEval、MBPP和SecurityEval数据集上使用零样本提示和思维链提示,专有LLM如GPT-4在漏洞检测中准确率超过95%,在功能验证中准确率达88%,且36.7%的生成漏洞描述与真实CWE条目匹配。

ABSTRACT

While code review is central to the software development process, it can be tedious and expensive to carry out. In this paper, we investigate whether and how Large Language Models (LLMs) can aid with code reviews. Our investigation focuses on two tasks that we argue are fundamental to good reviews: (i) flagging code with security vulnerabilities and (ii) performing software functionality validation, i.e., ensuring that code meets its intended functionality. To test performance on both tasks, we use zero-shot and chain-of-thought prompting to obtain final ``approve or reject'' recommendations. As data, we employ seminal code generation datasets (HumanEval and MBPP) along with expert-written code snippets with security vulnerabilities from the Common Weakness Enumeration (CWE). Our experiments consider a mixture of three proprietary models from OpenAI and smaller open-source LLMs. We find that the former outperforms the latter by a large margin. Motivated by promising results, we finally ask our models to provide detailed descriptions of security vulnerabilities. Results show that 36.7% of LLM-generated descriptions can be associated with true CWE vulnerabilities.

研究动机与目标

  • 评估LLM是否能在不执行代码的情况下有效识别安全漏洞。
  • 评估LLM是否能基于文档字符串验证代码是否符合其预期功能。
  • 调查LLM是否能同时执行漏洞检测与功能验证。
  • 检查LLM生成的漏洞描述与真实CWE条目之间的质量关联。
  • 比较专有LLM与开源LLM在代码审查任务中的性能表现。

提出的方法

  • 使用了三个代码数据集:HumanEval(148个函数)、MBPP(476个函数)和SecurityEval(36个存在漏洞的代码片段),所有数据集均包含单个函数及其文档字符串。
  • 采用零样本提示和思维链提示,以获取关于漏洞和功能任务的“批准或拒绝”决策。
  • 评估了专有模型(GPT-3.5-turbo、GPT-4、text-davinci-003)与开源模型(Llama-2、Dolly-v2、Falcon、CodeLlama)的性能。
  • 通过输入扰动和多次运行来减轻随机性影响,提升结果的鲁棒性。
  • 使用准确率、F1分数以及LLM生成的漏洞描述与实际CWE标识符的匹配率来衡量性能。
  • 构建了一个综合数据集用于评估,确保所有来源的函数与文档字符串结构一致。

实验结果

研究问题

  • RQ1RQ1:LLM能否识别出存在安全漏洞的代码?
  • RQ2RQ2:LLM能否在不执行代码的情况下完成软件功能验证?
  • RQ3RQ3:LLM能否同时识别漏洞并验证功能?
  • RQ4RQ4:LLM能否提供有意义的漏洞反馈?

主要发现

  • 专有模型text-davinci-003在漏洞检测中达到95.6%的准确率和37.9%的F1分数。
  • GPT-4在功能验证中达到88.7%的准确率和88.2%的F1分数,显著优于开源模型。
  • 思维链提示使GPT-4在综合任务中的准确率从80.8%提升至87.2%,F1分数从76.6%提升至85.7%。
  • 开源模型表现较差,所有任务中的F1分数均接近或低于随机基线水平。
  • GPT-4生成的漏洞描述中,有36.7%与真实CWE条目匹配,表明其语义对齐具有实际意义。
  • 在GPT、Llama和Dolly系列模型中,模型性能普遍随模型规模增加而提升,且专有模型显著优于开源模型。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。