Overview
Mmap overlapping chunks is a variation of the overlapping chunks technique that targets large, mmap-allocated chunks instead of regular heap chunks. Unlike the traditional overlapping chunks attack (patched in glibc 2.29), this technique still works on all glibc versions including the latest releases.Written by Maxwell Dulin (Strikeout)This technique works on all versions of glibc and targets the special behavior of mmap-allocated chunks.
Glibc Version Compatibility
Working Versions
All glibc versions (2.23 - 2.41+)
Status
Still working in modern glibc!
What Does This Technique Achieve?
Mmap overlapping chunks allows you to:- Overlap mmap regions - create aliased memory mappings
- Bypass heap protections - operates outside normal heap bins
- Munmap libraries - free system libraries or other mmap regions
- Read/write through aliasing - access same memory through multiple pointers
Mmap Chunks Primer
What Are Mmap Chunks?
In glibc, very large allocations (typically > 128KB) are handled differently:- Regular heap: Uses
brk()system call, managed in bins - Mmap chunks: Uses
mmap()system call, allocated in separate memory regions
mmap_threshold (default: 128KB, max: 512KB on 32-bit, larger on 64-bit).
Mmap Chunk Structure
- Size bit 1 (IS_MMAPPED) is set
- No fd/bk pointers - mmap chunks don’t go into bins
- Page aligned - must be aligned to page boundaries
- Direct munmap - freed by calling
munmap()directly
Memory Layout with Mmap
The first mmap chunk goes above libc, but subsequent allocations go below libc in descending addresses.
The Vulnerability
This attack requires:- Heap overflow or UAF - ability to corrupt mmap chunk size/prev_size
- Three large allocations - to set up the overlap scenario
- Free the corrupted chunk - trigger munmap with wrong size
Technical Details
Munmap with Corrupted Size
When freeing an mmap chunk:size field, we can make munmap() free more memory than was originally allocated, including adjacent mmap chunks!
Size Requirements
For the attack:- Original size: Size of the allocated chunk
- Corrupted size: Original size + size of overlapping chunk
- Both sizes must have the IS_MMAPPED bit (0x2) set
Step-by-Step Exploitation
1
Allocate Large Chunks
Create three mmap chunks:
The first chunk goes above libc, but chunks 2 and 3 are adjacent in memory below libc.
2
Examine Chunk Metadata
Check the original size field:The size field format:
- Bit 0: PREV_INUSE
- Bit 1: IS_MMAPPED (always 1 for mmap chunks)
- Bit 2: NON_MAIN_ARENA
- Remaining bits: actual size
3
Corrupt Size Field
Increase the size to include the adjacent chunk:
4
Free to Trigger Munmap
Free the corrupted chunk:Now both
mmap_chunk_2 and mmap_chunk_3 point to unmapped memory. Accessing them will crash:5
Reallocate Overlapping Region
Allocate a larger chunk to reclaim the freed region:
After freeing an mmap chunk,
mmap_threshold increases to the size of the freed chunk. Your next allocation must be larger than this threshold to get an mmap chunk.6
Exploit the Overlap
Use the overlap to write through both pointers:
Full Source Code
View Complete Exploit Code
View Complete Exploit Code
Advanced Attack Scenarios
1. Munmapping System Libraries
2. Munmapping the Heap
3. Information Disclosure
The Mmap Threshold
Key Concept: After freeing an mmap chunk,
mmap_threshold is updated to the size of the freed chunk.Why This Still Works
Unlike regular overlapping chunks (patched in 2.29), mmap overlapping chunks remain unpatched because:- No bin management - mmap chunks don’t go through unsorted bin checks
- Direct syscalls -
munmap()is called directly without validation - Performance - adding checks would slow down all large allocations
- Less common - fewer programs use extremely large allocations
Debugging Tips
Checking if Chunk is Mmapped
Finding Mmap Chunks in GDB
Calculating Distance
Exploitation Checklist
1
Verify mmap allocation
Ensure chunks are large enough (> 128KB)
2
Identify adjacent chunks
Find two mmap chunks that are adjacent in memory
3
Calculate combined size
Properly combine sizes while preserving IS_MMAPPED bit
4
Corrupt and free
Trigger munmap with corrupted size
5
Reallocate larger
Allocate chunk bigger than new mmap_threshold
6
Exploit overlap
Use aliased pointers for your attack
Related Techniques
- Overlapping Chunks - Regular heap variant (patched)
- [House of Force/techniques/house/house-of-force) - Another top chunk manipulation
