arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2404.18353cs.CRcs.AIcs.PL
收藏

AI生成代码的安全性如何:大语言模型的大规模对比研究

How secure is AI-generated Code: A Large-Scale Comparison of Large Language Models

Eötvös Loránd University (ELTE)(厄特沃什·罗兰大学);Technology Innovation Institute (TII)(技术创新研究院);University of Oslo(奥斯陆大学);Guelma University(盖勒马大学);The University of Manchester(曼彻斯特大学);Federal University of Amazonas(亚马逊联邦大学)

Norbert Tihanyi, Tamas Bisztray, Mohamed Amine Ferrag, Ridhi Jain, Lucas C. Cordeiro

AI总结:

该研究扩展FormAI数据集相关工作,构建含33.1万个C程序的FormAI-v2数据集,用形式化验证对比9款前沿大语言模型的代码生成安全性,发现超6成生成代码存在漏洞,提示LLM代码落地需风险评估。

摘要:

本研究对比了前沿大语言模型(LLM)在使用中性零样本提示编写C程序时生成漏洞的倾向。Tihanyi等人在PROMISE'23上提出了FormAI数据集,包含由GPT-3.5-turbo生成的11.2万个C程序,其中超过51.24%被判定存在漏洞。我们扩展了该研究,开展了一项涉及9个前沿模型的大规模研究,包括OpenAI的GPT-4o-mini、谷歌的Gemini Pro 1.0、TII的1800亿参数Falcon、Meta的130亿参数Code Llama,以及其他多个紧凑型模型。此外,我们提出了FormAI-v2数据集,包含由这些大语言模型生成的33.1万个可编译C程序。数据集中的每个程序都通过形式化验证(使用基于高效SMT的上下文有界模型检查器ESBMC),根据其源代码中检测到的漏洞进行标注。该技术通过为特定漏洞提供反例来最大程度减少误报,并通过完整执行验证流程来减少漏报。我们的研究显示,生成的程序中至少有62.07%存在漏洞。各模型之间的差异很小,它们都存在类似的编码错误,仅略有不同。我们的研究强调,尽管大语言模型在代码生成方面展现出可观的能力,但在生产环境中部署其输出仍需进行适当的风险评估与验证。

英文摘要:

This study compares state-of-the-art Large Language Models (LLMs) on their tendency to generate vulnerabilities when writing C programs using a neutral zero-shot prompt. Tihanyi et al. introduced the FormAI dataset at PROMISE'23, featuring 112,000 C programs generated by GPT-3.5-turbo, with over 51.24% identified as vulnerable. We extended that research with a large-scale study involving 9 state-of-the-art models such as OpenAI's GPT-4o-mini, Google's Gemini Pro 1.0, TII's 180 billion-parameter Falcon, Meta's 13 billion-parameter Code Llama, and several other compact models. Additionally, we introduce the FormAI-v2 dataset, which comprises 331 000 compilable C programs generated by these LLMs. Each program in the dataset is labeled based on the vulnerabilities detected in its source code through formal verification, using the Efficient SMT-based Context-Bounded Model Checker (ESBMC). This technique minimizes false positives by providing a counterexample for the specific vulnerability and reduces false negatives by thoroughly completing the verification process. Our study reveals that at least 62.07% of the generated programs are vulnerable. The differences between the models are minor, as they all show similar coding errors with slight variations. Our research highlights that while LLMs offer promising capabilities for code generation, deploying their output in a production environment requires proper risk assessment and validation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑