diff mbox series

[hurd,commited] htl: Clear kernel_thread field before releasing the thread structure

Message ID 20220115203155.514291-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series [hurd,commited] htl: Clear kernel_thread field before releasing the thread structure | expand

Commit Message

Samuel Thibault Jan. 15, 2022, 8:31 p.m. UTC
Otherwise this is a use-after-free.
---
 sysdeps/mach/htl/pt-thread-terminate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/sysdeps/mach/htl/pt-thread-terminate.c b/sysdeps/mach/htl/pt-thread-terminate.c
index 0cf72b330f..9bd6c3434d 100644
--- a/sysdeps/mach/htl/pt-thread-terminate.c
+++ b/sysdeps/mach/htl/pt-thread-terminate.c
@@ -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,