Page 56 - 《软件学报》2025年第4期
P. 56
1462 软件学报 2025 年第 36 卷第 4 期
to natural language processing and image processing models, the security of deep code models faces numerous challenges due to the
vulnerability and inexplicability of neural networks. It has become a research focus in software engineering. In recent years, researchers
have proposed numerous attack and defense methods for deep code models. Nevertheless, there is a lack of a systematic review of
research on deep code model security, hindering the rapid understanding of subsequent researchers in this field. To provide a
comprehensive overview of the current research, challenges, and latest findings in this field, this study collects 32 relevant papers and
categorizes existing research results into two main classes: backdoor attack and defense techniques, and adversarial attack and defense
techniques. This study systematically analyzes and summarizes the collected papers based on the above two categories. Subsequently, it
outlines commonly used experimental datasets and evaluation metrics in this field. Finally, it analyzes key challenges in this field and
suggests feasible future research directions, aiming to provide valuable guidance for further advancements in the security of deep code
models.
Key words: deep code model; security of deep code model; security of artificial intelligence model; backdoor attack and defense; adversarial
attack and defense
随着深度学习技术在计算机视觉与自然语言处理等领域上取得巨大成功, 大量软件工程研究者逐渐将其引入
到软件工程领域来解决软件工程任务, 尤其是代码相关任务. 已有研究者发现深度学习技术在挖掘深层代码特征
11
上具有巨大潜力 [1−4] . 此外, 深度学习技术在各种代码相关任务上具有传统方法与机器学习方法无法比拟的优势.
例如, 在 2018 年, Gu 等人 [2] 将深度学习模型应用于经典的代码检索任务. 他们首先利用深度学习模型将开发者输
入的自然语言查询与检索语料库中的代码片段分别转为向量嵌入表示 (embedding), 然后根据嵌入表示的相似度
[5]
进行检索, 其平均检索效果较基于布尔模型 (Boolean model) 的 CodeHow 提升了 33%, 较基于传统检索方法的
Lucene (https://lucene.apache.org/) 提升了 71%. 在 2020 年, Feng 等人 [6] 基于 BERT 提出用于编程语言表示的双峰
预训练模型 CodeBERT, 在涉及 6 种编程语言的 4 种下游任务中均取得了优异的效果. 本文将这些用于求解代码
相关任务的深度学习模型统称为深度代码模型 (deep code model). 近些年, 由 OpenAI 开发的 GitHub Copilot
(https://github.com/features/copilot) 辅助编程工具进一步推动了深度代码模型的发展. Copilot 背后是更大的深度代
码模型, 称为 Codex . Codex 利用 GitHub (https://github.com/) 上的大量开源代码数据学习不同编程人员的编程风
[7]
格和行为. 因此 Codex 赋能的 Copilot 可以根据开发者已编写的代码提供自动建议并补全后续代码以提高开发者
的编码效率. 然而, 尽管深度代码模型在求解众多代码相关任务上表现出巨大的成功, 但神经网络的脆弱性本质仍
会使深度代码模型的安全应用面临着巨大挑战. 近些年已有众多研究表明深度代码模型面临着诸多安全威胁. 例
如, 2021 年, Schuster 等人 [8] 发现在深度代码模型中植入后门可以提高模型生成含有恶意漏洞代码的概率, 置信度
从 0–20% 增加到 30%–100%. 2023 年, Gao 等人 [9] 通过保留源代码输入语义的程序转换创建离散对抗样本, 提出
了特定于深度代码模型的对抗攻击技术, 可以有效攻击深度代码模型. 因此, 开发者在训练和使用这些深度学习模
型时, 仍然应该保持谨慎, 一方面是需要检查模型所生成的代码质量, 另一方面则需要关注生成代码的安全性.
当前, 深度代码模型的安全问题已吸引了学术界和工业界的广泛关注, 掀起了深度代码模型安全研究热潮. 许
多研究者分别从攻击和防御的角度对深度代码模型的安全进行了深入研究, 并且提出了一系列的攻防方法 [9−12] .
然而, 该领域目前仍缺乏系统的综述, 这阻碍了后续研究者快速了解该领域的研究现状、研究挑战以及未来研究
机会. 因此, 为填补这一空白, 本文对该方向的相关论文进行了系统性地收集. 具体的, 我们采用谷歌学术 (Google
Scholar)、ACM Digital Library、IEEE Xplore、Spring、Elsevier 以及中国知网 (CNKI) 等搜索引擎和数据库, 使用
“code model security”“backdoor attack/defense”“adversarial attack/defense”“代码模型安全”“后门攻击/防御”和“对抗
攻击/防御”等关键字进行检索, 查找截至 2023 年 月的相关论文. 我们定义了以下 4 条选择和过滤论文的规则:
(1) 排除重复的论文或来自同一作者的不同版本的类似研究; (2) 排除书籍、学位论文和短篇论文, 保留在期刊和
会议上发表的长文; (3) 仅选择技术论文, 排除技术报告、实证研究和综述论文; (4) 论文中至少包含一种深度代码
模型, 同时需要研究该模型的安全性并提出一种创新的攻击或防御技术. 其中, 规则 (1) 避免了介绍相似的、冗余
的研究内容. 规则 (2) 和 (3) 聚焦于该领域的研究热点、方法和最新的技术发展动态. 规则 (4) 在于收集符合本文
目标的相关论文. 对于规则 (2) 提到的短篇论文, 在软件工程领域, 会议 (例如该领域的 4 个 CCF A 类会议 (ICSE、
FSE、ASE 和 ISSTA) 的工具论文和 IEEE 期刊短文通常在投稿要求中限制论文页数少于 5 页. 另外, 该领域综述