From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Daniel Palmer <daniel@thingy.jp>
Cc: w@1wt.eu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: Fix WIFSIGNALED(0)
Date: Sun, 18 Oct 2026 13:41:11 +0200 [thread overview]
Message-ID: <dc1db82f-1f48-4742-99d1-1231f64a0ece@t-8ch.de> (raw)
In-Reply-To: <20261018105341.243797-1-daniel@thingy.jp>
Hi Daniel,
On 2026-10-18 19:53:41+0900, Daniel Palmer wrote:
> WIFSIGNALED(0) currently returns true, so a process that exited
> normally with status 0 looks like it was killed by a signal.
>
> The macro uses a trick of checking whether status - 1 is below
> 0xff but is subtly broken because of using signed arithmetic.
> For 0 it computes -1 < 0xff which is true.
>
> Do what musl does: mask the status to 16 bits and use unsigned
> arithmetic so 0 wraps to 0xffff and the comparison fails.
> The mask also prevents bits we don't care about from sneaking in.
We already have commit 368fae47c6ca ("tools/nolibc: fix WIFSIGNALED()
for status 0") for this issue in nolibc-next. This implementation is
masking the status with 0xffff. OTOH the musl implementation of
WIFCONTINUED() is also missing the masking, so I am not sure how
necessary it is.
I'll look into it some more.
> Fixes: 8c934d4822c7 ("tools/nolibc: add helpers for wait() signal exits")
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
> ---
>
> I'm putting off sending anything else (dirfd and some other bits)
> until after the merge window has finished.. but this one seems like
> it should be fixed sooner.
Feel free to send the patches already. We won't apply them until after
the merge window, but we can discuss them before. There are no other
trees with changes to nolibc, so there won't be any conflicts.
> I found this while debugging an annoying issue in my homebrew nolibc
> based shell.
>
> tools/include/nolibc/types.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h
> index 8f3cb18df7f1..d241629b9e67 100644
> --- a/tools/include/nolibc/types.h
> +++ b/tools/include/nolibc/types.h
> @@ -119,7 +119,7 @@ struct timeval {
> #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
> #define WIFEXITED(status) (((status) & 0x7f) == 0)
> #define WTERMSIG(status) ((status) & 0x7f)
> -#define WIFSIGNALED(status) ((status) - 1 < 0xff)
> +#define WIFSIGNALED(status) (((status) & 0xffff) - 1U < 0xffU)
>
> /* standard exit() codes */
> #define EXIT_SUCCESS 0
> --
> 2.53.0
>
prev parent reply other threads:[~2026-10-18 11:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 10:53 Daniel Palmer
2026-10-18 11:41 ` Thomas Weißschuh [this message]
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=dc1db82f-1f48-4742-99d1-1231f64a0ece@t-8ch.de \
--to=linux@weissschuh.net \
--cc=daniel@thingy.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=w@1wt.eu \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®