Overview
The House of Botcake is a heap exploitation technique that bypasses the double-free restriction on tcache introduced in glibc 2.29. The technique creates overlapping chunks by combining:- Filling the tcache to force chunks into unsorted bin
- Consolidation in unsorted bin
- Double-free into tcache after tcache has space
- Chunk overlapping to control tcache metadata
Glibc Version Compatibility
Compatible with: glibc 2.26 and later (all modern versions)Works best on: glibc 2.29+ where simple tcache double-free is patched
- glibc 2.26 - 2.28: Works but simple double-free also works
- glibc 2.29+: Essential technique since direct tcache double-free is prevented
Requirements
- Double Free: Ability to free the same chunk twice
- Heap Control: Ability to allocate and free chunks of specific sizes
- No Leak Required: The basic primitive doesn’t require address leaks
- Safe-Linking Bypass: For glibc 2.32+, may need heap leak to bypass mangling
What It Achieves
The House of Botcake enables:- Chunk Overlapping: Create overlapping heap chunks
- Tcache Poisoning: Control tcache freelist metadata
- Arbitrary Allocation: Force malloc to return arbitrary pointers
- Memory Corruption: Read/write to overlapping memory regions
Technical Details
Attack Flow
Fill Tcache
Allocate 7 chunks of the target size and free them to fill the tcache for that size class. This ensures the next freed chunk goes to the unsorted bin instead of tcache.
Setup Victim Chunks
Allocate three chunks:
prev: Will be consolidated with victimvictim: The chunk we’ll double-freepadding: Prevents consolidation with top chunk
Create Consolidation
Free the victim chunk (goes to unsorted bin because tcache is full), then free the prev chunk. These consolidate into a single larger chunk in the unsorted bin.
Double Free into Tcache
Allocate one chunk from tcache to make room, then free the victim chunk again. Since the tcache has space and the victim chunk’s metadata hasn’t been overwritten, it goes into tcache despite already being part of a consolidated chunk.
Exploit Overlap
Allocate the large consolidated chunk from unsorted bin. This overlaps with the victim chunk that’s still in tcache. Use the overlapping chunk to overwrite the victim’s fd pointer in tcache.
Source Code
Walkthrough
Why Does This Bypass Double-Free Protection?
Why Does This Bypass Double-Free Protection?
The tcache double-free protection (added in glibc 2.29) works by setting a
key field in freed tcache chunks. When freeing a chunk into tcache, glibc checks if the chunk’s key matches the tcache structure address, indicating it’s already in tcache.House of Botcake bypasses this by:- First freeing the chunk when tcache is FULL → chunk goes to unsorted bin (no key set)
- Consolidating the chunk in unsorted bin → the chunk is now part of a larger chunk
- Making space in tcache, then freeing the original chunk again → since tcache has space and the key wasn’t set (chunk went to unsorted bin, not tcache), the free succeeds
Chunk Overlapping Explained
Chunk Overlapping Explained
After the double-free, we have:We can now use the large chunk to overwrite the victim’s tcache metadata (next pointer), enabling tcache poisoning.
- A large consolidated chunk in unsorted bin (size 0x220 in the example)
- The victim chunk (size 0x110) in tcache
- These two chunks overlap in memory!
Safe-Linking Considerations (glibc 2.32+)
Safe-Linking Considerations (glibc 2.32+)
Starting from glibc 2.32, tcache next pointers are “mangled” with safe-linking:To poison tcache, you need to:Without safe-linking (glibc 2.29-2.31), you can simply write:
- Know the heap address (for the
ptr >> 12part) - requires heap leak - Calculate the mangled value correctly
Visual Representation
Common Issues
Issue: Heap corruption detectedEnsure proper alignment and size calculations. The consolidated chunk must properly overlap the victim chunk. Use padding chunks to prevent unwanted consolidation.
CTF Challenges
No specific challenges listed, but this technique is applicable to:- Any challenge with double-free vulnerability on glibc 2.29+
- Challenges requiring tcache poisoning without direct double-free
- Modern CTF heap challenges
References
Related Techniques
- [Tcache Poisoning/techniques/tcache/tcache-poisoning) - Basic tcache exploitation
- Tcache Dup - Original double-free (obsolete on 2.29+)
- [Overlapping Chunks/techniques/bins/overlapping-chunks) - General chunk overlapping
