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 E107C3856DCB for ; Mon, 17 Apr 2023 19:00:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E107C3856DCB 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 1poU5a-0003R3-6p; Mon, 17 Apr 2023 15:00:34 -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=oTg7rLdUovow7LpipqaG0qF1m2kRhMIkug3WtwOn/ac=; b=nI9pKhSwQKdEHU14RFPF C7JZn7WnUZ/oyV6npsdqzXmDE3F0piMTSyYQiF7mqtRIP2gRYrdO8SM6UU9M5Us9T54cmC6AxFEF3 wVtRppS0HgLGE0+5zPXemdUmqYms73UxLClZuqu/eYPKD8Efjn08JFJlOQs7LTllIXovaeNy6KNdn lbsxa6SQ+Y5IsvV8bEmFp9piqiv35grDl+OYtAwjtimnRd2MRX5RqIRaRmht32gea1fhYqgLl/0Uh myfNMF7/nJH91iDuZsZRzd35pWkZ0JFUmsZUwqYWShaGEtHZvFqvY/fWdg65QUWVIwZrKjxKdpy6D S08OEqnlXnlkzQ==; Received: from 2a01cb008c251f00de41a9fffe47ec49.ipv6.abo.wanadoo.fr ([2a01:cb00:8c25:1f00:de41:a9ff:fe47:ec49] helo=begin.home) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1poU5T-0004mj-9J; Mon, 17 Apr 2023 15:00:32 -0400 Received: from samy by begin.home with local (Exim 4.96) (envelope-from ) id 1poU5Q-005fIT-25; Mon, 17 Apr 2023 21:00:24 +0200 Date: Mon, 17 Apr 2023 21:00:24 +0200 From: Samuel Thibault To: Sergey Bugaev Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: Re: [PATCH 1/5] hurd: Fix restoring reply port in sigreturn Message-ID: <20230417190024.4otllbmss3iaqtf7@begin> Mail-Followup-To: Sergey Bugaev , libc-alpha@sourceware.org, bug-hurd@gnu.org References: <20230414193700.542116-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230414193700.542116-1-bugaevc@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 ven. 14 avril 2023 22:36:56 +0300, a ecrit: > We must not use the user's reply port (scp->sc_reply_port) for any of > our own RPCs, otherwise various things break. So, use MACH_PORT_DEAD as > a reply port when destroying our reply port, and make sure to do this > after _hurd_sigstate_unlock (), which may do a gsync_wake () RPC. > > Signed-off-by: Sergey Bugaev > --- > sysdeps/mach/hurd/i386/sigreturn.c | 35 ++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 12 deletions(-) > > diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c > index 4f196710..a0fc8891 100644 > --- a/sysdeps/mach/hurd/i386/sigreturn.c > +++ b/sysdeps/mach/hurd/i386/sigreturn.c > @@ -26,11 +26,29 @@ register int *sp asm ("%esp"); > /* This is run on the thread stack after restoring it, to be able to > unlock SS off sigstack. */ > static void > -__sigreturn2 (int *usp) > +__sigreturn2 (int *usp, struct sigcontext *scp) > { > + mach_port_t reply_port; > struct hurd_sigstate *ss = _hurd_self_sigstate (); > _hurd_sigstate_unlock (ss); > > + /* Destroy the MiG reply port used by the signal handler, and restore the > + reply port in use by the thread when interrupted. > + > + We cannot use the original reply port for our RPCs that we do here, since > + we could unexpectedly receive/consume a reply message meant for the user > + (in particular, msg_sig_post_reply), and also since we would deallocate > + the port if *our* RPC fails, which we don't want to do since the user > + still has the old name. And so, temporarily set MACH_PORT_DEAD as our > + reply name, and make sure destroying the port is the very last RPC we > + do. */ > + reply_port = THREAD_GETMEM (THREAD_SELF, reply_port); > + THREAD_SETMEM (THREAD_SELF, reply_port, MACH_PORT_DEAD); > + if (MACH_PORT_VALID (reply_port)) > + (void) __mach_port_mod_refs (__mach_task_self (), reply_port, > + MACH_PORT_RIGHT_RECEIVE, -1); > + THREAD_SETMEM (THREAD_SELF, reply_port, scp->sc_reply_port); > + > sp = usp; > #define A(line) asm volatile (#line) > /* The members in the sigcontext are arranged in this order > @@ -58,7 +76,6 @@ __sigreturn (struct sigcontext *scp) > { > struct hurd_sigstate *ss; > struct hurd_userlink *link = (void *) &scp[1]; > - mach_port_t reply_port; > > if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)) > { > @@ -98,13 +115,6 @@ __sigreturn (struct sigcontext *scp) > if (scp->sc_onstack) > ss->sigaltstack.ss_flags &= ~SS_ONSTACK; > > - /* Destroy the MiG reply port used by the signal handler, and restore the > - reply port in use by the thread when interrupted. */ > - reply_port = THREAD_GETMEM (THREAD_SELF, reply_port); > - THREAD_SETMEM (THREAD_SELF, reply_port, scp->sc_reply_port); > - if (MACH_PORT_VALID (reply_port)) > - __mach_port_destroy (__mach_task_self (), reply_port); > - > if (scp->sc_fpused) > /* Restore the FPU state. Mach conveniently stores the state > in the format the i387 `frstor' instruction uses to restore it. */ > @@ -115,15 +125,16 @@ __sigreturn (struct sigcontext *scp) > copy the registers onto the user's stack, switch there, pop and > return. */ > > - int *usp = (int *) scp->sc_uesp; > + int usp_arg, *usp = (int *) scp->sc_uesp; > > *--usp = scp->sc_eip; > *--usp = scp->sc_efl; > memcpy (usp -= 12, &scp->sc_i386_thread_state, 12 * sizeof (int)); > + usp_arg = (int) usp; > > + *--usp = (int) scp; > /* Pass usp to __sigreturn2 so it can unwind itself easily. */ > - *(usp-1) = (int) usp; > - --usp; > + *--usp = usp_arg; > /* Bogus return address for __sigreturn2 */ > *--usp = 0; > *--usp = (int) __sigreturn2; > -- > 2.39.2 > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.