From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id B9FCE3858D38 for ; Mon, 10 Apr 2023 22:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9FCE3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1plzwb-0006cV-Ju; Mon, 10 Apr 2023 18:25:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=YteRmZ3ZB8yv0ac6UeUvjtIyzGoA76EBmIEUPpzfCeo=; b=RzgDZW0GMVD3NWI+pjvd GjjOTGp+wQ9QD0k81YGlp0+YpF+rtI8OcWcQdwVwAXsjw1iCREc9KPgoaqsXhFd9OTGU4cxHSVkGh HDx6lSF5u8uB08caC0MVllHZ7Hfut1Y086C1TL9AyAlLgHtO3CGF/mwaVMK/kbO7cGgT2RQtJd4gC 2R+XTkAMJEvBJrOO2qpqd/3h7l9tcLXLf6R4gS0TE3jPoTEfdzi0uUS08Blal8XHp6GSqBCD1fqdr NvNh4vLe5R1gsChg+2hKFEtg5fjhFvgn9btYt0AyH7Fcdw6EuF625X4uNHLZzBstGnCOrQKROJlU7 qqZIDztMXILkuQ==; Received: from [2a01:cb19:4a:a400:de41:a9ff:fe47:ec49] (helo=begin) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1plzwb-0008Vd-8T; Mon, 10 Apr 2023 18:25:01 -0400 Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1plzwa-000vUE-0p; Tue, 11 Apr 2023 00:25:00 +0200 Date: Tue, 11 Apr 2023 00:25:00 +0200 From: Samuel Thibault To: Sergey Bugaev Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: Re: [RFC PATCH glibc 27/34] hurd: Don't leak __hurd_reply_port0 Message-ID: <20230410222500.zj65pvj2zmn222ko@begin> Mail-Followup-To: Sergey Bugaev , libc-alpha@sourceware.org, bug-hurd@gnu.org References: <20230319151017.531737-1-bugaevc@gmail.com> <20230319151017.531737-28-bugaevc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230319151017.531737-28-bugaevc@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Applied, thanks! Sergey Bugaev, le dim. 19 mars 2023 18:10:10 +0300, a ecrit: > Previously, once we set up TLS, we would implicitly switch from using > __hurd_reply_port0 to reply_port inside the TCB, leaving the former > unused. But we never deallocated it, so it got leaked. > > Instead, migrate the port into the new TCB's reply_port slot. This > avoids both the port leak and an extra syscall to create a new reply > port for the TCB. > > Signed-off-by: Sergey Bugaev > --- > sysdeps/mach/hurd/i386/tls.h | 5 +++++ > sysdeps/mach/hurd/x86_64/tls.h | 9 ++++++++- > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h > index ee7b8004..0ac8917a 100644 > --- a/sysdeps/mach/hurd/i386/tls.h > +++ b/sysdeps/mach/hurd/i386/tls.h > @@ -141,12 +141,15 @@ _hurd_tls_init (tcbhead_t *tcb) > HURD_TLS_DESC_DECL (desc, tcb); > thread_t self = __mach_thread_self (); > bool success = true; > + extern mach_port_t __hurd_reply_port0; > > /* This field is used by TLS accesses to get our "thread pointer" > from the TLS point of view. */ > tcb->tcb = tcb; > /* We always at least start the sigthread anyway. */ > tcb->multiple_threads = 1; > + /* Take over the reply port we've been using. */ > + tcb->reply_port = __hurd_reply_port0; > > /* Get the first available selector. */ > int sel = -1; > @@ -172,6 +175,8 @@ _hurd_tls_init (tcbhead_t *tcb) > > /* Now install the new selector. */ > asm volatile ("mov %w0, %%gs" :: "q" (sel)); > + /* This port is now owned by the TCB. */ > + __hurd_reply_port0 = MACH_PORT_NULL; > > out: > __mach_port_deallocate (__mach_task_self (), self); > diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h > index da504d9c..2b7135f6 100644 > --- a/sysdeps/mach/hurd/x86_64/tls.h > +++ b/sysdeps/mach/hurd/x86_64/tls.h > @@ -177,13 +177,20 @@ _hurd_tls_init (tcbhead_t *tcb) > { > error_t err; > thread_t self = __mach_thread_self (); > + extern mach_port_t __hurd_reply_port0; > > /* We always at least start the sigthread anyway. */ > tcb->multiple_threads = 1; > + /* Take over the reply port we've been using. */ > + tcb->reply_port = __hurd_reply_port0; > > err = _hurd_tls_new (self, tcb); > if (err == 0) > - __libc_tls_initialized = 1; > + { > + __libc_tls_initialized = 1; > + /* This port is now owned by the TCB. */ > + __hurd_reply_port0 = MACH_PORT_NULL; > + } > __mach_port_deallocate (__mach_task_self (), self); > return err == 0; > } > -- > 2.39.2 > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.