]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Make __getrandom_nocancel set errno and add a _nostatus version
authorXi Ruoyao <xry111@xry111.site>
Thu, 4 Jan 2024 13:41:20 +0000 (21:41 +0800)
committerAndreas K. Hüttel <dilfridge@gentoo.org>
Fri, 12 Jan 2024 13:23:11 +0000 (14:23 +0100)
The __getrandom_nocancel function returns errors as negative values
instead of errno.  This is inconsistent with other _nocancel functions
and it breaks "TEMP_FAILURE_RETRY (__getrandom_nocancel (p, n, 0))" in
__arc4random_buf.  Use INLINE_SYSCALL_CALL instead of
INTERNAL_SYSCALL_CALL to fix this issue.

But __getrandom_nocancel has been avoiding from touching errno for a
reason, see BZ 29624.  So add a __getrandom_nocancel_nostatus function
and use it in tcache_key_initialize.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
malloc/malloc.c
sysdeps/generic/not-cancel.h
sysdeps/mach/hurd/not-cancel.h
sysdeps/unix/sysv/linux/not-cancel.h

index 198e78a1625a99aff355040f1474c282135509f1..bcb6e5b83ca9777df3c1ade273d821d5b742b2fb 100644 (file)
@@ -3139,7 +3139,9 @@ static uintptr_t tcache_key;
 static void
 tcache_key_initialize (void)
 {
-  if (__getrandom_nocancel (&tcache_key, sizeof(tcache_key), GRND_NONBLOCK)
+  /* We need to use the _nostatus version here, see BZ 29624.  */
+  if (__getrandom_nocancel_nostatus (&tcache_key, sizeof(tcache_key),
+                                    GRND_NONBLOCK)
       != sizeof (tcache_key))
     {
       tcache_key = random_bits ();
index d9a6cba4433dcc95690d87f79af137152c37de09..2dd10646004611cfc511acb8a88a00a3183d5796 100644 (file)
@@ -51,6 +51,8 @@
   __fcntl64 (fd, cmd, __VA_ARGS__)
 #define __getrandom_nocancel(buf, size, flags) \
   __getrandom (buf, size, flags)
+#define __getrandom_nocancel_nostatus(buf, size, flags) \
+  __getrandom (buf, size, flags)
 #define __poll_infinity_nocancel(fds, nfds) \
   __poll (fds, nfds, -1)
 
index 411f5796ae19d49d105df3bd0c97ce6b5fbe0d15..69fb3c00ef774d004f55dca9c5a921313556405b 100644 (file)
@@ -76,8 +76,10 @@ __typeof (__fcntl) __fcntl_nocancel;
 #define __fcntl64_nocancel(...) \
   __fcntl_nocancel (__VA_ARGS__)
 
+/* Non cancellable getrandom syscall that does not also set errno in case of
+   failure.  */
 static inline ssize_t
-__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
+__getrandom_nocancel_nostatus (void *buf, size_t buflen, unsigned int flags)
 {
   int save_errno = errno;
   ssize_t r = __getrandom (buf, buflen, flags);
@@ -86,6 +88,9 @@ __getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
   return r;
 }
 
+#define __getrandom_nocancel(buf, size, flags) \
+  __getrandom (buf, size, flags)
+
 #define __poll_infinity_nocancel(fds, nfds) \
   __poll (fds, nfds, -1)
 
index 50483d9e7445374a0d9c925bd0376973c739463d..2a7585b73f2b23f76b0dc5cd526a17bc64600c8c 100644 (file)
@@ -85,6 +85,14 @@ __writev_nocancel_nostatus (int fd, const struct iovec *iov, int iovcnt)
 
 static inline ssize_t
 __getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
+{
+  return INLINE_SYSCALL_CALL (getrandom, buf, buflen, flags);
+}
+
+/* Non cancellable getrandom syscall that does not also set errno in case of
+   failure.  */
+static inline ssize_t
+__getrandom_nocancel_nostatus (void *buf, size_t buflen, unsigned int flags)
 {
   return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags);
 }