Skip to main content

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+
This technique remains viable across all glibc versions because it exploits fundamental arena handling logic that hasn’t changed.

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:
  1. Write-Where Primitive: Write heap pointers to arbitrary addresses
  2. Repeatable: Can be done multiple times with different fastbin sizes
  3. Non-Destructive: Doesn’t brick malloc like unsorted bin attack
  4. 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:
When a chunk has the non-main arena bit set, glibc:
  1. Rounds the chunk address down to HEAP_MAX_SIZE boundary (0x4000000)
  2. Treats this location as a heap_info structure
  3. Reads the first field (ar_ptr) as the arena pointer
  4. Uses this arena for all operations

Attack Flow

1

Locate Fake Arena Offset

Calculate where to place the fake arena based on HEAP_MAX_SIZE (0x4000000) alignment:
This will be the address where we need to place our fake heap_info structure.
2

Prepare Fake Arena

Allocate a chunk that will serve as the fake arena and set:
  • system_mem at offset 0x888 to a large value (to pass size checks)
  • Any other arena fields needed for the attack
3

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.
4

Fill Tcache

For glibc 2.26+, fill the tcache for the target fastbin size to ensure the chunk uses fastbin instead of tcache.
5

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.
6

Write to Target

Free the chunk. The fastbin code will write the chunk address to:
By controlling the fake arena location, you control where this write occurs.

Source Code

Walkthrough

The heap_info structure is crucial to this attack:
By placing our controlled data at a HEAP_MAX_SIZE-aligned address, we can make glibc interpret it as a heap_info structure and read our fake ar_ptr value.
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 * 8 bytes
For a 0x60 chunk:
  • Index: 4 (0x60 / 16 = 6, fastbin_index = (6-2) = 4)
  • Offset: 0x10 + (4 * 8) = 0x30
By setting ar_ptr to target - 0x30, the write occurs at exactly target.
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
This makes it much more versatile for multi-stage exploits.
For glibc 2.26+, chunks first go to tcache, not fastbin. You must:
  1. Fill the tcache for the target size (7 chunks)
  2. Then the 8th freed chunk goes to fastbin
Alternatively:
  • Use sizes > 0x410 (above tcache range)
  • Exploit before tcache is initialized
  • Corrupt tcache metadata first

Visual Representation

Common Pitfalls

Issue: Segmentation fault during freeCauses:
  • system_mem not set high enough (must be > chunk size)
  • Next chunk doesn’t have valid size
  • ar_ptr points to invalid memory
Solution: Ensure fake arena is properly initialized with valid system_mem value.
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
Verify the offset in your target glibc version.

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

  • 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

Author

Written by Maxwell Dulin (Strikeout)