Show Me Your Code! 杀死代码投毒:一种基于代码自然性的轻量级方法
Show Me Your Code! Kill Code Poisoning: A Lightweight Method Based on Code Naturalness
AI总结:
针对代码投毒攻击,提出轻量级检测方法KillBadCode,基于代码自然性破坏原理,利用n-gram语言模型识别触发标记并净化数据,高效且显著优于现有基线。
摘要:
神经代码模型(NCMs)在代码智能任务中展现了非凡的能力。与此同时,NCMs及基于NCMs系统的安全性也日益受到关注。特别是,NCMs通常在大规模可能来自不可信来源的数据上进行训练,这为攻击者提供了通过向数据中插入精心构造的样本来操纵它们的机会。这种类型的攻击被称为代码投毒攻击(也称为后门攻击)。它允许攻击者在NCMs中植入后门,从而控制模型行为,构成严重的安全威胁。然而,目前仍缺乏检测各种复杂代码投毒攻击的有效技术。在本文中,我们提出了一种创新且轻量级的代码投毒检测技术,名为KillBadCode。KillBadCode的设计基于我们的洞察:代码投毒破坏了代码的自然性。具体来说,KillBadCode首先在轻量级n-gram语言模型上构建一个代码语言模型(CodeLM)。然后,给定投毒数据,KillBadCode利用CodeLM识别(投毒)代码片段中的那些标记,这些标记在被删除作为触发标记后会使代码片段更加自然。考虑到在单个样本中删除一些正常标记也可能增强代码自然性,导致高假阳性率(FPR),我们聚合每个标记在所有样本中的累积改进。最后,KillBadCode通过移除所有包含已识别触发标记的投毒样本来净化投毒数据。在两个代码投毒攻击和四个代码智能任务上的实验结果表明,KillBadCode显著优于四个基线。更重要的是,KillBadCode非常高效,最小时间消耗仅为5分钟,平均比最佳基线快25倍。
英文摘要:
Neural code models (NCMs) have demonstrated extraordinary capabilities in code intelligence tasks. Meanwhile, the security of NCMs and NCMs-based systems has garnered increasing attention. In particular, NCMs are often trained on large-scale data from potentially untrustworthy sources, providing attackers with the opportunity to manipulate them by inserting crafted samples into the data. This type of attack is called a code poisoning attack (also known as a backdoor attack). It allows attackers to implant backdoors in NCMs and thus control model behavior, which poses a significant security threat. However, there is still a lack of effective techniques for detecting various complex code poisoning attacks. In this paper, we propose an innovative and lightweight technique for code poisoning detection named KillBadCode. KillBadCode is designed based on our insight that code poisoning disrupts the naturalness of code. Specifically, KillBadCode first builds a code language model (CodeLM) on a lightweight $n$-gram language model. Then, given poisoned data, KillBadCode utilizes CodeLM to identify those tokens in (poisoned) code snippets that will make the code snippets more natural after being deleted as trigger tokens. Considering that the removal of some normal tokens in a single sample might also enhance code naturalness, leading to a high false positive rate (FPR), we aggregate the cumulative improvement of each token across all samples. Finally, KillBadCode purifies the poisoned data by removing all poisoned samples containing the identified trigger tokens. The experimental results on two code poisoning attacks and four code intelligence tasks demonstrate that KillBadCode significantly outperforms four baselines. More importantly, KillBadCode is very efficient, with a minimum time consumption of only 5 minutes, and is 25 times faster than the best baseline on average.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。