arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.04994cs.SE
收藏

SPVR: 基于大语言模型的语法到提示漏洞修复

SPVR: syntax-to-prompt vulnerability repair based on large language models

Harbin Institute of Technology, Shenzhen(哈尔滨工业大学(深圳));Hong Kong University of Science and Technology(香港科技大学);The Chinese University of Hong Kong(香港中文大学);Chinese Academy of Sciences(中国科学院)

Ruoke Wang, Zongjie Li, Cuiyun Gao, Chaozheng Wang, Yang Xiao, Xuan Wang

AI总结:

SPVR通过语法分析生成针对性提示,提升大语言模型修复漏洞的准确性。

摘要:

目的:在漏洞修复领域,先前的研究利用了预训练模型和基于LLM的提示工程,其中基于LLM的方法表现出更好的泛化能力,并取得了最佳性能。然而,基于LLM的方法通常将漏洞修复视为序列到序列任务,并未显式捕捉不同漏洞类型的语法模式,导致准确性有限。我们旨在创建一种方法,确保针对易受攻击的代码的提示的特异性,同时利用大语言模型的生成能力。方法:我们提出SPVR(语法到提示漏洞修复),一种新的框架,该框架从语法树中收集信息,并生成相应的提示。我们的方法包括三个步骤:规则设计、提示生成和补丁生成。在规则设计步骤中,我们的方法解析代码补丁并设计规则以提取相关上下文信息。这些规则有助于识别与漏洞相关的问题。在提示生成步骤中,我们的方法使用预定义规则从易受攻击的代码中提取信息,自动将其转换为提示。我们还把CWE(常见弱点分类)的描述作为已知信息纳入提示中。最后,在补丁生成步骤中,该提示将作为输入提供给任何对话式LLM以获得代码补丁。结果:广泛的实验验证了我们的方法在帮助LLM准确修复漏洞方面的优秀表现。我们利用多种大语言模型来验证我们工作的有效性,使用ChatGPT-4修复了547个易受攻击的代码中的143个。我们还对我们的方法与几种现有的漏洞修复方法(包括基于微调和基于提示的方法)进行了多指标比较。

英文摘要:

Purpose: In the field of vulnerability repair, previous research has leveraged pretrained models and LLM-based prompt engineering, among which LLM-based approaches show better generalizability and achieve the best performance. However, the LLM-based approaches generally regard vulnerability repair as a sequence-to-sequence task, and do not explicitly capture the syntax patterns for different vulnerability types, leading to limited accuracy. We aim to create a method that ensures the specificity of prompts targeting vulnerable code while also leveraging the generative capabilities of Large Language Models. Methods: We propose SPVR (Syntax-to-Prompt Vulnerability Repair), a novel framework that collects information from syntax trees, and generates corresponding prompts. Our method consists of three steps: rule design, prompt generation, and patch generation. In the rule design step, our method parses code patches and designs rules to extract relevant contextual information. These rules aid in identifying vulnerability-related issues. In the prompt generation step, our method extracts information from vulnerable code with pre-defined rules, automatically converting them into prompts. We also incorporate the description of CWE (Common Weakness Enumeration) as known information into the prompts. Finally, in the patch generation step, this prompt will serve as input to any conversational LLM to obtain code patches. Results: Extensive experiments validate that our method achieves excellent results in assisting LLMs to fix vulnerabilities accurately. We utilize multiple Large Language Models to validate the effectiveness of our work, repairing 143 of 547 vulnerable code using ChatGPT-4. We conducted a comparison of our approach against several existing vulnerability repair approaches (including fine-tuning-based and prompt-based), across multiple metrics.

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

↑