unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Anthony Iliopoulos <ailiop@suse.com>
To: libc-alpha@sourceware.org
Subject: [PATCH] arc4random: fix getrandom fallback to /dev/urandom
Date: Wed,  3 Apr 2024 18:55:23 +0200	[thread overview]
Message-ID: <20240403165523.23129-1-ailiop@suse.com> (raw)

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")
---
 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)
-- 
2.44.0


             reply	other threads:[~2024-04-03 16:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 16:55 Anthony Iliopoulos [this message]
2024-04-03 17:26 ` [PATCH] arc4random: fix getrandom fallback to /dev/urandom Adhemerval Zanella Netto
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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=20240403165523.23129-1-ailiop@suse.com \
    --to=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).