From patchwork Tue Jul 23 13:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 813952 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2322632wro; Tue, 23 Jul 2024 06:42:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXW2mDA7y/fohEpNvYloAC6cYG++iBd73lU8cGgHiX8SN+ZWcjwiRYBa/Criq39KeoLij/e/xChQCN9DJGBfEqK X-Google-Smtp-Source: AGHT+IE0lNrAu2g9ridaJbb8MwPhxtykRhNVOoqk0MgBMwuM3jW/AA9TP4WiZZ1lyIR5Ko6z84gt X-Received: by 2002:a05:622a:44c:b0:447:e532:b36b with SMTP id d75a77b69052e-44fc7fa8a8bmr35994251cf.21.1721742176920; Tue, 23 Jul 2024 06:42:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1721742176; cv=pass; d=google.com; s=arc-20160816; b=HGm0seOy5nWH7FI29sUAZZ3HIdroJl5baCy+VO4AdVOakvxMoI1ybFvLyxSGpBU+Yp BuKov305pFaX932IKW2Wmcdw/Ir4TaD9VAMdmYVumCblXs5wgcI66+kVqFwkM8nnReVo BZQHZ+c4XDUDV8GoUiGVnB/eOBj2nCn1ZBuTGjLDOgkDI310XBk2V6sLfB/UD8Y2Bmlx EwWVKWt6TdRC0y0NMq/yrsprQnurNjviXyNETdH6wuns+p717TBece1ujjqBJ9y2WGG1 oppDeuzI715EbTZ6RlT7dXfj1V4gcE5dD5uUkai27P4tu1ukCPz7S3zVwDczTnsme8OK rOgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=ytNO9jfF8YKOUnAdOGwrT3mHNJ0sPueas9IsGMvCOog=; fh=FrIIm/QnOE7OXYy+gkIIpqXil55ZUjyK4D4YjoZapbQ=; b=oBrNbdvPfpSLpTXNee8eXfqhUXKJfvXaENNRUa/yiVn/H16PzG1tKBhSjvNGYgM/iX zDEOa0IdePZNuop6kOh4LzkGO0rDeBCpVk0Zk5uZ49PAdVdGeDxHlY1YkSrksTpBvdPy GI2xWpd2w1RQ6VxbkAZosPxmgC9czw1r2azRHx+3g7vP+sAcI3k5ikfOBytGNE1YxjhS s4IjRXA/eo2ehFcXvuSOQh5sCT9l3ZEDA01U4r7ieGnUffe+LU6xNi/W3vVfWSZxzxXI JThwRaK7qik8KW8tM9mtXhYLw2s6ad35ifgeGj6F52oJcv9wbvs5pFvYT+62LXplVcLd 5J4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g5aSrtVD; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d75a77b69052e-44f9ccfd2a1si101152301cf.97.2024.07.23.06.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 06:42:56 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g5aSrtVD; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85ABA3861029 for ; Tue, 23 Jul 2024 13:42:56 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 0F5673858430 for ; Tue, 23 Jul 2024 13:42:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F5673858430 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0F5673858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721742166; cv=none; b=CzKGwj7RQKTGPwuccvAKuI5111q0LVSBQp8DAjOWVwg2/DtCSANDmpSK+7M9pNduOGtHmzwd9FglwxkfOEu/Du2u9VUrD1n9JhwBuj4S2nXrP/fcKZev3wIN/o99uLWI3xbxDlqWq/ppT+MNhRKhyOvd8vFL2ypEtk40BiXZL88= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721742166; c=relaxed/simple; bh=wBsqYH9j7Z2iDBntj3fLVORFEjlHPONB0qFSWAbvf90=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NIL8ko4wPyQEK5VpgcJTJ+hvu7iv3+6GunYFG8WAubAUFL5WHZMOyhtCK18HmCHeYOHEihNbeAR9lsZMPm3I7N1FBRFzH645Ew0tMjDEv7twS5E9aGkmyGZxHxZXZp4DqZ8dwnaBW0YwfEBTVbHv/nNzOg8ztk6JxTmJxJhyyEM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d316f0060so1072088b3a.1 for ; Tue, 23 Jul 2024 06:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721742162; x=1722346962; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ytNO9jfF8YKOUnAdOGwrT3mHNJ0sPueas9IsGMvCOog=; b=g5aSrtVDGVD4TVq9KtV+JNOiZizD/MAy9bO2kYP+gMx92FmfEIozsKvp8V6XjNVGB8 rqaZVg0pTDZtLjq4SE4V7VwkbSN2kIVtAAfxWbpuvG90uKkCd5whEGrCyBF7TeMyN6Yj 5+0njtNCa8mgwoHu3Xdi1GmeBVYUYfz9E1PfL6TSVo12qlHq2MrdAYIab6/U4tevDbT+ TM4FVDG/50EdquifpwhiSmzAmlzzvsDVJ8FiBr1uxbDUDj8htSXK7ExEULOEk1PN1TxE i0Np79xF5qaAogamZnkjkPeOmbpPQF0zH08pBUB+5rdfWZT7s+yJ8pgziW3SnqVJ3Wxn 8BYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721742162; x=1722346962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytNO9jfF8YKOUnAdOGwrT3mHNJ0sPueas9IsGMvCOog=; b=qMNAmXCdHRqzOCIPq4k3XFGBNi3JqD0ysX1OrM1i0baE6oVNwplq6X6IzvlLbrEu91 zMzI5Sh5VKGMnO3SfKa8oOeTpyFSuh0S4/VhUK+sRny/IicJpobjshephZLCW8VLeJ2S T/tEpqk04iEgz0zmILHu9A38Rae4X7TpETFhlY6WMNTaiyGetrKISKhHt7K2uKYOp+qL TvEsWnn7DFZ1UJxUBvkLuqnGbPcYhX4RJEkE01FFTb5Ryyb6mRRLFc405V/qyj6Ms3yU L9hEeOV8m6LAsbehjYysiaSlBe0V5mxHGSpTooKc8lKSzts3gbbMz5NxwEF7m0s67Y3v JNXg== X-Gm-Message-State: AOJu0YxpIQabXsbATPq5KguaZXL0V4gyqYCP1GO+vQ5KhUlR0XOg8ILx jc4V2E0OxGqfCjJaG+6QcbLr4hlA6eTbbtqc3fz+sXtTh4M3uzvLMZSVP9Rh4mzyiTMpY9xNUC+ I X-Received: by 2002:a05:6a00:1a8c:b0:70d:2fef:2ca0 with SMTP id d2e1a72fcca58-70e8074fda4mr3392610b3a.2.1721742162449; Tue, 23 Jul 2024 06:42:42 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:842a:1aa9:89f1:3b40:9ac]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-79f0af5e635sm6321269a12.22.2024.07.23.06.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 06:42:41 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Carlos O'Donell , Florian Weimer Subject: [PATCH v2 1/2] setjmp: Use BSD sematic as default for setjmp Date: Tue, 23 Jul 2024 10:41:48 -0300 Message-ID: <20240723134235.1520483-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240723134235.1520483-1-adhemerval.zanella@linaro.org> References: <20240723134235.1520483-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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~patch=linaro.org@sourceware.org POSIX relaxed the relation of setjmp/longjmp and the signal mask save/restore, meaning that setjmp does not require to be routed to _setjmp to be standard compliant. This is done to avoid breakage of SIGABRT handlers, since to fully make abort AS-safe, it is required to remove the recurisve lock used to unblock SIGABRT prior raised the signal. Also, it allows caller to actually use setjmp, since from 7011c2622fe3e10a29dbe74f06aaebd07710127d the symbol is unconditionally routed to _setjmp. Checked on x86_64-linux-gnu. --- NEWS | 4 +++- manual/setjmp.texi | 14 ++++---------- nptl/pthread_create.c | 3 ++- setjmp/setjmp.h | 5 ----- sysdeps/nptl/libc_start_call_main.h | 3 ++- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index 2f67f3f315..a30fb748d6 100644 --- a/NEWS +++ b/NEWS @@ -17,7 +17,9 @@ Deprecated and removed features, and other changes affecting compatibility: Changes to build and runtime requirements: - [Add changes to build and runtime requirements here] +* The setjmp now uses the BSD semantic as default, where the signal mask + is saved. This is required to avoid the break of SIGABRT handler for + the async-signal-safe abort implementation. Security related changes: diff --git a/manual/setjmp.texi b/manual/setjmp.texi index 7092a0dde2..f2d82a2f33 100644 --- a/manual/setjmp.texi +++ b/manual/setjmp.texi @@ -189,16 +189,10 @@ them @code{volatile}. @section Non-Local Exits and Signals In BSD Unix systems, @code{setjmp} and @code{longjmp} also save and -restore the set of blocked signals; see @ref{Blocking Signals}. However, -the POSIX.1 standard requires @code{setjmp} and @code{longjmp} not to -change the set of blocked signals, and provides an additional pair of -functions (@code{sigsetjmp} and @code{siglongjmp}) to get the BSD -behavior. - -The behavior of @code{setjmp} and @code{longjmp} in @theglibc{} is -controlled by feature test macros; see @ref{Feature Test Macros}. The -default in @theglibc{} is the POSIX.1 behavior rather than the BSD -behavior. +restore the set of blocked signals; see @ref{Blocking Signals}, while +on @w{System V} they will not. POSIX does not specify the relation of +@code{setjmp} and @code{longjmp} to signal mask. The default in +@theglibc{} is the BSD behavior. The facilities in this section are declared in the header file @file{setjmp.h}. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 1d3665d5ed..527cb9017d 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -402,7 +402,8 @@ start_thread (void *arg) the saved signal mask), so that is a false positive. */ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); #endif - not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + not_first_call = __sigsetjmp ( + (struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf, 0); DIAG_POP_NEEDS_COMMENT; /* No previous handlers. NB: This must be done after setjmp since the diff --git a/setjmp/setjmp.h b/setjmp/setjmp.h index 1309c6210d..98efa3e863 100644 --- a/setjmp/setjmp.h +++ b/setjmp/setjmp.h @@ -44,11 +44,6 @@ extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL Return 0. */ extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL; -/* Do not save the signal mask. This is equivalent to the `_setjmp' - BSD function. */ -#define setjmp(env) _setjmp (env) - - /* Jump to the environment saved in ENV, making the `setjmp' call there return VAL, or 1 if VAL is 0. */ extern void longjmp (struct __jmp_buf_tag __env[1], int __val) diff --git a/sysdeps/nptl/libc_start_call_main.h b/sysdeps/nptl/libc_start_call_main.h index 26ac8dd53b..c41ca6843b 100644 --- a/sysdeps/nptl/libc_start_call_main.h +++ b/sysdeps/nptl/libc_start_call_main.h @@ -41,7 +41,8 @@ __libc_start_call_main (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), the saved signal mask), so that is a false positive. */ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); #endif - not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + not_first_call = __sigsetjmp ( + (struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf, 0); DIAG_POP_NEEDS_COMMENT; if (__glibc_likely (! not_first_call)) {