Overview
The House of Mind - Fastbin Variant is a powerful heap exploitation technique that creates a fake non-main arena to achieve a write-where primitive through fastbin manipulation. By controlling arena handling and exploiting how glibc locates arena structures, attackers can write heap pointers to arbitrary locations. This is a modern variant of the classic House of Mind attack, adapted for fastbin exploitation.Glibc Version Compatibility
Compatible with: All glibc versions including latestWorks on: glibc 2.23 through 2.41+
Requirements
- Heap Leak: Need to know heap address for fake arena location
- Unlimited Allocations: Ability to allocate many chunks to reach target heap offset
- Single Byte Overflow: Ability to overwrite chunk size to set non-main arena bit
- Proper Sizing: Target location must have valid size value for validation
- Next Chunk Valid: The next chunk must have valid size between 0x20 and system_mem
What It Achieves
The House of Mind - Fastbin Variant enables:- Write-Where Primitive: Write heap pointers to arbitrary addresses
- Repeatable: Can be done multiple times with different fastbin sizes
- Non-Destructive: Doesn’t brick malloc like unsorted bin attack
- Arena Control: Manipulate arena handling for advanced attacks
Technical Details
Arena Resolution Process
Glibc uses arena metadata to manage multiple heaps efficiently. The key macros are:- Rounds the chunk address down to
HEAP_MAX_SIZEboundary (0x4000000) - Treats this location as a
heap_infostructure - Reads the first field (
ar_ptr) as the arena pointer - Uses this arena for all operations
Attack Flow
Locate Fake Arena Offset
Calculate where to place the fake arena based on This will be the address where we need to place our fake
HEAP_MAX_SIZE (0x4000000) alignment:heap_info structure.Prepare Fake Arena
Allocate a chunk that will serve as the fake arena and set:
system_memat offset 0x888 to a large value (to pass size checks)- Any other arena fields needed for the attack
Allocate to Target Offset
Allocate chunks repeatedly until reaching the calculated fake arena offset. Place the fake
heap_info structure with ar_ptr pointing to your fake arena.Fill Tcache
For glibc 2.26+, fill the tcache for the target fastbin size to ensure the chunk uses fastbin instead of tcache.
Trigger Arena Lookup
Set the non-main arena bit on a fastbin chunk’s size field:When this chunk is freed, glibc will use
arena_for_chunk() which will find your fake arena.Source Code
Walkthrough
Understanding heap_info Structure
Understanding heap_info Structure
The By placing our controlled data at a
heap_info structure is crucial to this attack:HEAP_MAX_SIZE-aligned address, we can make glibc interpret it as a heap_info structure and read our fake ar_ptr value.Fastbin Write Offset Calculation
Fastbin Write Offset Calculation
When a fastbin chunk is freed, glibc writes to:The offset from arena base to the write location is:
- Base offset to fastbinsY: 0x10 (in glibc 2.31+)
- Index offset:
size/16 * 8bytes
- Index: 4 (0x60 / 16 = 6, fastbin_index = (6-2) = 4)
- Offset: 0x10 + (4 * 8) = 0x30
ar_ptr to target - 0x30, the write occurs at exactly target.Why This Doesn't Break Malloc
Why This Doesn't Break Malloc
Unlike the unsorted bin attack which corrupts bin structures, this technique:
- Only writes to a single fastbin entry
- Doesn’t corrupt critical malloc metadata
- Can be repeated with different fastbin sizes
- Leaves malloc in a working state
Tcache Considerations
Tcache Considerations
For glibc 2.26+, chunks first go to tcache, not fastbin. You must:
- Fill the tcache for the target size (7 chunks)
- Then the 8th freed chunk goes to fastbin
- Use sizes > 0x410 (above tcache range)
- Exploit before tcache is initialized
- Corrupt tcache metadata first
Visual Representation
Common Pitfalls
Issue: Write goes to wrong locationThe write offset depends on:
- Fastbin index (determined by chunk size)
- Glibc version (fastbinsY offset may vary)
- Arena structure layout
CTF Challenges
No specific challenges listed, but applicable to:- Challenges with heap leaks and overflow primitives
- Multi-stage exploits requiring multiple writes
- Scenarios where unsorted bin attack would break malloc
References
- Original House of Mind - Original Phrack article
- Ret2 Wargames Interactive Demo
- Maxwell Dulin’s Blog Post
Related Techniques
- House of Gods - Arena hijacking technique
- [Unsorted Bin Attack/techniques/bins/unsorted-bin-attack) - Simpler write-where primitive
- House of Orange - Another arena manipulation technique
