public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Anthony Iliopoulos <ailiop@suse.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH] arc4random: fix getrandom fallback to /dev/urandom
Date: Wed, 3 Apr 2024 14:26:39 -0300	[thread overview]
Message-ID: <dd7983f0-fb8e-4871-aed9-077ec48fcd65@linaro.org> (raw)
In-Reply-To: <20240403165523.23129-1-ailiop@suse.com>



On 03/04/24 13:55, Anthony Iliopoulos wrote:
> arc4random_buf relies on the errno of getrandom_nocancel to fallback to
> /dev/urandom, but getrandom_nocancel returns a status code instead of
> the syscall errno (-ENOSYS) so it breaks the expectation and thus the
> fallback in cases where a kernel does not support the getrandom syscall.
> 
> Commit 609c9d0951da ("malloc: Do not clobber errno on __getrandom_nocancel
> (BZ #29624)") changed __getrandom_nocancel from INLINE_SYSCALL_CALL to
> INTERNAL_SYSCALL_CALL and modified arc4random_buf to rely on the return
> status instead of errno.
> 
> Commit 5a85786a9005 ("Make __getrandom_nocancel set errno and add a
> _nostatus version") changed __getrandom_nocancel back to
> INLINE_SYSCALL_CALL and added a __getrandom_nocancel_nostatus variant
> that calls via INTERNAL_SYSCALL_CALL, but this broke the fallback of
> arc4random on kernels where the getrandom syscall is not available.
> 
> Fix it by calling __getrandom_nocancel_nostatus from arc4random_buf so
> that the fallback works again.
> 
> Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
> Fixes: 5a85786a9005 ("Make __getrandom_nocancel set errno and add a _nostatus version")

It is a user-visible change, could you open a bug report so we can backport it
2.39? The patch looks good to me.

> ---
>  stdlib/arc4random.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
> index 3ae8fc130234..9b6a6ee85150 100644
> --- a/stdlib/arc4random.c
> +++ b/stdlib/arc4random.c
> @@ -42,7 +42,7 @@ __arc4random_buf (void *p, size_t n)
>  
>    for (;;)
>      {
> -      l = TEMP_FAILURE_RETRY (__getrandom_nocancel (p, n, 0));
> +      l = TEMP_FAILURE_RETRY (__getrandom_nocancel_nostatus (p, n, 0));
>        if (l > 0)
>  	{
>  	  if ((size_t) l == n)

  reply	other threads:[~2024-04-03 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 16:55 Anthony Iliopoulos
2024-04-03 17:26 ` Adhemerval Zanella Netto [this message]
2024-04-03 17:35 ` Florian Weimer
2024-04-03 17:48   ` Adhemerval Zanella Netto
2024-04-03 17:50     ` Adhemerval Zanella Netto

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=dd7983f0-fb8e-4871-aed9-077ec48fcd65@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=ailiop@suse.com \
    --cc=libc-alpha@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).