Secure-Instruct: 一种利用LLM合成指令微调数据集的自动化流程,用于安全代码生成
Secure-Instruct: An Automated Pipeline for Synthesizing Instruction-Tuning Datasets Using LLMs for Secure Code Generation
AI总结:
Secure-Instruct通过自动化合成安全代码示例和指令微调LLM,提升代码生成的安全性和功能性正确性。
摘要:
尽管大型语言模型(LLM)在自动化代码生成方面显示出有前途的解决方案,但它们往往生成不安全的代码,威胁软件安全。当前的方法(例如SafeCoder)在提高安全代码生成方面受到限制,因为指令微调数据集小且不平衡。在本工作中,我们提出了Secure-Instruct,一种新的流程,能够自动合成高质量的易受攻击和安全代码示例,并对LLM进行指令微调,以对齐任务描述和安全代码生成能力。我们在四个代表性的LLM上评估了Secure-Instruct,使用两个安全相关的基准测试:我们自己的CWEBench和现有的CWEval。CWEBench包含93种场景,涉及44种CWEs,所有情况均不与Secure-Instruct的合成指令微调数据集重叠,而CWEval涵盖31种CWEs,包含119个手动验证的安全关键任务。我们发现,Secure-Instruct在代码生成的安全性和功能性正确性方面都得到了提升。在CWEBench上,Secure-Instruct显著提高了安全代码生成,平均在安全比率上比预训练模型提高了28.5%,并且优于SafeCoder 12.6%。在CWEval上,Secure-Instruct在CodeLlama-7B上实现了比预训练模型157.3%的提升,在Mistral-7B上实现了46.4%的提升,在Func-Sec@1上显著优于SafeCoder。
英文摘要:
Although Large Language Models (LLMs) show promising solutions to automated code generation, they often produce insecure code that threatens software security. Current approaches (e.g., SafeCoder) to improve secure code generation are limited by small, imbalanced instruction-tuning datasets. In this work, we present Secure-Instruct, a novel pipeline that automatically synthesizes high-quality vulnerable and secure code examples and instruction-tunes LLMs to align task description and secure code generation abilities. We evaluate Secure-Instruct on four representative LLMs using two security-related benchmarks: our own CWEBench and the existing CWEval. CWEBench comprises 93 scenarios on 44 CWEs, all without overlap with Secure-Instruct's synthetic instruction-tuning dataset, while CWEval covers 31 CWEs with 119 manually verified security-critical tasks. We find that Secure-Instruct improves both security and functional correctness in code generation. On CWEBench, Secure-Instruct substantially improves secure code generation, giving a 28.5% increase on average in secure ratio over the pre-trained models and outperforms SafeCoder by 12.6%. On CWEval, Secure-Instruct achieves an increase of 157.3% for CodeLlama-7B and 46.4% for Mistral-7B in Func-Sec@1 over pretrained models, and significantly outperforms SafeCoder.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。