From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1138 invoked by alias); 18 Mar 2018 19:45:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 863 invoked by uid 89); 18 Mar 2018 19:45:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=H*r:sk:static-, Hx-spam-relays-external:sk:static-, H*RU:sk:static-, our X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [hurd,commited 5/5] Hurd: fix port leak in TLS Date: Sun, 18 Mar 2018 19:45:00 -0000 Message-Id: <20180318194451.11862-6-samuel.thibault@ens-lyon.org> In-Reply-To: <20180318194451.11862-1-samuel.thibault@ens-lyon.org> References: <20180318194451.11862-1-samuel.thibault@ens-lyon.org> X-SW-Source: 2018-03/txt/msg00437.txt.bz2 From: Richard Braun * sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary thread reference. --- ChangeLog | 5 +++++ sysdeps/mach/hurd/i386/tls.h | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a34efca45..ddf8c9c9d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-03-18 Richard Braun + + * sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary + thread reference. + 2018-03-18 Agustina Arzille * sysdeps/mach/libc-lock.h (__libc_cleanup_frame): Define structure. diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index c443552df4..771c94ff95 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -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 -- 2.16.2