用自动构造的漏洞场景训练代码大模型,提升安全性
ProSec: Fortifying Code LLMs with Proactive Security Alignment
- 从CWE枚举生成漏洞诱导场景,主动暴露模型缺陷
- 合成数据量达之前7倍,使模型安全率提升25.2%~35.4%
- 适合关注代码安全性的开发与安全研究人员
尽管近期代码专用大语言模型在代码生成能力上显著提升,但其安全性仍缺乏深入探索,生成的不安全代码可能引入真实系统漏洞。现有方法依赖真实漏洞数据进行指令微调,但受限于漏洞代码的数据稀疏性,且难以适配现代LLM多阶段后训练流程。本文提出ProSec,一种主动安全对齐新方法,通过从通用弱点枚举(CWE)中合成漏洞诱导编程场景,并生成修复方案,使模型通过偏好学习掌握安全编码实践。ProSec合成的场景触发的漏洞代码数量是普通指令微调数据集的25倍,构建的安全对齐数据集规模达前人工作的7倍。实验表明,使用ProSec训练的模型在安全性上比此前工作提升25.2%至35.4%,同时未降低模型实用性。
原文摘要 · Abstract (English)
While recent code-specific large language models (LLMs) have greatly enhanced their code generation capabilities, the safety of these models remains under-explored, posing potential risks as insecure code generated by these models may introduce vulnerabilities into real-world systems. Existing methods collect security-focused datasets from real-world vulnerabilities for instruction tuning in order to mitigate such issues. However, they are largely constrained by the data sparsity of vulnerable code, and have limited applicability in the multi-stage post-training workflows of modern LLMs. In this paper, we propose ProSec, a novel proactive security alignment approach designed to align code LLMs with secure coding practices. ProSec systematically exposes the vulnerabilities in a code LLM by synthesizing vulnerability-inducing coding scenarios from Common Weakness Enumerations (CWEs) and generates fixes to vulnerable code snippets, allowing the model to learn secure practices through preference learning objectives. The scenarios synthesized by ProSec trigger 25x more vulnerable code than a normal instruction-tuning dataset, resulting in a security-focused alignment dataset 7x larger than the previous work. Experiments show that models trained with ProSec are 25.2% to 35.4% more secure compared to previous work without degrading models' utility.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。