]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdlib: fix arc4random fallback to /dev/urandom (BZ 31612)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 5 Apr 2024 13:27:29 +0000 (10:27 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 8 Jul 2024 13:23:10 +0000 (10:23 -0300)
The __getrandom_nocancel used by __arc4random_buf uses
INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
the return value instead of errno to fallback to /dev/urandom.

The malloc code now uses __getrandom_nocancel_nostatus, which uses
INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
not set errno (BZ#29624).

Checked on x86_64-linux-gnu.

Reviewed-by: Xi Ruoyao <xry111@xry111.site>
(cherry picked from commit 184b9e530e6326e668709826903b6d30dc6cac3f)

NEWS
stdlib/arc4random.c

diff --git a/NEWS b/NEWS
index 2a40238d0a0cc31ebc15e27ad876678985b31019..4eadd9e51d49d9e2cf3a8bd31405f491ff0d4554 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,8 @@ The following bugs are resolved with this release:
     saved registers
   [31429] build: Glibc failed to build with -march=x86-64-v3
   [31501] dynamic-link: _dl_tlsdesc_dynamic_xsavec may clobber %rbx
+  [31612] libc: arc4random fails to fallback to /dev/urandom if
+    getrandom is not present
   [31640] dynamic-link: POWER10 ld.so crashes in
     elf_machine_load_address with GCC 14
   [31676] Configuring with CC="gcc -march=x86-64-v3"
index 3ae8fc130234b04ddd1ba49da6659c6438ea9331..7818cb9cf66e0f3b428a974c90bee1f120668561 100644 (file)
@@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
          n -= l;
          continue; /* Interrupted by a signal; keep going.  */
        }
-      else if (l == -ENOSYS)
+      else if (l < 0 && errno == ENOSYS)
        break; /* No syscall, so fallback to /dev/urandom.  */
       arc4random_getrandom_failure ();
     }