用大模型自动标注C代码内存使用,提升安全检测效率
CNnotator: LLM-Guided Memory Safety Annotation Synthesis
- 用大模型生成内存规范,结合测试验证其正确性
- o3模型首次尝试成功率达90%,整体成功率97%
- 适合需要迁移或审计老旧C代码的开发团队
内存安全错误占C语言系统中安全漏洞的很大比例;现代语言如Java和Rust因设计上内存安全而避免此类问题。要迁移至更安全语言或识别内存错误,必须先明确旧代码的内存操作方式。这类信息在代码中仅隐式存在。许多情况下,人类理解内存使用模式只是繁琐而非困难。本文探讨大语言模型(LLMs)能否通过生成表示内存使用情况的规格说明来完成此任务。我们构建了工具CNnotator,利用大模型自动生成并测试CN规格说明。实验表明,当前模型能为中小型C程序生成有效规格,OpenAI o3推理模型首次尝试成功率高达90%,总体成功率达97%;GPT-4o聊天模型首次标注正确率为65%。结果表明,人工智能辅助标注已具备应用于真实世界C代码库的可行性。
原文摘要 · Abstract (English)
Memory safety errors account for a large proportion of security bugs in systems written in C; modern languages such as Java and Rust prevent such bugs because they are memory-safe by design. To migrate systems to safer languages or identify memory errors, we must first determine how legacy code manipulates memory. This information is only represented implicitly in such code. In many cases, memory usage patterns are merely tedious for humans to figure out, rather than truly difficult. In this work, we ask if large language models (LLMs) can perform this task by having them synthesize annotations representing memory usage as specifications in CN, a hybrid testing/verification tool. Our tool, CNnotator, uses LLMs to automatically generate and test CN specifications. We find that current models are able to generate CN specifications for small-to-medium C programs, with the OpenAI o3 reasoning model achieving a 90% success rate on first attempts and 97% overall success, while the chat model GPT-4o correctly annotates 65% of first attempts. These results suggest AI-assisted annotation is becoming practical for real-world C codebases.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。