Skip to main content

Overview

The House of Lore is a sophisticated heap exploitation technique that abuses the smallbin freelist to force malloc to return a nearly-arbitrary pointer. This technique is particularly interesting because it bypasses the hardening checks introduced in modern glibc versions.
This is an advanced exploitation technique that requires understanding of glibc’s bin management and double-linked list structures.

Glibc Version Compatibility

Ret2 Wargames Practice: Try this technique hands-on at House of Lore Interactive Challenge

What This Technique Achieves

The House of Lore enables:
  • Stack allocation: Force malloc to return a pointer to the stack
  • Arbitrary pointer allocation: Get malloc to return nearly any address
  • Control flow hijacking: Overwrite return addresses or function pointers on the stack
  • Bypass modern hardening: Works even with glibc’s double-linked list corruption checks

Prerequisites and Constraints

This technique requires:
  1. Heap overflow or UAF: Ability to overwrite a freed chunk’s bk pointer
  2. Fake chunk setup: Ability to create fake chunks with proper fd/bk pointers
  3. Tcache bypass: Must fill tcache (7 chunks) before targeting smallbin
  4. Size knowledge: Target size must be in smallbin range (>= 128 bytes on x64)
  5. Fake freelist: Need to set up a chain of fake chunks to prevent crashes

How It Works

1

Allocate the victim chunk

Allocate a chunk in smallbin range (>= 0x100 bytes) that will later be corrupted.
2

Fill the tcache

Allocate and free 7 dummy chunks of the same size to fill tcache.
3

Create fake chunks on stack

Set up a chain of fake chunks with proper fd/bk pointers to bypass corruption checks.
4

Free victim into smallbin

Free the victim chunk and trigger smallbin sorting.
5

Corrupt the victim's bk pointer

Overwrite victim->bk to point to your fake chunk.
6

Drain tcache and allocate

Take out all tcache chunks, then allocate twice to get the fake chunk.

Complete Source Code

Technical Deep Dive

Smallbin Corruption Checks

Glibc introduced hardening to detect smallbin corruption:
To bypass this check:
  1. Set stack_buffer_1->fd = victim_chunk so bck->fd == victim
  2. When we corrupt victim->bk = stack_buffer_1, the check passes

The Allocation Chain

When we allocate from the corrupted smallbin:

Smallbin-to-Tcache Mechanism

On glibc 2.26+, when allocating from smallbin, chunks are first moved to tcache:
This is why we need the fake freelist - to prevent crashes when chunks are moved to tcache.

Why Two Fake Chunks?

We need two fake chunks because:
  1. First fake chunk (stack_buffer_1): This is what we’ll get from malloc
  2. Second fake chunk (stack_buffer_2): This passes the double-linked list check for stack_buffer_1
The check validates: stack_buffer_1->bk->fd == stack_buffer_1

Common Pitfalls

Forgot Fake Freelist: Without the fake freelist chain, the smallbin-to-tcache mechanism will crash when trying to traverse the corrupted list.
Wrong Size Range: House of Lore only works with smallbin sizes (>= 0x100 bytes on x64). For smaller sizes, use House of Spirit or fastbin techniques.
Tcache Not Filled: If tcache isn’t full, allocations will come from tcache instead of smallbin, and the corruption won’t be reached.

Exploitation Strategies

Stack-Based Exploitation

  1. Create fake chunks on the stack
  2. Use House of Lore to get a stack pointer from malloc
  3. Write shellcode pointer or overwrite return address
  4. Jump over stack canary to avoid detection

Heap Feng Shui

  1. Shape the heap to place victim chunk near target
  2. Use overflow to corrupt victim->bk
  3. Get allocation at target location
  4. Overwrite sensitive data structures

Mitigations

This technique remains unpatched but faces several mitigations:
  • Tcache: Makes exploitation more complex by requiring tcache bypass
  • Double-linked list checks: Requires more sophisticated fake chunk setup
  • Metadata validation: Some implementations add additional checks
  • Safe linking (glibc 2.32+): Doesn’t affect smallbin but makes related techniques harder

Unsafe Unlink

Related technique exploiting double-linked list manipulation

Tcache Stashing Unlink

Modern variant combining tcache and smallbin exploitation

See Also