arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.29901cs.CRcs.LG
收藏

剖析黑箱:LLM 漏洞检测的电路级分析

Dissecting the Black Box: Circuit-Level Analysis of LLM Vulnerability Detection

Lund University(隆德大学)

Syafiq Al Atiiq, Chun Zhou, Christian Gehrmann

AI总结:

通过机械可解释性分析 Gemma-2-2b 模型在 C/C++ 漏洞检测中的内部计算,发现模型主要依赖安全检测器(识别安全编码模式的注意力头)而非直接检测漏洞特征,并识别出关键神经组件(早期层注意力头和 MLP 神经元),通过消融实验验证其因果作用。

摘要:

大型语言模型(LLM)能够检测软件漏洞,但它们实际上是如何识别易受攻击的代码的呢?我们利用机械可解释性来回答这个问题;分析神经网络的内部计算以理解其推理过程。通过在 Gemma-2-2b 上使用 Circuit Tracer,我们追踪了模型将 472 个 C/C++ 代码样本分类为易受攻击或安全时所激活的计算路径。我们的分析揭示了一个令人惊讶的发现:模型主要依赖安全检测器(即识别安全编码模式的注意力头),而不是直接检测漏洞特征。当这些安全检测器未能激活时,模型将代码分类为易受攻击。我们识别出了关键的神经组件:早期层(L5、L7)中专注于安全模式的特定注意力头,以及第 7 层中编码漏洞相关特征的多层感知器(MLP)神经元。消融实验证实了它们的因果作用;移除第 11 层会使漏洞检测准确率从 100% 降至 6%,而仅消融第 7 层中的 20 个神经元就会使其降低 50%。我们的发现表明,LLM 漏洞检测使用了稀疏、可解释的电路(仅占模型容量的 16%),从而能够为安全预测提供电路级解释,并有针对性地改进检测系统。

英文摘要:

Large language models (LLMs) can detect software vulnerabilities, but how do they actually identify vulnerable code? We address this question using mechanistic interpretability; analyzing the internal computations of a neural network to understand its reasoning process.Using Circuit Tracer on Gemma-2-2b, we trace the computational pathways activated when the model classifies 472 C/C++ code samples as vulnerable or safe. Our analysis reveals a surprising finding: the model primarily relies on safety detectors, attention heads that recognize safe coding patterns, rather than directly detecting vulnerability signatures. When these safety detectors fail to activate, the model classifies code as vulnerable. We identify the critical neural components: specific attention heads in early layers (L5, L7) that focus on safety patterns, and Multilayer Perceptron (MLP) neurons in Layer 7 that encode vulnerability-related features. Ablation experiments confirm their causal role; removing Layer 11 drops vulnerability detection accuracy from 100% to 6%, while ablating just 20 neurons in Layer 7 reduces it by 50%.Our findings show that LLM vulnerability detection uses sparse, interpretable circuits (only 16% of model capacity), enabling circuit-level explanations for security predictions and targeted improvements to detection systems.

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

↑