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

C语言的反思及其在库健壮性中的应用

Introspection for C and its Applications to Library Robustness

Manuel Rigger, Rene Mayrhofer, Roland Schatz, Matthias Grimmer, Hanspeter Mössenböck

摘要:

内容:在C语言中,低级错误(如缓冲区溢出和释放后使用)是一个主要问题,因为它们会导致安全漏洞和难以发现的错误。C缺乏自动检查,程序员不能应用防御性编程技术,因为对象(例如,数组或结构)缺乏有关边界、生存期和类型的运行时信息。咨询电话:当前处理低级错误的方法包括动态工具,如边界或类型检查器,它们在程序执行期间检查某些操作。如果检测到错误,它们通常会中止执行。尽管它们将运行时信息作为运行时的一部分进行跟踪,但它们并不向程序员公开这些信息。方法:我们设计了一个内省接口,允许C程序员访问运行时信息并查询对象边界、对象生命周期、对象类型以及有关可变参数的信息。这使库编写器能够检查无效输入或程序状态,从而实现自定义错误处理,以维护系统可用性,并且不会在良性错误时终止。当我们假设内省与实现自动检查的动态工具一起使用时,应用程序逻辑中未处理的错误继续导致动态工具中止执行。知识:使用内省接口,我们实现了一个更健壮、源代码兼容的C标准库版本,该库验证其函数的参数。库函数对未定义的行为做出反应;例如,它们可以检测潜在的缺陷,处理未终止的字符串,检查格式字符串参数,并在检测到良性使用错误时设置errno。接地:现有的动态工具保持运行时的信息,可用于实现的内省接口,我们证明了它的实现在安全苏龙,解释器和动态的错误查找工具C,运行在Java虚拟机上,因此可以很容易地暴露相关的运行时信息。重要性:在用户代码中使用内省是解决C中长期存在的低级错误问题的一种新方法。随着新方法降低运行时信息维护的性能开销,C的动态运行时的使用可能会变得更加普遍,这最终可能会促进这种内省接口的更广泛的实现。

英文摘要:

Context: In C, low-level errors, such as buffer overflow and use-after-free, are a major problem, as they cause security vulnerabilities and hard-to-find bugs. C lacks automatic checks, and programmers cannot apply defensive programming techniques because objects (e.g., arrays or structs) lack run-time information about bounds, lifetime, and types. Inquiry: Current approaches to tackling low-level errors include dynamic tools, such as bounds or type checkers, that check for certain actions during program execution. If they detect an error, they typically abort execution. Although they track run-time information as part of their runtimes, they do not expose this information to programmers. Approach: We devised an introspection interface that allows C programmers to access run-time information and to query object bounds, object lifetimes, object types, and information about variadic arguments. This enables library writers to check for invalid input or program states and thus, for example, to implement custom error handling that maintains system availability and does not terminate on benign errors. As we assume that introspection is used together with a dynamic tool that implements automatic checks, errors that are not handled in the application logic continue to cause the dynamic tool to abort execution. Knowledge: Using the introspection interface, we implemented a more robust, source-compatible version of the C standard library that validates parameters to its functions. The library functions react to otherwise undefined behavior; for example, they can detect lurking flaws, handle unterminated strings, check format string arguments, and set errno when they detect benign usage errors. Grounding: Existing dynamic tools maintain run-time information that can be used to implement the introspection interface, and we demonstrate its implementation in Safe Sulong, an interpreter and dynamic bug-finding tool for C that runs on a Java Virtual Machine and can thus easily expose relevant run-time information. Importance: Using introspection in user code is a novel approach to tackling the long-standing problem of low-level errors in C. As new approaches are lowering the performance overhead of run-time information maintenance, the usage of dynamic runtimes for C could become more common, which could ultimately facilitate a more widespread implementation of such an introspection interface.

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

↑