TL;DR
FreeGuard is a novel secure heap allocator that bridges the gap between high-performance "insecure" allocators and slow "secure" ones. By combining a "Big Bag of Pages" (BIBOP) layout with protected freelists and shadow memory, it provides robust defense against heap overflows and use-after-free attacks with a negligible performance overhead of less than 2%.
What Problem Does This Paper Address?
Memory management in C/C++ is a notorious source of security vulnerabilities. Attacks like heap overflows, use-after-free (UAF), and double-frees allow hackers to leak information or hijack program control flow.
Historically, developers have faced a "security vs. speed" dilemma:
- Performance-oriented allocators (like the default Linux
glibcorHoard) are fast but store metadata (like object sizes) right next to the data. This makes it trivial for an overflow to corrupt the allocator's internal state. - Secure allocators (like
OpenBSDorDieHarder) isolate metadata and randomize memory placement to stop attacks, but they often pay a heavy price—sometimes running 20% to 100% slower (or more) than standard allocators.
The authors of FreeGuard set out to create an allocator that offers the security of the latter with the speed of the former.
Methods
FreeGuard achieves its goals through a "best of both worlds" architecture:
- BIBOP-style Layout with Sequential Placement: It uses a "Big Bag of Pages" approach where objects of the same size are grouped together. Leveraging the vast 64-bit address space, it places these "bags" sequentially, which allows the allocator to calculate metadata locations in constant time without expensive hash table lookups.
- Segregated Shadow Memory: Unlike
glibc, which prepends metadata to objects, FreeGuard stores all management data (freelists and object status) in a separate "shadow memory" area. This prevents attackers from overwriting allocator internals via a simple buffer overflow. - Protected Freelists: While most secure allocators avoid "freelists" (lists of available memory chunks) because they are hard to protect, FreeGuard uses them for speed but stores the pointers in shadow memory. It maintains four separate freelists per size class per thread to improve scalability and randomization.
- Randomized Guard Pages & Canaries: FreeGuard randomly inserts "guard pages" (inaccessible memory) within the heap to catch overflows. It also adds a 1-byte "canary" at the end of objects, checking its integrity whenever memory is freed.
- Fast RNG: To avoid the performance bottlenecks of standard random number generators (which often use global locks), FreeGuard implements a high-speed pseudo-random number generator optimized with Intel SSE2 instructions.
Datasets
The authors evaluated FreeGuard using:
- PARSEC Benchmark Suite: 11 multi-threaded applications used to measure performance and scalability.
- Real-world Applications: High-traffic software including the Apache web server, Firefox browser, MySQL, Memcached, and SQLite.
- Vulnerability Benchmarks: A collection of 10 real-world buggy programs (e.g.,
bc-1.06,gzip-1.2.4, and the infamous Heartbleed bug in OpenSSL) to test defensive effectiveness.
Key Insights and Ideas
- The Bitmap Bottleneck: The researchers identified that many secure allocators are slow because they use bitmaps to track free memory. Searching a bitmap for a free slot is much slower than popping an item off a freelist. FreeGuard proves you can use freelists securely if you isolate them in shadow memory.
- FIFO as a Security Feature: By reusing freed memory in a First-In-First-Out (FIFO) order, FreeGuard naturally increases the time between an object being freed and its memory being reused. This "temporal isolation" makes use-after-free attacks significantly harder to execute.
- 64-bit Optimization: The paper highlights how the massive address space of modern 64-bit systems can be traded for performance. By mapping a huge virtual memory range upfront, they eliminate the need for frequent, slow system calls (
mmap) and simplify metadata tracking.
Key Results
- Performance: FreeGuard's overhead is remarkably low—less than 2% on average compared to
glibc. In contrast, the OpenBSD allocator showed a 22-34% overhead, and DieHarder was 36-88% slower. - Security: In testing against 10 real-world vulnerabilities, FreeGuard successfully prevented or mitigated all of them, including stopping the Heartbleed information leak and preventing crashes from double-frees in PHP.
- Scalability: Because it uses per-thread heaps, FreeGuard avoids "false sharing" issues that plague other secure allocators, allowing it to maintain high performance even on multi-core systems.
Limitations and Future Work
- Entropy Trade-off: To maintain its high speed, FreeGuard provides slightly less "randomness" (entropy) in memory placement than a tool like
DieHarder. It uses 2 bits of entropy for list selection, whereas others may offer more. - Memory Footprint: FreeGuard uses about 20% more physical memory than
glibc. This is due to internal fragmentation (using power-of-two size classes) and the 10% budget allocated for guard pages. - Information Leakage: While FreeGuard hides metadata, the authors acknowledge that if an attacker can read the entire memory map (e.g., via
/proc/self/maps), they could potentially calculate the location of the shadow memory, though ASLR makes this difficult. - Future Work: The authors suggest exploring ways to further reduce memory overhead without sacrificing the performance gains achieved by their sequential layout.
Summary updated