Skip to main content

Overview

The House of Gods is an arena hijacking technique for glibc < 2.27 that supplies attackers with arbitrary write capability against the thread_arena symbol of the main thread. By hijacking the arena pointer, attackers gain complete control over heap allocation behavior, enabling trivial escalation to arbitrary code execution. The technique demonstrates how to replace main_arena with a carefully crafted fake arena within only 8-11 allocations.

Glibc Version Compatibility

Compatible with: glibc 2.23 - 2.26 onlyPatched in glibc 2.27+The technique relies on specific arena handling that was changed in glibc 2.27. The underlying bug was reported in Bugzilla #29709.

Requirements

  • 8 Allocations: 8 allocations of arbitrary size to hijack arena (+2 for ACE)
  • Chunk Control: Control over first 5 quadwords of chunk userdata
  • Write-After-Free: Single WAF bug on an unsorted chunk
  • Heap Leak: Need heap address leak
  • Libc Leak: Need libc address leak

What It Achieves

The House of Gods enables:
  1. Arena Hijacking: Replace thread_arena with fake arena
  2. Complete Heap Control: Control all malloc operations
  3. Arbitrary Allocation: Return any pointer from malloc
  4. Fast ACE: Trivial escalation to code execution
  5. Efficient: Only 8-11 allocations needed

Technical Details

The Binmap Attack

The core of House of Gods is the “binmap attack” - allocating a fake chunk that overlaps the binmap field within main_arena.
1

Craft Fake Size via Binmap

Allocate and bin a smallchunk (e.g., 0x90) into smallbin. This triggers mark_bin(m, i) which sets the binmap. The value 0x200 at offset 0x855 in main_arena serves as a valid size field for a fake chunk at offset 0x850.
2

Link Binmap Chunk to Unsorted Bin

Use a write-after-free bug to redirect the unsorted bin to the binmap-chunk at main_arena + 0x850. The main_arena.next pointer at offset 0x868 acts as a valid bk pointer, passing the partial unlink check.
3

Allocate Binmap Chunk

Request a chunk of size 0x1f8 (matching the fake size). This allocates the binmap-chunk, giving control over main_arena.next at offset 0x868.
4

Unsorted Bin Attack on narenas

Perform unsorted bin attack targeting the narenas variable, writing a large value to exceed narenas_limit. This forces subsequent allocations to reuse arenas.
5

Inject Fake Arena

Write the address of a fake arena into main_arena.next. This fake arena will be in the arena list traversal.
6

Trigger reused_arena()

Make two allocations for 0xffffffffffffffc0 bytes (invalid size). This triggers reused_arena() twice:
  • First call: returns main_arena
  • Second call: traverses to main_arena.next, returns fake arena
  • Sets thread_arena to fake arena address!

Source Code

Walkthrough

The binmap is a bitmap in main_arena that tracks which bins contain chunks:
When a chunk is binned, mark_bin(m, i) sets a bit:
For a 0x90 chunk, this sets binmap to 0x200 at offset 0x855.By reading memory at offset 0x850:
This forms size 0x0200, valid for unsorted bin!
When narenas exceeds narenas_limit, malloc calls reused_arena():
The arena list is:
By controlling main_arena.next, we control where the second call goes!First call:
  • Starts at next_to_use (= main_arena)
  • Returns main_arena
Second call:
  • Starts at main_arena (from first call)
  • Traverses to main_arena.next (our fake arena!)
  • Returns fake arena
  • Sets thread_arena = fake_arena
When you request 0xffffffffffffffc0 bytes:
  1. Malloc adds header size: 0xffffffffffffffc0 + 0x10 = 0xffffffffffffffd0
  2. Checks if size > PTRDIFF_MAX (maximum valid size)
  3. Fails size check, returns NULL
  4. Before returning, tries to find working arena
  5. Calls reused_arena() to get a different arena
  6. Retries with new arena
This triggers arena traversal without actually allocating anything!
The fake arena only needs minimal setup:
For fastbin-based arbitrary allocation:
  • Set fastbinsY[index] to target address
  • Ensure target has valid size field
  • Call malloc(size) to get target back
For more advanced attacks, populate more fields.

Visual Representation

CTF Challenges

No specific challenges listed, but applicable to:
  • CTF challenges on Ubuntu 16.04 (glibc 2.23)
  • Old challenges on glibc 2.24-2.26
  • Historical heap exploitation challenges

References

  • House of Mind - Another arena manipulation technique
  • House of Orange - File stream exploitation with arena
  • [Unsorted Bin Attack/techniques/bins/unsorted-bin-attack) - Used in this technique

Author

David Milosevic (milo)