From patchwork Wed May 26 06:05:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 43583 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10EB43857C67; Wed, 26 May 2021 06:05:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10EB43857C67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622009135; bh=HDwTlIjWPRleHAWn6Cm1+UYFnBvFueCcCu3BHwMnVyw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QCvhz3NqWF4Cfnlx7UX0/iWMQkqJL0qwfL/KEqtfI6Vt1f02JJ8hKpGC6KNzKHIn+ NwiwTiG8fKXfzqEF49GXRVGWMOdInLWmaYv0sirCYMGGcUqyGvI0p51+skhfOF9SgP CguB1vMSKvxMEPFUYq9rGSwdlWvoRxQ3zcAgKMSQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id ED7353857C62 for ; Wed, 26 May 2021 06:05:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ED7353857C62 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-77-OXHat4KbO9Kpy29EgfvE2g-1; Wed, 26 May 2021 02:05:27 -0400 X-MC-Unique: OXHat4KbO9Kpy29EgfvE2g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3585B107ACCA for ; Wed, 26 May 2021 06:05:26 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-113-228.ams2.redhat.com [10.36.113.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E36D10190A7 for ; Wed, 26 May 2021 06:05:25 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Install SIGSETXID handler with SA_ONSTACK [BZ #27914] Date: Wed, 26 May 2021 08:05:23 +0200 Message-ID: <87fsyat4gs.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The signal is sent to all threads, some of which may have switched to very small stacks. If they have also installed an alternate signal stack, SA_ONSTACK makes this work. The Go runtime needs this: runtime: C.setuid/C.setgid smashes Go stack Doing this for SIGCANCEL is less obviously beneficial and needs further testing. Tested on i686-linux-gnu and x86_64-linux-gnu. I verified that a glibc build for a distribution unbreaks the Go test suite on x86-64. Reviewed-by: Carlos O'Donell --- nptl/pthread_create.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 5680687efe..b7073a8285 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -83,9 +83,12 @@ late_init (void) (void) __libc_sigaction (SIGCANCEL, &sa, NULL); } - /* Install the handle to change the threads' uid/gid. */ + /* Install the handle to change the threads' uid/gid. Use + SA_ONSTACK because the signal may be sent to threads that are + running with custom stacks. (This is less likely for + SIGCANCEL.) */ sa.sa_sigaction = __nptl_setxid_sighandler; - sa.sa_flags = SA_SIGINFO | SA_RESTART; + sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTART; (void) __libc_sigaction (SIGSETXID, &sa, NULL); /* The parent process might have left the signals blocked. Just in