mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Fix the use of sigaltstack to return to the saved main stack.
@ 2019-07-09 19:01 James Y Knight
  2019-07-09 19:30 ` Rich Felker
  0 siblings, 1 reply; 10+ messages in thread
From: James Y Knight @ 2019-07-09 19:01 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 392 bytes --]

Previously, musl would reject the call, because the main stack has
ss_size == 0 and ss_flags == SS_DISABLE.

We could condition on ss_flags not containing SS_DISABLE, but instead,
simply remove the ss_size check, as the kernel performs the same check,
anyhow.

[[Note: I've also included the corresponding patch to libc-tests. I'm not
sure if this is OK, or if I should send it separately?]]

[-- Attachment #1.2: Type: text/html, Size: 476 bytes --]

[-- Attachment #2: 0001-Fix-the-use-of-sigaltstack-to-return-to-the-saved-ma.patch --]
[-- Type: text/x-patch, Size: 1162 bytes --]

From fe70a508fe945cb1a44f8a6bbd87ee295637447b Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight@google.com>
Date: Tue, 9 Jul 2019 14:59:01 -0400
Subject: [PATCH] Fix the use of sigaltstack to return to the saved main stack.

Previously, musl would reject the call, because the main stack has
ss_size == 0 and ss_flags == SS_DISABLE.

We could condition on ss_flags not containing SS_DISABLE, but instead,
simply remove the ss_size check, as the kernel performs the same check,
anyhow.
---
 src/signal/sigaltstack.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/signal/sigaltstack.c b/src/signal/sigaltstack.c
index cfa3f5c1..d8e8eb0b 100644
--- a/src/signal/sigaltstack.c
+++ b/src/signal/sigaltstack.c
@@ -4,15 +4,9 @@
 
 int sigaltstack(const stack_t *restrict ss, stack_t *restrict old)
 {
-	if (ss) {
-		if (ss->ss_size < MINSIGSTKSZ) {
-			errno = ENOMEM;
-			return -1;
-		}
-		if (ss->ss_flags & SS_ONSTACK) {
-			errno = EINVAL;
-			return -1;
-		}
+	if (ss && (ss->ss_flags & SS_ONSTACK)) {
+		errno = EINVAL;
+		return -1;
 	}
 	return syscall(SYS_sigaltstack, ss, old);
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


[-- Attachment #3: 0001-Verify-that-returning-to-the-original-stack-doesn-t-.patch --]
[-- Type: text/x-patch, Size: 1165 bytes --]

From 9272ed8666f930dc2f24d05b1fd248584bbf495f Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight@google.com>
Date: Tue, 9 Jul 2019 14:31:24 -0400
Subject: [PATCH] Verify that returning to the original stack doesn't return an
 error (e.g. ENOMEM).

---
 src/regression/sigaltstack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/regression/sigaltstack.c b/src/regression/sigaltstack.c
index bfdc44a..6847454 100644
--- a/src/regression/sigaltstack.c
+++ b/src/regression/sigaltstack.c
@@ -30,7 +30,7 @@ static void handler(int sig)
 
 int main(void)
 {
-	stack_t ss;
+	stack_t ss, oldss;
 	struct sigaction sa;
 
 	ss.ss_sp = stack;
@@ -39,7 +39,7 @@ int main(void)
 	sa.sa_handler = handler;
 	sa.sa_flags = SA_ONSTACK;
 
-	T(sigaltstack(&ss, 0));
+	T(sigaltstack(&ss, &oldss));
 	T(sigfillset(&sa.sa_mask));
 	T(sigaction(SIGUSR1, &sa, 0));
 	T(raise(SIGUSR1));
@@ -56,7 +56,7 @@ int main(void)
 		t_error("sigaltstack with bad ss_flags should have failed with EINVAL, "
 			"got %s\n", strerror(errno));
 	errno = 0;
-	T(sigaltstack(0, 0));
+	T(sigaltstack(oldss, 0));
 
 	return t_status;
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-07-12 16:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-09 19:01 [PATCH] Fix the use of sigaltstack to return to the saved main stack James Y Knight
2019-07-09 19:30 ` Rich Felker
2019-07-10 18:04   ` James Y Knight
2019-07-10 18:39     ` Rich Felker
2019-07-10 20:11       ` James Y Knight
2019-07-10 21:23         ` Szabolcs Nagy
2019-07-10 21:48           ` Rich Felker
2019-07-11 15:51             ` James Y Knight
2019-07-12  9:18           ` Florian Weimer
2019-07-12 16:06             ` 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).