arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2311.04109cs.LGcs.CR
收藏

语言模型是否学习代码语义?以漏洞检测为案例的研究

Do Language Models Learn Semantics of Code? A Case Study in Vulnerability Detection

Iowa State University(爱荷华州立大学)

Benjamin Steenhoek, Md Mahbubur Rahman, Shaila Sharmin, Wei Le

AI总结:

本研究针对预训练语言模型在漏洞检测中是否习得相关代码语义的问题展开分析,发现模型与漏洞语义对齐不足,提出高亮漏洞语义的标注方法,有效提升了多数场景下的模型性能与对齐程度。

摘要:

近期,预训练语言模型在漏洞检测任务上展现出了当前最优的性能。这类模型先在大规模源代码语料上进行预训练,再在规模更小的有监督漏洞数据集上进行微调。由于训练目标和模型性能存在差异,一个值得探究的问题是:这些模型是否习得了与漏洞检测相关的代码语义,即漏洞语义?如果答案是肯定的,模型与漏洞语义的对齐程度又和模型性能有怎样的关联?本文采用三种不同的方法对模型展开分析:可解释性工具、注意力分析和交互矩阵分析。我们将模型的关键特征集与定义漏洞成因的漏洞语义特征(包括漏洞路径和潜在漏洞语句Potentially Vulnerable Statements, PVS)进行对比。研究发现:(1)性能更优的模型与PVS的对齐程度也更高;(2)所有模型都未能与PVS实现强对齐;(3)所有模型完全无法与漏洞路径对齐。基于上述分析,我们提出了两种标注方法,用于在模型输入中高亮标注漏洞语义。我们在四种不同的Transformer模型和四个漏洞数据集上评估了该方法,结果显示,在大多数设置下(16组中的11组),我们的标注方法提升了模型性能,与传统微调相比,F1分数最高提升了9.57个点。我们进一步发现,加入我们的标注后,模型与潜在漏洞语句的对齐程度最高提升了232%。研究结果表明,向模型提供漏洞语义信息是有帮助的,且模型能够关注到这些信息,这也为未来学习更复杂的基于路径的漏洞语义相关研究提供了动力。我们的代码和数据可在https://figshare.com/s/4a16a528d6874aad51a0获取。

英文摘要:

Recently, pretrained language models have shown state-of-the-art performance on the vulnerability detection task. These models are pretrained on a large corpus of source code, then fine-tuned on a smaller supervised vulnerability dataset. Due to the different training objectives and the performance of the models, it is interesting to consider whether the models have learned the semantics of code relevant to vulnerability detection, namely bug semantics, and if so, how the alignment to bug semantics relates to model performance. In this paper, we analyze the models using three distinct methods: interpretability tools, attention analysis, and interaction matrix analysis. We compare the models' influential feature sets with the bug semantic features which define the causes of bugs, including buggy paths and Potentially Vulnerable Statements (PVS). We find that (1) better-performing models also aligned better with PVS, (2) the models failed to align strongly to PVS, and (3) the models failed to align at all to buggy paths. Based on our analysis, we developed two annotation methods which highlight the bug semantics inside the model's inputs. We evaluated our approach on four distinct transformer models and four vulnerability datasets and found that our annotations improved the models' performance in the majority of settings - 11 out of 16, with up to 9.57 points improvement in F1 score compared to conventional fine-tuning. We further found that with our annotations, the models aligned up to 232% better to potentially vulnerable statements. Our findings indicate that it is helpful to provide the model with information of the bug semantics, that the model can attend to it, and motivate future work in learning more complex path-based bug semantics. Our code and data are available at https://figshare.com/s/4a16a528d6874aad51a0.

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

↑