]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Hurd: fix port leak in TLS
authorRichard Braun <rbraun@sceen.net>
Sun, 18 Mar 2018 19:27:16 +0000 (20:27 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 18 Mar 2018 19:43:59 +0000 (20:43 +0100)
* sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary
thread reference.

ChangeLog
sysdeps/mach/hurd/i386/tls.h

index 1a34efca454c248b0c074ada197375eed6663555..ddf8c9c9d11272ee81ce8bb8b1ac23e8702a23a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-03-18  Richard Braun  <rbraun@sceen.net>
+
+       * sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary
+       thread reference.
+
 2018-03-18  Agustina Arzille  <avarzille@riseup.net>
 
        * sysdeps/mach/libc-lock.h (__libc_cleanup_frame): Define structure.
index c443552df4a0059dc70d4965bba705b82445dd3b..771c94ff95e34cb19803b690c7323a47a6294c82 100644 (file)
@@ -111,36 +111,41 @@ static inline const char * __attribute__ ((unused))
 _hurd_tls_init (tcbhead_t *tcb)
 {
   HURD_TLS_DESC_DECL (desc, tcb);
+  thread_t self = __mach_thread_self ();
+  const char *msg = NULL;
 
   /* This field is used by TLS accesses to get our "thread pointer"
      from the TLS point of view.  */
   tcb->tcb = tcb;
 
-  /* Cache our thread port.  */
-  tcb->self = __mach_thread_self ();
-
   /* Get the first available selector.  */
   int sel = -1;
-  error_t err = __i386_set_gdt (tcb->self, &sel, desc);
+  error_t err = __i386_set_gdt (self, &sel, desc);
   if (err == MIG_BAD_ID)
     {
       /* Old kernel, use a per-thread LDT.  */
       sel = 0x27;
-      err = __i386_set_ldt (tcb->self, sel, &desc, 1);
+      err = __i386_set_ldt (self, sel, &desc, 1);
       assert_perror (err);
       if (err)
-       return "i386_set_ldt failed";
+      {
+       msg = "i386_set_ldt failed";
+       goto out;
+      }
     }
   else if (err)
     {
       assert_perror (err); /* Separate from above with different line #. */
-      return "i386_set_gdt failed";
+      msg = "i386_set_gdt failed";
+      goto out;
     }
 
   /* Now install the new selector.  */
   asm volatile ("mov %w0, %%gs" :: "q" (sel));
 
-  return 0;
+out:
+  __mach_port_deallocate (__mach_task_self (), self);
+  return msg;
 }
 
 /* Code to initially initialize the thread pointer.  This might need