计算机科学 ›› 2025, Vol. 52 ›› Issue (11A): 241100060-8.doi: 10.11896/jsjkx.241100060

• 信息安全 • 上一篇    下一篇

一种结合静态分析的轻量化内存安全运行时检测方法

毛瑞琪1, 陈哲1,2   

  1. 1 南京航空航天大学计算机科学与技术学院 南京 211106
    2 软件新技术与产业化协同创新中心 南京 211106
  • 出版日期:2025-11-15 发布日期:2025-11-10
  • 通讯作者: 陈哲(zhechen@nuaa.edu.cn)
  • 作者简介:maoruiqi714@qq.com
  • 基金资助:
    国家自然科学基金(62172217);国家自然科学基金委员会-中国民航局民航联合研究基金(U1533130)

Lightweight Memory Safety Runtime Detection Method Combined with Static Analysis

MAO Ruiqi1, CHEN Zhe1,2   

  1. 1 College of Computer Science and Technology,Nanjing University of Aeronautics and Astronautics,Nanjing 211106,China
    2 Collaborative Innovation Center of Novel Software Technology and Industrialization,Nanjing 211106,China
  • Online:2025-11-15 Published:2025-11-10
  • Supported by:
    National Natural Science Foundation of China(62172277)and Joint Research Funds of National Natural Science Foundation of China and Civil Aviation Administration of China(U1533130).

摘要: 缓冲区溢出等内存安全问题长久困扰C语言开发者。运行时检测是解决C语言内存安全问题的可靠方法,但也引入了较高的运行时开销。现存的内存安全运行时检测开销削减方法或不兼容已有代码、依赖人工标注,或在削减开销的同时引入漏报和误报,或无法保证非法访存和检测报错的时序性。对此,提出了一种结合静态分析的针对栈上内存区域的轻量化运行时检测方法,将部分运行时元数据查询替换为编译时元数据查询,将大部分高开销的检测函数调用替换为轻量化的内联布尔条件判断,并使用跨过程的按需别名分析将方法扩展到跨过程分析、全程序检测。基于C语言抽象语法树进行静态分析和检测代码插桩,实现了原型工具LISA(Lightweight Inline Safety Assertion)。实验结果表明,LISA降低运行时检测的时间开销平均达36%,仅引入约0.5%额外的空间开销。此外,LISA还解决了现存方法不兼容已有代码、运行时检测有效性低、无法实时保证内存安全的问题。

关键词: 内存安全, 运行时检测, 静态分析, 源代码插桩, 别名分析

Abstract: Memory safety issues,such as buffer overflow,have long troubled C language developers.Runtime detection is a reliable solution to C language memory safety problems,but it introduces significant runtime overhead.Existing methods to reduce runtime overhead for memory safety detection may be incompatible with existing code,depend on manual annotations,introduce false negatives and positives,or fail to ensure timing consistency between illegal memory access and error reporting.This paper proposes a lightweight runtime detection method for stack memory regions,which combines static analysis to replace certain runtime metadata lookups with compile-time metadata checks,and replaces most high-overhead detection function calls with inline Boolean condition checks.The method also uses on-demand interprocedural alias analysis to extend detection to interprocedural and whole-program analysis.A prototype tool,LISA(Lightweight Inline Safety Assertion),was implemented with static analysis and detection code instrumentation based on the C language abstract syntax tree.Experiments show that LISA reduces runtime detection overhead by an average of 36%,with only about 0.5% additional space overhead.Furthermore,LISA addresses compatibility with existing code,enhances runtime detection effectiveness,and ensures real-time memory safety,overcoming limitations of previous methods.

Key words: Memory safety, Runtime verification, Static analysis, Source level instrumentation, Alias analysis

中图分类号: 

  • TP309
[1]YE D,SU Y,SUI Y,et al.WPBOUND:Enforcing Spatial Memo-ry Safety Efficiently at Runtime with Weakest Preconditions[C]//IEEE 25th International Symposium on Software Reliabi-lity Engineering.2014:88-99.
[2]CHEN Z,WANG C,YAN J,et al.Runtime Detection of Memory Errors with Smart Status[C]//30th ACM SIGSOFT International Symposium on Software Testing and Analysis.2021:296-308.
[3]SANTOSH N,JIANZHOU Z,MILO M,et al.SoftBound:highly compatible and complete spatial memory safety for C[C]//Proceedings of the 2009 ACM SIGPLAN Conference on Programming Language Design and Implementation.2009:245-258.
[4]KONSTANTIN S,DEREK B,ALEXANDER P,et al.AddressSanitizer:A Fast Address Sanity Checker[C]//2012 USENIX Annual Technical Conference.2012:309-318.
[5]NICHOLAS N,JULIAN S.Valgrind:a framework for heavy-weight dynamic binary instrumentation[C]//Proceedings of the ACM SIGPLAN 2007 Conference on Programming Language Design and Implementation.2007:89-100.
[6]GEORGE C,JEREMY C,MATTHEW H,et al.CCured:type-safe retrofitting of legacy software[J].ACM Transactions on Programming Languages and Systems,2005,27(3):477-526.
[7]ARCHIBALD S,ANDREW R,MICHAEL H,et al.Checked C:Making C Safe by Extension[C]//2018 IEEE Cybersecurity Development.2018:53-60.
[8]JONAS W,VOLODYMYR K,GEORGEC,et al.High system-code security with low overhead[C]//IEEE Symposium on Security and Privacy.2015:866-879.
[9]ZHANG J,WANG S,MANUEL R,et al.SANRAZOR:Reducing Redundant Sanitizer Checks in C/C++ Programs[C]//15th USENIX Symposium on Operating Systems Design and Implementation.2021:479-494.
[10]ZHANG Y,LIU T,SUN Z,et al.Catamaran:Low-overheadmemory safety enforcement via parallel acceleration[C]//Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis.2023:816-828.
[11]CHEN Z,WANG C,KAN S L,et al.Detecting Memory Errors at Runtime with Source-Level Instrumentation[C]//Procee-dings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis.2019:341-351.
[12]CHEN Z,WU J,ZHANG Q,et al.A Dynamic Analysis Tool for Memory Safety Based on Smart Status and Source-Level Instrumentation[C]//Proceedings of the 44th ACM/IEEE International Conference on Software Engineering.2022:22-24.
[13]CHEN Z,ZHANG Q,WU J,et al.A Source-Level Instrumentation Framework for the Dynamic Analysis of Memory Safety[J].IEEE Transactions on Software Engineering,2023,49(4):2107-2127.
[14]CHEN Z,YAN R,MA Y Z,et al.A Smart Status Based Monitoring Algorithm for the Dynamic Analysis of Memory Safety[J].ACM Transactions on Software Engineering and Methodo-logy,2024,33(4):1-17.
[15]MATTHEW G,JEFFREY S,DAN E,et al.MiBench:A free,commercially representative embedded benchmark suite[C]//Proceedings of the IEEE 4th Annual Workshop on Workload Characterization.2001:3-14.
[16]Facebook infer[EB/OL].https://fbinfer.com/.
[17]Clang static analyzer[EB/OL].https://clang-analyzer.llvm.org/
[18]SUI Y,YE D,XUE J.Static memory leak detection using full-sparse value-flow analysis[C]//Proceedings of the 2012 International Symposium on Software Testing and Analysis.2012:254-264.
[19]International Organization for Standardization,ISO/IEC 9899:1999:Programming Languages-C[S].ISO,1999.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!