mailing list of musl libc
 help / color / mirror / code / Atom feed
From: James Y Knight <jyknight@google.com>
To: musl@lists.openwall.com
Subject: Re: [PATCH] Fix the use of sigaltstack to return to the saved main stack.
Date: Wed, 10 Jul 2019 16:11:23 -0400	[thread overview]
Message-ID: <CAA2zVHrijyMnrUef5XUqRKX+H0QOwugRmk+gJOgPLvbxJ78=9g@mail.gmail.com> (raw)
In-Reply-To: <20190710183931.GT1506@brightrain.aerifal.cx>


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

Updated patches attached.

W.r.t.:
> Here, "set to" is
> probably something the resolution of Austin Group issue 1187 failed to
> fix; it should probably be "includes" rather than "is set to". But I'm
> not sure it makes sense to have any flags set alongside SS_DISABLE
> anyway.

While the SS_AUTODISARM flag has no effect if specified alongside
SS_DISABLE, the kernel still accepts and stores it. So A subsequent call to
sigaltstack can return SS_DISABLE|SS_AUTODISARM in the "old" flags value.
To avoid the case where the old value returned from sigaltstack is not
accepted back as the input, I used the "includes" semantics here.


On Wed, Jul 10, 2019 at 2:39 PM Rich Felker <dalias@libc.org> wrote:

> On Wed, Jul 10, 2019 at 02:04:18PM -0400, James Y Knight wrote:
> > On Tue, Jul 9, 2019 at 3:30 PM Rich Felker <dalias@libc.org> wrote:
>
>

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

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

From f6a83b477b5b1b7bd1706327f9d6de19b6efe386 Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight@google.com>
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


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

From 313618c8e00df106528e24cabc38379b4783f51e 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..2bfe329 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


  reply	other threads:[~2019-07-10 20:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-09 19:01 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA2zVHrijyMnrUef5XUqRKX+H0QOwugRmk+gJOgPLvbxJ78=9g@mail.gmail.com' \
    --to=jyknight@google.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).