arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2604.16697cs.CRcs.LG
收藏

对LLMs中不安全代码生成的外科修复

Surgical Repair of Insecure Code Generation in LLMs

Tandon School of Engineering(坦顿工程学院);New York University(纽约大学)

Gustavo Sandoval, Brendan Dolan-Gavitt, Siddharth Garg

AI总结:

研究揭示LLMs生成不安全代码并非知识缺失,而是格式可靠性缺口问题,通过机制分析发现安全表示在最终层被格式合规需求压制,采用针对性修正向量可将不安全生成降低74%。

摘要:

大型语言模型能够编写生产代码,但经常引入已知漏洞。我们证明这不是知识缺陷:相同能生成不安全代码的模型在被直接询问时能正确识别并解释漏洞,这种差距我们称为格式可靠性缺口。机制分析揭示原因:安全表示在最早层被编码,但直到最终层才变得计算上活跃,其中格式合规需求与它们竞争。由于失败局限于单一层,每种漏洞的引导向量可将不安全生成降低高达74%,且开销极低。该机制和修复方法在五种模型、三种架构家族和六种漏洞类型上均适用,表明不安全代码生成是可解释性问题,而非训练固有缺陷。

英文摘要:

Large language models write production code, and yet they routinely introduce well-known vulnerabilities. We show that this is not a knowledge deficit: the same models that generate insecure code, correctly identify and explain the vulnerability when asked directly, this is a gap we call the Format-Reliability Gap. Mechanistic analysis reveals the cause: security representations are encoded from the earliest layers but remain computationally inert until the final layer, where format-compliance demands compete with them. Because the failure is localized to a single layer, per-vulnerability steering vectors reduce insecure generation by up to 74% with negligible overhead. The mechanism and the fix generalize across five models, three architecture families, and six vulnerability types, suggesting insecure code generation is an interpretability problem, not a training artifact.

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

↑