arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2401.07031cs.CRcs.AIcs.SE
收藏

基于大语言模型与强化学习的代码安全漏洞修复

Code Security Vulnerability Repair Using Reinforcement Learning with Large Language Models

University of Texas at San Antonio(德克萨斯大学圣安东尼奥分校)

Nafis Tanveer Islam, Mohammad Bahrami Karkevandi, Peyman Najafirad

AI总结:

针对现有LLM代码修复因监督微调的样本不平衡而忽略安全防护的问题,提出结合语义、语法奖励机制的强化学习代码修复方法,以实现LLM生成代码的安全加固。

摘要:

随着大语言模型(Large Language Models, LLMs)的最新进展,对广大开发者而言,生成功能正确的代码已变得不再那么复杂。尽管使用LLMs加快了功能开发流程,但它也给代码安全带来了严重风险。利用LLM生成具备合理安全防护措施的代码,是一项比功能代码生成难度大得多的任务。安全防护措施可包括在原有代码中添加数行代码,例如空指针检查或用于防范SQL注入的预编译语句(prepared statements)。当前可用的代码修复LLM通过监督微调生成代码修复方案,其模型优化依据是交叉熵损失。然而,原始代码与修复后的代码除了少数(1-2行)充当安全防护的代码行之外,在功能和语法上大多高度相似。安全防护所需代码行与功能代码之间的这种不平衡,使得监督微调模型优先生成功能代码,而不添加合理的安全防护措施——这还能让模型获得损失最小化的“收益”。因此,在本研究中,为实现对LLMs生成代码的安全加固与强化,我们提出了一种基于强化学习的、针对特定程序的修复方法,该方法结合了语义与语法奖励机制,二者分别重点关注在代码中添加安全防护措施与功能保障措施。

英文摘要:

With the recent advancement of Large Language Models (LLMs), generating functionally correct code has become less complicated for a wide array of developers. While using LLMs has sped up the functional development process, it poses a heavy risk to code security. Code generation with proper security measures using LLM is a significantly more challenging task than functional code generation. Security measures may include adding a pair of lines of code with the original code, consisting of null pointer checking or prepared statements for SQL injection prevention. Currently, available code repair LLMs generate code repair by supervised fine-tuning, where the model looks at cross-entropy loss. However, the original and repaired codes are mostly similar in functionality and syntactically, except for a few (1-2) lines, which act as security measures. This imbalance between the lines needed for security measures and the functional code enforces the supervised fine-tuned model to prioritize generating functional code without adding proper security measures, which also benefits the model by resulting in minimal loss. Therefore, in this work, for security hardening and strengthening of generated code from LLMs, we propose a reinforcement learning-based method for program-specific repair with the combination of semantic and syntactic reward mechanisms that focus heavily on adding security and functional measures in the code, respectively.

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

↑