[论文解读] Poison Attack and Defense on Deep Source Code Processing Models
本文提出 CodePoisoner,一种通过生成可编译、人类难以察觉的投毒样本,向深度源代码处理模型注入后门的投毒攻击框架,以及 CodeDetector,一种利用积分梯度检测此类投毒样本的防御机制。该方法在缺陷检测、代码克隆检测和代码修复任务中均展现出极高的攻击成功率(平均:98.6%)和近乎完美的检测能力(最高:100%)。
In the software engineering community, deep learning (DL) has recently been applied to many source code processing tasks. Due to the poor interpretability of DL models, their security vulnerabilities require scrutiny. Recently, researchers have identified an emergent security threat, namely poison attack. The attackers aim to inject insidious backdoors into models by poisoning the training data with poison samples. Poisoned models work normally with clean inputs but produce targeted erroneous results with poisoned inputs embedded with triggers. By activating backdoors, attackers can manipulate the poisoned models in security-related scenarios. To verify the vulnerability of existing deep source code processing models to the poison attack, we present a poison attack framework for source code named CodePoisoner as a strong imaginary enemy. CodePoisoner can produce compilable even human-imperceptible poison samples and attack models by poisoning the training data with poison samples. To defend against the poison attack, we further propose an effective defense approach named CodeDetector to detect poison samples in the training data. CodeDetector can be applied to many model architectures and effectively defend against multiple poison attack approaches. We apply our CodePoisoner and CodeDetector to three tasks, including defect detection, clone detection, and code repair. The results show that (1) CodePoisoner achieves a high attack success rate (max: 100%) in misleading models to targeted erroneous behaviors. It validates that existing deep source code processing models have a strong vulnerability to the poison attack. (2) CodeDetector effectively defends against multiple poison attack approaches by detecting (max: 100%) poison samples in the training data. We hope this work can help practitioners notice the poison attack and inspire the design of more advanced defense techniques.
研究动机与目标
- 研究深度源代码处理模型在投毒攻击下的脆弱性,此类攻击可通过投毒训练数据注入后门。
- 开发一种实用的投毒攻击框架 CodePoisoner,能够生成有效且人类无法察觉的投毒样本。
- 设计一种可泛化的防御机制 CodeDetector,用于检测多种模型架构中的训练数据中的投毒样本。
- 在真实世界源代码处理任务(包括缺陷检测、代码克隆检测和代码修复)上评估攻击与防御框架。
- 提高软件工程社区对投毒训练数据安全风险的认识,并激发更稳健的防御技术。
提出的方法
- CodePoisoner 使用基于规则和语言模型引导的策略生成投毒样本,以嵌入语法有效且语义自然的触发器。
- 该框架确保投毒样本可编译并通过保持自然的代码结构来规避训练过程中的检测。
- CodeDetector 采用积分梯度算法计算特征重要性,识别出指示投毒样本的可疑输入模式。
- 它通过评估代码标记的显著性,检测与后门行为相关的训练数据异常。
- 该防御机制与模型架构无关,对基于 CNN、LSTM 和 Transformer 的模型均有效。
- 实验通过在训练数据中注入 2% 的投毒样本,并对比模型在干净输入与触发注入输入下的行为进行评估。
实验结果
研究问题
- RQ1能否通过语法正确且语义自然的投毒样本,有效对深度源代码处理模型实施投毒攻击?
- RQ2CodePoisoner 在保持低投毒成本和高隐蔽性的同时,其攻击成功率有多高?
- RQ3CodeDetector 能否在多种模型架构和投毒攻击策略下可靠检测投毒样本?
- RQ4投毒攻击对真实世界源代码处理任务(如缺陷检测、代码克隆检测和代码修复)有何影响?
- RQ5在实际中,CodeDetector 能在多大程度上防御多种投毒攻击方法?
主要发现
- CodePoisoner 在所有评估任务中平均攻击成功率达到 98.6%,最高达 100%,证明其在仅 2% 投毒成本下具有极高有效性。
- CodePoisoner 生成的投毒样本可编译且人类难以察觉,具有高度隐蔽性,极有可能被接受为真实训练数据。
- CodeDetector 在多种攻击策略和模型架构下,对投毒样本的检测准确率最高达 100%。
- 该防御机制对基于规则和语言模型引导的投毒策略均有效,展现出对不同类型攻击的泛化能力。
- 攻击与防御框架已在三项不同的源代码处理任务上得到验证,确认了威胁面的存在以及防御方案的可行性。
- 结果凸显了在使用深度学习的软件工程流水线中,对训练数据进行验证的紧迫性,尤其是在依赖开源训练数据时。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。