Skip to main content

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 make sysmalloc 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

When malloc 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:
This behavior is exploited in House of Orange and House of Tangerine.

Full Source Code

Step-by-Step Walkthrough

1

Probe the Top Chunk Size

First, determine the current Top Chunk size to calculate our target size:
2

Calculate Required Allocation

Compute the exact size to allocate such that corrupting the Top Chunk will leave a specific freed size:
3

Allocate and Locate Top Chunk

Allocate the computed size and find the Top Chunk metadata:
4

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

Trigger Heap Growth

Allocate a chunk larger than the corrupted Top Chunk size:
This forces sysmalloc to:
  1. Request more memory from the OS (via sbrk or mmap)
  2. Attempt to merge the old Top Chunk
  3. Fail to merge (due to size corruption)
  4. Call _int_free() on the old Top Chunk
6

Reallocate from Freed Top

The old Top Chunk is now in a bin and can be reallocated:

Key Constraints

Critical Requirements:
  1. Page Alignment: Corrupted Top Chunk size must be page-aligned (typically 0x1000)
  2. Size Calculation: Freed size is computed as:
    where FENCEPOST = 2 * CHUNK_HDR_SZ = 0x20
  3. Malloc Alignment: Final freed size must be malloc-aligned (0x10)

Controlling the Freed Chunk Size

The size of the freed Top Chunk can be controlled precisely:
Important: You can’t achieve arbitrary freed sizes - they’re constrained by page alignment.
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:
1

Free the Top Chunk

Use sysmalloc int free to get the Top Chunk into unsorted bin.
2

Leak Libc

The unsorted bin contains libc pointers - leak them.
3

Corrupt _IO_list_all

Use unsorted bin attack to corrupt _IO_list_all.
4

Trigger with malloc

Call malloc to trigger FILE stream exploitation.

House of Orange

Learn the complete House of Orange technique

Use in House of Tangerine

House of Tangerine (modern adaptation for glibc 2.26+):
1

Free the Top Chunk

Use sysmalloc int free to create a freed chunk.
2

Tcache Poisoning

Use the freed chunk to poison tcache freelists.
3

Arbitrary Allocation

Get malloc to return arbitrary addresses.

House of Tangerine

Learn the modern alternative using tcache

Why This Is Advanced

Sysmalloc Int Free is considered advanced because:
  1. Precise Size Calculation: Must compute exact allocation sizes accounting for multiple alignment requirements
  2. Page Alignment Requirements: Corrupted sizes must satisfy strict constraints
  3. Understanding sysmalloc: Requires deep knowledge of heap expansion mechanism
  4. Limited Control: Can’t achieve arbitrary freed sizes due to alignment
  5. 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

Avoid These Mistakes:
  1. Not page-aligning: sysmalloc will abort if size isn’t page-aligned
  2. Size too small: Must be at least FENCEPOST + MALLOC_ALIGN
  3. Wrong offset calculation: Off-by-one errors are common
  4. Forgetting PREV_INUSE: The size field should have the PREV_INUSE bit set
  • [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