线性校正混合生成安全代码
A Mixture of Linear Corrections Generates Secure Code
AI总结:
本研究通过表示工程发现LLMs内部能区分安全与漏洞代码,并据此开发了推理时引导技术MoC,通过调节token生成概率有效提升代码安全性且不损害功能。
摘要:
大型语言模型(LLMs)已能熟练完成复杂的代码生成任务,但在可靠检测或避免代码漏洞方面仍显不足。这种缺陷是由于对代码漏洞学习不足,还是仅仅因为提示无效?使用表示工程技术,我们研究了LLMs是否在内部编码了识别代码漏洞所需的概念。我们发现,当前的LLMs编码了精确的内部表示,能够区分易受攻击和安全的代码——其准确率高于标准提示方法。利用这些漏洞敏感表示,我们开发了一种推理时引导技术,通过校正混合(MoC)微妙地调节模型的token生成概率。我们的方法有效地引导LLMs生成漏洞更少的代码而不损害功能性,展示了在生成代码中控制漏洞管理的实用方法。值得注意的是,MoC将Qwen2.5-Coder-7B的安全比例提高了8.9%,同时在HumanEval pass@1上将功能性提升了2.1%。
英文摘要:
Large language models (LLMs) have become proficient at sophisticated code-generation tasks, yet remain ineffective at reliably detecting or avoiding code vulnerabilities. Does this deficiency stem from insufficient learning about code vulnerabilities, or is it merely a result of ineffective prompting? Using representation engineering techniques, we investigate whether LLMs internally encode the concepts necessary to identify code vulnerabilities. We find that current LLMs encode precise internal representations that distinguish vulnerable from secure code--achieving greater accuracy than standard prompting approaches. Leveraging these vulnerability-sensitive representations, we develop an inference-time steering technique that subtly modulates the model's token-generation probabilities through a mixture of corrections (MoC). Our method effectively guides LLMs to produce less vulnerable code without compromising functionality, demonstrating a practical approach to controlled vulnerability management in generated code. Notably, MoC enhances the security ratio of Qwen2.5-Coder-7B by 8.9\%, while simultaneously improving functionality on HumanEval pass@1 by 2.1\%.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。