From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ouvsmtp1.octopuce.fr (ouvsmtp1.octopuce.fr [194.36.166.50]) by sourceware.org (Postfix) with ESMTPS id 6698E3857354 for ; Thu, 29 Sep 2022 18:44:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6698E3857354 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=opteya.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=opteya.com Received: from panel.vitry.ouvaton.coop (unknown [194.36.166.20]) by ouvsmtp1.octopuce.fr (Postfix) with ESMTPS id A7C6812C; Thu, 29 Sep 2022 20:44:25 +0200 (CEST) Received: from sm.ouvaton.coop (ouvadm.octopuce.fr [194.36.166.2]) by panel.vitry.ouvaton.coop (Postfix) with ESMTPSA id 71DAD5E1ACB; Thu, 29 Sep 2022 20:44:25 +0200 (CEST) MIME-Version: 1.0 Date: Thu, 29 Sep 2022 18:44:25 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: "Yann Droneaud" Message-ID: Subject: Re: [PATCH v2] malloc: Do not clobber errno on __getrandom_nocancel (BZ#29624) To: "Adhemerval Zanella" , libc-alpha@sourceware.org In-Reply-To: <20220929175526.2596756-1-adhemerval.zanella@linaro.org> References: <20220929175526.2596756-1-adhemerval.zanella@linaro.org> X-Originating-IP: 10.0.20.16 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RCVD_IN_SBL_CSS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, 29 septembre 2022 =C3=A0 19:56 "Adhemerval Zanella via Libc-alpha" a =C3= =A9crit: >=20 >=20Use INTERNAL_SYSCALL_CALL instead of INLINE_SYSCALL_CALL. This > requires emulate the semantic for hurd call (so __arc4random_buf > uses the fallback). >=20 >=20Checked on x86_64-linux-gnu. > --- > stdlib/arc4random.c | 4 ++-- > sysdeps/mach/hurd/not-cancel.h | 12 ++++++++++-- > sysdeps/unix/sysv/linux/not-cancel.h | 2 +- > 3 files changed, 13 insertions(+), 5 deletions(-) >=20 >=20diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c > index e417ef624d..0a1f4b8a57 100644 > --- a/stdlib/arc4random.c > +++ b/stdlib/arc4random.c > @@ -34,7 +34,7 @@ void > __arc4random_buf (void *p, size_t n) > { > static int seen_initialized; > - size_t l; > + int l; > int fd; >=20=20 >=20 if (n =3D=3D 0) > @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n) > n -=3D l; > continue; /* Interrupted by a signal; keep going. */ > } > - else if (l < 0 && errno =3D=3D ENOSYS) Aside: I failed to noticed this (the fact is, except commit message, I di= dn't review much Jason's patch) . https://sourceware.org/pipermail/libc-alpha/2022-July/141049.html l being size_t, it cannot be less than 0, thus is there a chance it can a= ctually fallback to reading /dev/urandom ? > + else if (l =3D=3D -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-can= cel.h > index ae58b734e3..518f738519 100644 > --- a/sysdeps/mach/hurd/not-cancel.h > +++ b/sysdeps/mach/hurd/not-cancel.h > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include >=20=20 >=20 /* Non cancellable close syscall. */ > __typeof (__close) __close_nocancel; > @@ -75,8 +76,15 @@ __typeof (__fcntl) __fcntl_nocancel; > #define __fcntl64_nocancel(...) \ > __fcntl_nocancel (__VA_ARGS__) >=20=20 >=20-#define __getrandom_nocancel(buf, size, flags) \ > - __getrandom (buf, size, flags) > +static inline int > +__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) > +{ > + int save_errno =3D errno; > + int r =3D __getrandom (buf, buflen, flags); > + r =3D r =3D=3D -1 ? -errno : r; > + __set_errno (save_errno); > + return r; > +} >=20=20 >=20 #define __poll_infinity_nocancel(fds, nfds) \ > __poll (fds, nfds, -1) > diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/l= inux/not-cancel.h > index a263d294b1..00ab75a405 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 iove= c *iov, int iovcnt) > static inline int > __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); > } >=20=20 >=20 static inline int > --=20 > 2.34.1 > Reviewed-by: Yann Droneaud --=20 Yann=20Droneaud OPTEYA