fastbin reverse into tcache¶
Poison'lanmış bir fastbin'i ters sırada tcache'e drain ederek size-check'siz bir arbitrary write elde et.
Mechanism¶
Bir fastbin'e birkaç chunk doldur, sonra bir heap overflow/UAF kullanarak bir
victim fastbin chunk'ının fd'sini (safe-link ile mangle edilmiş) bir target
adresiyle overwrite et. O size için tcache boş olduğunda ve malloc'u 7 kez
yaptığında, glibc tüm fastbin'i ters sırada tcache'e drain eder (_int_malloc'taki
stashing loop'u). Poison'lanmış chunk tcache'in önüne düşer, dolayısıyla hemen bir
sonraki allocation attacker-chosen adresi döndürür.
Note
fastbin-dup-into-stack karşısındaki belirleyici avantaj: tcache stash path'i
fastbin size check'lerini atlar, dolayısıyla target'ta forge edilmiş bir size
field gerekmez — herhangi bir writable adres işe yarar.
Walkthrough¶
// fill tcache (7 frees), then push N chunks into the fastbin.
// overwrite one victim's fd with the safe-link-mangled target:
*(size_t**)victim = (size_t*)((long)&stack_var[0] ^ ((long)victim >> 12));
// emptying the fastbin into tcache happens in reverse:
for (int i = 0; i < 7; i++) malloc(0x40); // drains fastbin -> tcache (reverse)
// poisoned entry now at tcache head
void *p = malloc(0x40); // returns &stack_var[0]
assert(p == (void*)&stack_var[0]);
Beklenen çıktı: son allocation target adrese eşittir ve assert geçer. tcache'e reverse-stash, fastbin size validation'ını bypass ettiği için target'ın bir fake chunk header'a ihtiyacı yoktur — sadece bir adres.
Mitigation¶
Safe-linking (2.32+), fd'yi mangle etmek için bir heap leak'i zorunlu kılar; tcache
key/count field'ları hafif consistency ekler. Bir leak elde tutulduğunda teknik,
etkilenen glibc'de güvenilir bir arbitrary-write primitive'i olarak kalır.