From f6a83b477b5b1b7bd1706327f9d6de19b6efe386 Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Wed, 10 Jul 2019 15:22:58 -0400 Subject: [PATCH] Fix the use of sigaltstack to return to the saved main stack. Previously, musl would reject the call with -ENOMEM, because the main stack typically has ss_size == 0 and ss_flags == SS_DISABLE. --- src/signal/sigaltstack.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/signal/sigaltstack.c b/src/signal/sigaltstack.c index cfa3f5c1..b0d799d2 100644 --- a/src/signal/sigaltstack.c +++ b/src/signal/sigaltstack.c @@ -4,11 +4,19 @@ int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) { + // We must check requirements which Linux fails to verify in the syscall + // itself. if (ss) { - if (ss->ss_size < MINSIGSTKSZ) { + // The syscall does already check against MINSIGSTKSZ, however, + // the kernel's value is smaller than musl's value on some + // architectures. Thus, although this check may appear + // redundant, it is not. + if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) { errno = ENOMEM; return -1; } + // Linux ignores SS_ONSTACK on input, but POSIX requires an + // error. if (ss->ss_flags & SS_ONSTACK) { errno = EINVAL; return -1; -- 2.22.0.410.gd8fdbe21b5-goog