S3Library: Automatically Eliminating C/C++ Buffer Overflow using Compatible Safer Libraries

Kang Sun, Daliang Xu, Dongwei Chen, Xu Cheng, Dong TongarXiv 2020

Abstract

Buffer overflows remain a critical vulnerability in C/C++ software, yet safer alternatives like C11 Annex K have seen limited adoption due to binary incompatibility and the need for manual code refactoring. This paper presents S3Library, a drop-in security reinforcement that automatically replaces unsafe string and memory functions with safer, "failure-oblivious" versions. By leveraging a compact tagged-pointer scheme called MinFat and a novel Saturation Memory Access (SMA) mechanism, S3Library eliminates buffer overflows without requiring source code changes or breaking the Application Binary Interface (ABI).

Introduction

C and C++ are notorious for memory safety issues, with buffer overflows accounting for a significant portion of severe software flaws. While the C11 standard introduced safer function variants (e.g., strcpy_s), these require programmers to manually update millions of lines of code to include explicit size arguments. Furthermore, existing dynamic defenses often impose high performance overheads (50–150%) or break binary compatibility by using "fat pointers."

S3Library addresses these challenges by providing a middle ground: a fully automatic solution that maintains high system availability and keeps performance costs low enough for production environments. It achieves this by embedding metadata directly into pointers and redirecting illegal accesses to safe zones rather than crashing the program.

Methodology

S3Library is implemented as an LLVM compiler pass that instruments code during compilation. It introduces two core innovations to handle memory safety transparently.

MinFat Pointers

On modern 64-bit systems, many bits in a virtual address are effectively unused. S3Library utilizes the upper 6 bits of a pointer to store a "tag" representing the log2 of the allocated object's size. Because all objects are aligned to powers of two, the system can instantly calculate the base and bounds of any object using simple bitwise operations. This avoids the need for slow, external lookup tables or ABI-breaking fat pointers.

The MinFat pointer layout uses 6 bits for the size tag and 58 bits for the virtual address, allowing for efficient metadata storage without breaking binary compatibility.

Saturation Memory Access (SMA)

Unlike traditional "fail-stop" security tools that crash a program upon detecting an overflow, S3Library adopts a "failure-oblivious" approach. If a library function attempts an out-of-bounds write, SMA redirects that write to a "boundless" padding area at the end of the power-of-two memory block. This isolates the error, prevents the corruption of adjacent objects, and allows the program to continue execution safely.

Comparison of memory access handling between legacy functions, C11 Annex K, and S3Library's Saturation Memory Access (SMA).

Evaluation and Results

The authors evaluated S3Library using industry-standard benchmarks including SPEC CPU2006, the RIPE benchmark, and the NIST SARD (Juliet Test Suite).

  • Security: S3Library successfully prevented 100% of the 735 attacks in the RIPE benchmark and all 1,939 vulnerabilities tested from the NIST Juliet suite (CWE-121 and CWE-122).
  • Performance: The average runtime overhead on SPEC CPU2006 was 32.42%. While not negligible, this is significantly lower than comprehensive bounds-checking solutions that often exceed 100% overhead.
  • Real-World Viability: When applied to the Nginx web server, the system showed only a 6.6% increase in latency and a negligible 0.5% increase in memory usage, demonstrating its suitability for high-performance network applications.

Discussion and Conclusion

S3Library prioritizes system availability by "saturating" illegal addresses rather than interrupting service. This is particularly valuable for mission-critical systems where a crash can be as detrimental as a vulnerability. By "hiding" size information inside the pointer itself, S3Library enables the use of safer functions without requiring programmers to pass explicit size arguments.

However, the system has limitations. It currently only protects memory accesses within standard library functions, not custom user-written loops. Additionally, programs that perform non-standard bit-level manipulations on pointers may conflict with the MinFat tagging scheme. Future work will focus on expanding protection to POSIX functions and exploring hardware-assisted pointer masking (such as ARM's Top Byte Ignore) to further reduce overhead.

Summary updated

BibTeX
@misc{sun2020s,
  author = {Kang Sun and Daliang Xu and Dongwei Chen and Xu Cheng and Dong Tong},
  title = {{S3Library: Automatically Eliminating C/C++ Buffer Overflow using Compatible Safer Libraries}},
  year = {2020},
  eprint = {2004.09062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.09062},
}
Figure