mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] [RFC] fixing sysconf(_SC_MINSIGSTKSZ) & sigaltstack behavior
@ 2024-08-31 16:40 Rich Felker
  0 siblings, 0 replies; only message in thread
From: Rich Felker @ 2024-08-31 16:40 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

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

[-- Attachment #2: 0001-sigaltstack-enforce-dynamic-MINSIGSTKSZ-limit.patch --]
[-- Type: text/plain, Size: 1169 bytes --]

From 300a1f53907a4acaadd9a696d0c67eee6fc10430 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
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 <signal.h>
 #include <errno.h>
+#include <unistd.h>
 #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


[-- Attachment #3: 0002-sysconf-fix-_SC_MINSIGSTKSZ-computation-to-match-ker.patch --]
[-- Type: text/plain, Size: 1540 bytes --]

From 8c43c562694fd0436494dc9d3faabb3eea86f9d8 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-31 16:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-31 16:40 [musl] [PATCH] [RFC] fixing sysconf(_SC_MINSIGSTKSZ) & sigaltstack behavior Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).