public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] hurd: Don't leak __hurd_reply_port0 Date: Mon, 10 Apr 2023 22:24:58 +0000 (GMT) [thread overview] Message-ID: <20230410222458.850653858D38@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=cd019ddd892e182277fadd6aedccc57fa3923c8d commit cd019ddd892e182277fadd6aedccc57fa3923c8d Author: Sergey Bugaev <bugaevc@gmail.com> Date: Sun Mar 19 18:10:10 2023 +0300 hurd: Don't leak __hurd_reply_port0 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 <bugaevc@gmail.com> Message-Id: <20230319151017.531737-28-bugaevc@gmail.com> Diff: --- 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 ee7b8004bc..0ac8917a95 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 da504d9c81..2b7135f635 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; }
reply other threads:[~2023-04-10 22:24 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230410222458.850653858D38@sourceware.org \ --to=sthibaul@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).