From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 347753858298; Fri, 30 Sep 2022 18:26:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 347753858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664562368; bh=4BKTJFbetZC9UoazgXLp48eMNKj3YcS5ZVkggRt0Y1A=; h=From:To:Subject:Date:From; b=s6sbfoZkhJLCV93um8ioX7jtW0VIHJ9zUT2eJLbSOykJXyTBBmRh7aAvk1Z3gVIz8 aFy3s8oGm3+UKbkffA65RdxpVW3u1dVuVSPOzlwk6FFgedPAlnZHBAZ7LWfnP0Ukd8 VZMN9WwzEEZAJeAp9AuIenN1l/AemWzipdm4vf8g= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] malloc: Do not clobber errno on __getrandom_nocancel (BZ #29624) X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/master X-Git-Oldrev: 13db9ee2cb3b77e25f852be7d6952882e1be6f00 X-Git-Newrev: 609c9d0951da387cd523b5db42a82d38dabc37c4 Message-Id: <20220930182608.347753858298@sourceware.org> Date: Fri, 30 Sep 2022 18:26:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=609c9d0951da387cd523b5db42a82d38dabc37c4 commit 609c9d0951da387cd523b5db42a82d38dabc37c4 Author: Adhemerval Zanella Date: Thu Sep 29 16:18:06 2022 -0300 malloc: Do not clobber errno on __getrandom_nocancel (BZ #29624) Use INTERNAL_SYSCALL_CALL instead of INLINE_SYSCALL_CALL. This requires emulate the semantic for hurd call (so __arc4random_buf uses the fallback). Checked on x86_64-linux-gnu. Reviewed-by: Wilco Dijkstra Diff: --- stdlib/arc4random.c | 2 +- sysdeps/mach/hurd/not-cancel.h | 12 ++++++++++-- sysdeps/unix/sysv/linux/not-cancel.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c index 960a38f295..c126c601bf 100644 --- a/stdlib/arc4random.c +++ b/stdlib/arc4random.c @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n) n -= l; continue; /* Interrupted by a signal; keep going. */ } - else if (l < 0 && errno == ENOSYS) + else if (l == -ENOSYS) break; /* No syscall, so fallback to /dev/urandom. */ arc4random_getrandom_failure (); } diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h index ae58b734e3..e2edfb1cf3 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -75,8 +76,15 @@ __typeof (__fcntl) __fcntl_nocancel; #define __fcntl64_nocancel(...) \ __fcntl_nocancel (__VA_ARGS__) -#define __getrandom_nocancel(buf, size, flags) \ - __getrandom (buf, size, flags) +static inline ssize_t +__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) +{ + int save_errno = errno; + ssize_t r = __getrandom (buf, buflen, flags); + r = r == -1 ? -errno : r; + __set_errno (save_errno); + return r; +} #define __poll_infinity_nocancel(fds, nfds) \ __poll (fds, nfds, -1) diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index cf35c8bfc9..93615de681 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -71,7 +71,7 @@ __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); + return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags); } static inline int