From patchwork Thu Sep 26 11:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 97994 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 541943858D28 for ; Thu, 26 Sep 2024 11:16:55 +0000 (GMT) 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C43543858D28 for ; Thu, 26 Sep 2024 11:16:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C43543858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C43543858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727349390; cv=none; b=N+0CzChUUlfP8keY3joKlrenDMxiegEm4RuPgEcOSVegdX2T9/Z+ycaCN27kcRgQEc0gmqgDj/mUHWpZddwtRgMZL3uWNKcVg33d+CT7DTNMjlfkfnFjNLM20no74qvAbhC57yvi4uBrme8xK+AlfyL3svhL8eQSoBx/mRD23tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727349390; c=relaxed/simple; bh=sg5fwuYbg8VDlbEE0Doi9FP70LpN5AqRFDGqqPLaxLk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t0r+y8xauq1b7MFyESjeg9eU63f63KmCePhGagqr8zAtGJeRbKf/9BQjJf0eYYpedB3c6mBA/tg5qmm2vSOyFxjxOOxaTolI0OXKl0ywMZdXbuyp99iMwiihyafHOsrRneT9bwGRejEqjPX3RMeqS4dQX9PXycY7utQmdNohJDs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727349388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=qeWftKZIm3YDJL9b0hUf1pPWxpqBbQm3fL49XyOhsDc=; b=WZbglwshn3pTqnN/WqcmDsXGNV9EOUAGC3V49/ShJr+++I68aFqRHwmI4L8GJckkOeTer+ jyPK5FL+3yhWykl6t4IfwDS+Dokv4++prfQ6yQyun3AqwHkPk2xV36h+yWW9Gb6w6wthGI uYOXlInjEhnos8ZCk1o26iDmlmC5OcA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-h262mVqkM5OgOgh3qU4kHQ-1; Thu, 26 Sep 2024 07:16:27 -0400 X-MC-Unique: h262mVqkM5OgOgh3qU4kHQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36A681943CFD for ; Thu, 26 Sep 2024 11:16:26 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.151]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5D3091956086 for ; Thu, 26 Sep 2024 11:16:25 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] Linux: Block signals around _Fork (bug 32215) Date: Thu, 26 Sep 2024 13:16:22 +0200 Message-ID: <87ldze7ji1.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This hides the inconsistent TCB state (missing robust mutx list) from signal handlers. Tested on i686-linux-gnu and x86_64-linux-gnu. --- sysdeps/nptl/_Fork.c | 7 +++++++ 1 file changed, 7 insertions(+) base-commit: cc84cd389c7329ceb38228f931044e8c84ca7245 diff --git a/sysdeps/nptl/_Fork.c b/sysdeps/nptl/_Fork.c index ef199ddbc3..fd2cfc7840 100644 --- a/sysdeps/nptl/_Fork.c +++ b/sysdeps/nptl/_Fork.c @@ -22,6 +22,11 @@ pid_t _Fork (void) { + /* Block all signals to avoid revealing the inconsistent TCB state + to a signal handler after fork. */ + internal_sigset_t original_sigmask; + internal_signal_block_all (&original_sigmask); + pid_t pid = arch_fork (&THREAD_SELF->tid); if (pid == 0) { @@ -44,6 +49,8 @@ _Fork (void) INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, sizeof (struct robust_list_head)); } + + internal_signal_restore_set (&original_sigmask); return pid; } libc_hidden_def (_Fork)