From: Willy Tarreau <w@1wt.eu>
To: Daniel Palmer <daniel@thingy.jp>
Cc: linux@weissschuh.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: stackprotector: Avoid stalling program startup if crng is not init yet
Date: Fri, 22 May 2026 11:39:27 +0200 [thread overview]
Message-ID: <ahAkTz3M3Kfv68OA@1wt.eu> (raw)
In-Reply-To: <20260522090726.726985-1-daniel@thingy.jp>
Hi Daniel!
On Fri, May 22, 2026 at 06:07:26PM +0900, Daniel Palmer wrote:
> We are using the getrandom syscall to get a random seed for the
> stack protector canary but we are calling it with no flags which means
> it'll block until there is some real randomness to return.
>
> This means that if the crng is not ready yet program startup will
> block and if you are unlucky that could be for a long time and
> look like the program has crashed.
>
> There is a comment in the code about mixing in the pid to make
> sure the canary isn't 0 even if getrandom fails so it seems ok
> to pass the non-blocking and insecure flags so it doesn't block
> and potentially return something even if the crng is not init
> yet.
>
> Fixes: 7188d4637e95 ("tools/nolibc: add support for stack protector")
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
Acked-by: Willy Tarreau <w@1wt.eu>
> ---
>
> The insecure flag is apparently from 5.6, I think Willy said before
> we are trying to keep nolibc working on the oldest LTS kernel.
> That seems to be 5.10 so I think its ok?
Sounds reasonable. We could also condition the flag to its existence
if it causes issues.
> Anyhow, I switched compilers for my nommu target and everything
> stopped working, tracked it down to this. my other compiler must
> have not supported the stack protector.
Possible, indeed.
Thanks!
Willy
>
> tools/include/nolibc/stackprotector.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h
> index e11c20c75465..916a92062ba0 100644
> --- a/tools/include/nolibc/stackprotector.h
> +++ b/tools/include/nolibc/stackprotector.h
> @@ -42,7 +42,8 @@ uintptr_t __stack_chk_guard;
>
> static __nolibc_no_stack_protector void __stack_chk_init(void)
> {
> - __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0);
> + __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard),
> + GRND_INSECURE | GRND_NONBLOCK);
> /* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */
> if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard)
> __stack_chk_guard ^= (uintptr_t) &__stack_chk_guard;
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-05-22 9:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 9:07 [PATCH] tools/nolibc: stackprotector: Avoid stalling program startup if crng is not init yet Daniel Palmer
2026-05-22 9:11 ` Daniel Palmer
2026-05-22 9:39 ` Willy Tarreau [this message]
2026-05-22 14:46 ` Thomas Weißschuh
2026-05-22 22:29 ` Daniel Palmer
2026-05-24 4:25 ` Willy Tarreau
2026-05-24 8:02 ` Thomas Weißschuh
2026-05-24 1:25 ` Daniel Palmer
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=ahAkTz3M3Kfv68OA@1wt.eu \
--to=w@1wt.eu \
--cc=daniel@thingy.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
/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