]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Clear kernel_thread field before releasing the thread structure
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 15 Jan 2022 20:30:17 +0000 (21:30 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 15 Jan 2022 20:31:08 +0000 (21:31 +0100)
Otherwise this is a use-after-free.

sysdeps/mach/htl/pt-thread-terminate.c

index 0cf72b330f3512b0c68ec3b0279c5b516398e0a8..9bd6c3434d083d13d6092f3c02d9a4a948963533 100644 (file)
@@ -62,15 +62,15 @@ __pthread_thread_terminate (struct __pthread *thread)
       ? __mig_get_reply_port () : MACH_PORT_NULL;
   __mach_port_deallocate (__mach_task_self (), self_ktid);
 
+  /* The kernel thread won't be there any more.  */
+  thread->kernel_thread = MACH_PORT_DEAD;
+
   /* Finally done with the thread structure.  */
   __pthread_dealloc (thread);
 
   /* The wake up port is now no longer needed.  */
   __mach_port_destroy (__mach_task_self (), wakeup_port);
 
-  /* The kernel thread won't be there any more.  */
-  thread->kernel_thread = MACH_PORT_DEAD;
-
   /* Terminate and release all that's left.  */
   err = __thread_terminate_release (kernel_thread, mach_task_self (),
                                    kernel_thread, reply_port,