Overview
Sysmalloc Int Free is a technique that exploits glibc’s heap growth mechanism to force the allocator to free the Top Chunk (Wilderness). By corrupting the Top Chunk’s size and triggering heap expansion, we can makesysmalloc call _int_free() on the old Top Chunk, converting it into a usable bin that can be reallocated.
Glibc Compatibility: Works on all modern glibc versions (tested from 2.27 to 2.41). This is a fundamental behavior of the allocator.
What It Achieves
This technique allows you to:- Free the Top Chunk without calling free(): Useful when you can’t directly call free
- Create nearly arbitrary sized bins: Control what bin the freed Top Chunk goes into
- Corrupt heap without free primitive: Achieve heap corruption with only malloc + overflow
- Enable House of Orange and House of Tangerine: Core primitive for these techniques
The Fundamental Mechanism
Whenmalloc requests more memory than the Top Chunk can provide, sysmalloc is called to grow the heap. If the corrupted Top Chunk cannot be merged with newly allocated memory, sysmalloc will free it:
Full Source Code
Step-by-Step Walkthrough
Calculate Required Allocation
Compute the exact size to allocate such that corrupting the Top Chunk will leave a specific freed size:
Corrupt Top Chunk Size
Overwrite the Top Chunk size to be smaller but still page-aligned:Critical: The new size must be page-aligned to pass
sysmalloc checks.Trigger Heap Growth
Allocate a chunk larger than the corrupted Top Chunk size:This forces
sysmalloc to:- Request more memory from the OS (via
sbrkormmap) - Attempt to merge the old Top Chunk
- Fail to merge (due to size corruption)
- Call
_int_free()on the old Top Chunk
Key Constraints
Controlling the Freed Chunk Size
The size of the freed Top Chunk can be controlled precisely:Size Calculation Example
Size Calculation Example
To get a freed chunk in the 0x100-0x200 range:For smaller sizes, use the minimum:Then you can split the freed chunk with allocations.
Use in House of Orange
House of Orange uses this technique as its first step:House of Orange
Learn the complete House of Orange technique
Use in House of Tangerine
House of Tangerine (modern adaptation for glibc 2.26+):House of Tangerine
Learn the modern alternative using tcache
Why This Is Advanced
Sysmalloc Int Free is considered advanced because:- Precise Size Calculation: Must compute exact allocation sizes accounting for multiple alignment requirements
- Page Alignment Requirements: Corrupted sizes must satisfy strict constraints
- Understanding sysmalloc: Requires deep knowledge of heap expansion mechanism
- Limited Control: Can’t achieve arbitrary freed sizes due to alignment
- Foundation for Complex Techniques: Used as primitive in House of Orange/Tangerine
Practical Considerations
Detecting Top Chunk Location
You need to know where the Top Chunk is relative to your overflow:Avoiding Detection
Keep the size realistic:Debugging Tips
Use GDB to watch the process:Common Pitfalls
Related Techniques
- [House of Orange/techniques/house/house-of-orange) - Classic technique using this primitive
- [House of Tangerine/techniques/house/house-of-tangerine) - Modern tcache-based variant
- House of Force - Different Top Chunk exploitation
CTF Applications
Useful when:- You have overflow/OOB but no free primitive
- Need to get libc leak without existing free chunks
- Want to exploit FILE structures (House of Orange)
- Working with limited allocations
References
- glibc sysmalloc source (2.39)
- House of Orange - Hitcon 2016
- Tested on glibc 2.27, 2.31, 2.34, 2.39 across x86_64, x86, aarch64
