Overview
Safe-Link Double Protect is a blind bypass technique for the safe-linking mitigation that requires no heap leaks. By protecting a pointer twice with the same key, the XOR operations cancel out, effectively reverting to the original unprotected pointer.Glibc Compatibility: Works on glibc 2.32+ where safe-linking was introduced.
What It Achieves
This technique allows you to:- Bypass safe-linking without heap leaks: No need to know actual addresses
- Link arbitrary pointers into tcache: Achieve arbitrary allocation primitive
- Exploit with limited primitives: Only needs tcache metadata control
- Require only 4-bit bruteforce: If using write primitive (no bruteforce with increment)
The Core Concept
Safe-linking protects pointers using:Full Source Code
Step-by-Step Walkthrough
1
Set Up Multiple Tcache Bins
Allocate chunks in different size classes to have control over multiple tcache bins:
2
Write Target Address
Store your target address (aligned) in a heap chunk:
3
Populate Tcache Bins
Free the chunks to create tcache freelists:Now both freelists have safe-linked pointers.
4
Corrupt Tcache Metadata (First Protection)
Modify the 0x40 tcache entry to point to our value chunk:Now the 0x40 tcache contains our target address (protected once by safe-linking).
5
Allocate to Get Protected Pointer
Take one chunk from 0x40 tcache to make our target the head:
6
Apply Second Protection (Double Protect)
Point the 0x20 tcache bin to the 0x40 tcache bin entry:When we free into 0x20, safe-linking will protect our already-protected pointer again, canceling out the protection!
7
Trigger Arbitrary Allocation
Allocate from the 0x20 tcache twice:The second allocation returns our arbitrary target address.
Why This Works
The technique exploits how safe-linking is applied:-
First Protection (when freeing chunk A):
-
Second Protection (when reading from tcache):
-
Cancellation:
Visual Representation
Visual Representation
Bruteforce Considerations
Prerequisites
This technique requires:- Tcache Metadata Control: Ability to overwrite
tcache_perthread_struct - Multiple Tcache Bins: Need at least two different size classes
- Heap Chunk with Target Address: A place to store your target pointer
- Allocation Primitive: Ability to call malloc to trigger the exploit
Combining with Other Techniques
House of Water
House of Water provides the tcache metadata control needed:House of Water
Learn how to gain leakless control of tcache metadata
Tcache Relative Write
Can be used to corrupt tcache metadata:Tcache Relative Write
Achieve out-of-bounds tcache metadata writes
Why This Is Advanced
Safe-Link Double Protect is considered advanced because:- Requires deep understanding of safe-linking: Must understand XOR properties at bit level
- Needs precise tcache metadata control: Difficult to achieve in most programs
- Complex multi-step setup: Requires orchestrating multiple tcache bins
- Blind technique: Works without leaks, but needs precise execution
- Fragile exploitation: Small mistakes can crash the program
Advantages Over Other Bypasses
Common Pitfalls
Real-World Applications
This technique has been used in:- 37c3 Potluck CTF - Tamagoyaki: Original demonstration of the technique
- Modern CTF challenges on glibc 2.32+ without heap leaks
- Exploits where information disclosure is heavily restricted
Implementation Tips
Debugging the Exploit
Use GDB to verify each step:Related Techniques
- Safe-Linking Overview - Understanding the mitigation
- Decrypt Safe-Linking - Alternative bypass
- [House of Water/techniques/house/house-of-water) - Tcache metadata control
- [Tcache Poisoning/techniques/tcache/tcache-poisoning) - Classic technique this bypasses
References
- 37c3 Potluck - Tamagoyaki Challenge
- Technique by @udp_ctf (Water Paddler / Blue Water)
- Safe-Linking Commit
