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

利用大语言模型实现 C 程序的内存安全

Enabling Memory Safety of C Programs using LLMs

Nausheen Mohammed, Akash Lal, Aseem Rastogi, Subhajit Roy, Rahul Sharma

AI总结:

本文提出利用大语言模型将 C 代码移植到 CheckedC 安全方言,并结合轻量级静态分析设计整程序转换框架 MSA,以自动推断注解和重写代码,在微基准和真实代码上优于 LLM 基线与符号化方法。

摘要:

用 C 等低级语言编写的代码中的内存安全违规问题,仍然是软件漏洞的主要来源之一。通过构造来消除此类违规的一种方法是将 C 代码移植到安全的 C 方言。此类方言依赖程序员提供的注解,以最小的运行时开销来保证安全性。然而,这种移植是一个手动过程,给程序员带来了沉重负担,因此该技术的采用一直很有限。移植任务不仅需要推断注解,还可能需要对代码进行重构或重写,使其适合添加此类注解。在本文中,我们使用大语言模型(LLMs)来解决这两个问题。我们展示了如何利用 LLM 的能力进行复杂的代码推理以及大规模代码库的重写。我们还提出了一个新颖的整程序转换框架,该框架利用轻量级静态分析将转换分解为更小的步骤,从而可以由 LLM 有效执行。我们在一个名为 MSA 的工具中实现了这些思想,该工具面向 CheckedC 方言。我们在多个微基准测试以及多达 2 万行代码的真实世界代码上对 MSA 进行了评估。我们展示了与普通 LLM 基线相比的优越性能,并证明了相对于最先进的符号化(非 LLM)技术的改进。

英文摘要:

Memory safety violations in low-level code, written in languages like C, continues to remain one of the major sources of software vulnerabilities. One method of removing such violations by construction is to port C code to a safe C dialect. Such dialects rely on programmer-supplied annotations to guarantee safety with minimal runtime overhead. This porting, however, is a manual process that imposes significant burden on the programmer and, hence, there has been limited adoption of this technique. The task of porting not only requires inferring annotations, but may also need refactoring/rewriting of the code to make it amenable to such annotations. In this paper, we use Large Language Models (LLMs) towards addressing both these concerns. We show how to harness LLM capabilities to do complex code reasoning as well as rewriting of large codebases. We also present a novel framework for whole-program transformations that leverages lightweight static analysis to break the transformation into smaller steps that can be carried out effectively by an LLM. We implement our ideas in a tool called MSA that targets the CheckedC dialect. We evaluate MSA on several micro-benchmarks, as well as real-world code ranging up to 20K lines of code. We showcase superior performance compared to a vanilla LLM baseline, as well as demonstrate improvement over a state-of-the-art symbolic (non-LLM) technique.

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

↑