-
Notifications
You must be signed in to change notification settings - Fork 1.2k
TCache relative write #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Relative offset for &mp_.tcache_bins computation in all versions: 0x938
Relative offset for &mp_.tcache_bins computation in 2.35-2.37 versions: 0x918 Relative offset for &mp_.tcache_bins computation in 2.32-2.34 versions: 0x930 Relative offset for &mp_.tcache_bins computation in 2.31 version: 0x910
|
This is my understanding of this technique:
If my understanding is correct, then this is very similar to a technique that was quite popular ~2019. Back then, it was overwriting the fastbin's limit (also in I think we should include this. Also, I have a question/suggestions:
|
|
Thanks for the comment. So first of all, I think you've missed the most important objective of the attack. This technique is not just about writing a pointer out-of-bounds; it is also about the ability to write the counter out-of-bounds. I've demonstrated a chunk overlapping attack using this capability, in the how2heap PoCs and the blog post.
You should also note that About the similarity to the fastbins relative write (which is used in the popular technique House of Husk), you're absolutely right. This technique is similar to the fastbins attack because it overwrites bins limit to achieve out-of-bounds write. But here are the facts that I believe make this technique unique and different from the already mentioned:
I didn't find the For your questions/suggestions:
|
|
Sorry, I’m not sure whether you’re waiting for me to make changes. Based on my previous comment, please let me know if there’s anything you want me to update in the files. |
|
Hi, Sorry for the late response. I was (still am) quite busy recently and forgot about this issue.
I don't think it is feasible in practice. When the allocation size is large enough, the allocator will use mmap instead, unless we assume we can overwrite
you are right. I missed that part. |
In the objectives part it is said one is capable of triggering a semi-arbitrary write or fully arbitrary write, based on whether they can also set mp_.tcache_count to a large value.
|
Thanks for your time. I appreciate it. You're right about the limited range of "out-of-bounds counter-writing", and it should be in fact called a semi-arbitrary writing, unless we can also make To distinguish the "semi-arbitrary" and "fully arbitrary" cases, I changed the description for that primitive in the last commit. I hope it is more clear and precise now.
Assume we have several contiguous freed chunks that, when consolidated, form a single unsorted/largebin chunk whose size is higher than With some heap grooming, I believe this is totally possible to achieve in practice, thus I'd say the technique itself still gives us the arbitrary location capability, but to actually be a fully arbitrary location, it depends on the use case. |
I've come up with a tcache-based technique, and I did not find any House of ... or CTF that can achieve both of its objectives. Basically, it takes advantage of an out-of-bounds tcache metadata writing (both the pointer and counter) to achieve the following objectives:
tcache_perthread_struct, which is allocated on heap. The most powerful use case would be a chunk overlapping attack.tcache_perthread_struct. A powerful use case would be chunk edits (tcache poisoning, fastbin corruption, etc.)And with these prerequisites:
In the PoC, I demonstrated these two primitives to trigger a chunk overlapping, and a simple arbitrary pointer write.
I've thoroughly explained the technique in this blog post: https://d4r30.github.io/heap-exploit/2025/11/25/tcache-relative-write.html
Here's the summary:
This technique works on
2.30and higher versions. The latest version tested is2.41.There's also another blog post that mainly discusses
mp_hijack, but does not discuss the arbitrary counter-writing capability. It is more beginner-friendly though, as it provides a more complete discussion of tcache basics: https://4xura.com/binex/pwn-mp_-exploiting-malloc_par-to-gain-tcache-bin-control/One issue
As it is obvious in
tcache_relative_write.c, when the PoC wants to compute&mp_.tcache_bins, a constant is used to compute the distance between unsortedbin and thetcache_binsfield. This was the best possible option I had in my mind, because neithermp_normain_arenaare exported. The difference between&main_arenaand&mp_are also different among glibc versions. If you had any idea on how to remove the constant and make the PoC more portable, please let me know. I've manually calculated and tested all the relative constants for2.31-2.41, so I expect it will pass all the checks.