fastbin dup consolidate¶
malloc_consolidate'i tetikleyerek fastbin head'ini temizle ve double-free check'ini bypass et.
Mechanism¶
fasttop head check'inden kaçınmak için ikinci bir chunk free etmek yerine, büyük
(>= 0x400) bir chunk talep ederek malloc_consolidate'i tetikliyorsun.
malloc_consolidate, fastbin'leri unsorted bin'e flush eder / top ile merge eder ki
bu da fastbin head'ini temizler. Fastbin'e halihazırda free ettiğin chunk
dolayısıyla artık head değildir, bu yüzden onu ikinci kez free etmek check'i geçer —
ve iki kez allocate edilebilir hale gelir.
Note
Bu, head'i takas etmek için ikinci bir aynı boyutlu chunk yerine yalnızca bir
free edilebilir chunk artı bir büyük allocation gerektiren bir fastbin-dup
varyantıdır.
Note
glibc >= 2.26'da, free(p1)'in fastbin'e (tcache yerine) düşmesi için önce o
size class için 7-entry'lik tcache'i doldurmalısın; aksi halde p1 tcache'e
gider ve malloc_consolidate onu drain edemez. how2heap 2.35 PoC'si bu
sequence'ten önce tcache'i ısıtır (bkz. fastbin-dup).
Walkthrough¶
void *p1 = malloc(0x40);
free(p1); // p1 -> fastbin (head)
void *p2 = malloc(0x400); // large request triggers malloc_consolidate,
// draining the fastbin so p1 is no longer "head"
free(p1); // ACCEPTED: fasttop double-free check bypassed
void *p3 = malloc(0x40); // p3 == p1
Beklenen çıktı: p3 (ve sonraki bir aynı boyutlu malloc) p1'i alias'lar — aynı
adres iki kez verilir ve consolidate path'inin fasttop check'ini bypass ettiğini
kanıtlar.
Mitigation¶
fastbin-dup ile aynı yüzey: bypass edilen şey fasttop head check'idir. glibc
tcache key (2.29+) ve safe-linking (2.32+) takip eden exploitation'ı kısıtlar ama
consolidate hilesinin kendisini kısıtlamaz.