From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id E1EFA2DC80 for ; Sat, 31 Aug 2024 18:40:17 +0200 (CEST) Received: (qmail 32388 invoked by uid 550); 31 Aug 2024 16:40:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 32353 invoked from network); 31 Aug 2024 16:40:12 -0000 Date: Sat, 31 Aug 2024 12:40:04 -0400 From: Rich Felker To: musl@lists.openwall.com Message-ID: <20240831164002.GR10433@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tBhgiDt8dP1efIIJ" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [musl] [PATCH] [RFC] fixing sysconf(_SC_MINSIGSTKSZ) & sigaltstack behavior --tBhgiDt8dP1efIIJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline These do not fix the ppc 4k/8k discrepancy, which needs to be addressed separately, but do fix sysconf(_SC_MINSIGSTKSZ) not working as intended. Rich --tBhgiDt8dP1efIIJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-sigaltstack-enforce-dynamic-MINSIGSTKSZ-limit.patch" >From 300a1f53907a4acaadd9a696d0c67eee6fc10430 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 31 Aug 2024 12:25:44 -0400 Subject: [PATCH 1/2] sigaltstack: enforce dynamic MINSIGSTKSZ limit commit 996b6154b20184c3b08cce28eb01edb7f47e9413 added support for querying the dynamic limit but did not enforce it in sigaltstack. the kernel also does not seem to reliably enforce it, or at least does not necessarily enforce the same limit exposed to userspace, so it needs to be enforced here. --- src/signal/sigaltstack.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/signal/sigaltstack.c b/src/signal/sigaltstack.c index d3a6e821..616625c5 100644 --- a/src/signal/sigaltstack.c +++ b/src/signal/sigaltstack.c @@ -1,11 +1,13 @@ #include #include +#include #include "syscall.h" int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) { if (ss) { - if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) { + size_t min = sysconf(_SC_MINSIGSTKSZ); + if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < min) { errno = ENOMEM; return -1; } -- 2.21.0 --tBhgiDt8dP1efIIJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-sysconf-fix-_SC_MINSIGSTKSZ-computation-to-match-ker.patch" >From 8c43c562694fd0436494dc9d3faabb3eea86f9d8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 31 Aug 2024 12:34:13 -0400 Subject: [PATCH 2/2] sysconf: fix _SC_MINSIGSTKSZ computation to match kernel interpretation the value placed in the aux vector AT_MINSIGSTKSZ by the kernel is purely the signal frame size, and does not include any execution space for the signal handler. this is contrary to the POSIX definition of MINSIGSTKSZ to be a value that can actually execute at least some minimal signal handler, and contrary to the historical definitions of MINSIGSTKSZ which had at least 1k of headroom. --- src/conf/sysconf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c index 60d3e745..8dd5c725 100644 --- a/src/conf/sysconf.c +++ b/src/conf/sysconf.c @@ -220,8 +220,13 @@ long sysconf(int name) return (mem > LONG_MAX) ? LONG_MAX : mem; case JT_MINSIGSTKSZ & 255: case JT_SIGSTKSZ & 255: ; - long val = __getauxval(AT_MINSIGSTKSZ); - if (val < MINSIGSTKSZ) val = MINSIGSTKSZ; + /* Value from auxv/kernel is only sigfame size. Clamp it + * to at least 1k below arch's traditional MINSIGSTKSZ, + * then add 1k of working space for signal handler. */ + unsigned long sigframe_sz = __getauxval(AT_MINSIGSTKSZ); + if (sigframe_sz < MINSIGSTKSZ - 1024) + sigframe_sz = MINSIGSTKSZ - 1024; + unsigned val = sigframe_sz + 1024; if (values[name] == JT_SIGSTKSZ) val += SIGSTKSZ - MINSIGSTKSZ; return val; -- 2.21.0 --tBhgiDt8dP1efIIJ--