From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 363A53858D39 for ; Tue, 9 Jan 2024 02:55:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 363A53858D39 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 363A53858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704768911; cv=none; b=cvO+NE3TPv7s6EL578vM9IgZvDTpgIPh+tWo3FV0p4O/q6WRfLFB7cdlnjxmgWd4qbkjrPwJAY0C6uPuiWna2SAvZ8KtPp+3ezSIlU5Ju9HamFkxHT3CDy2frzN0YlUOP7VM3FtAKlI0a+rNgekcOJSrZGzn2NYDthHuTIXYW5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704768911; c=relaxed/simple; bh=eRmLxQznJNmkzeJ1KZMoxqu+ETfBHsrIoB/R+2BBw2g=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=vGVs9PJ6gpAPemSIy5nncUZyxobBMMUafl2Nuww7qex0/G3f4sryqVzX2TWQt1vhPCtqXINNh0lDeoMd/ErzwOmJcgPTVRbo/jTKGBS2p7W3VaNteK+qWTCRYsi+mqLHuGRbsNzQoCOyFd1x6Vz8zk4Ou1ysDlliIXQDTOR5oAo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1704768907; bh=eRmLxQznJNmkzeJ1KZMoxqu+ETfBHsrIoB/R+2BBw2g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JhwjbzGi1ATwd2mlIpgNKi8ASK5k4ckdgpQ7HOTZ21Svfno+mQN/EyF7NZ2lKfcpe 6Hgzj3s58TOIWR5//DXA+UY6wujjnUJO2Z6Uc4kkupRtdr4QLkT2YuIATLdhAtp/TS PTCJTB0UDQCVxVkpOrbCUb5MMBbvKZcS0m0Z9OzQ= Received: from [IPv6:240e:358:1102:4000:dc73:854d:832e:2] (unknown [IPv6:240e:358:1102:4000:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 56E9F669F7; Mon, 8 Jan 2024 21:55:04 -0500 (EST) Message-ID: <580434ff0b49927afb06f6c2b75b5d3e4ad90ef4.camel@xry111.site> Subject: Ping: [PATCH v2] Make __getrandom_nocancel set errno and add a _nostatus version From: Xi Ruoyao To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Netto , "Andreas K . Huettel" , Florian Weimer Date: Tue, 09 Jan 2024 10:55:00 +0800 In-Reply-To: <20240104134243.1581383-1-xry111@xry111.site> References: <20240104134243.1581383-1-xry111@xry111.site> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: Ping. Sorry for an abnormal time period but now we are close to hard freeze, and the next review meeting won't happen before the hard freeze. On Thu, 2024-01-04 at 21:41 +0800, Xi Ruoyao wrote: > The __getrandom_nocancel function returns errors as negative values > instead of errno.=C2=A0 This is inconsistent with other _nocancel functio= ns > and it breaks "TEMP_FAILURE_RETRY (__getrandom_nocancel (p, n, 0))" in > __arc4random_buf.=C2=A0 Use INLINE_SYSCALL_CALL instead of > INTERNAL_SYSCALL_CALL to fix this issue. >=20 > But __getrandom_nocancel has been avoiding from touching errno for a > reason, see BZ 29624.=C2=A0 So add a __getrandom_nocancel_nostatus functi= on > and use it in tcache_key_initialize. >=20 > Signed-off-by: Xi Ruoyao > --- >=20 > Superseds the incorrect patch [v1]. >=20 > [v1]:https://sourceware.org/pipermail/libc-alpha/2024-January/153727.html= . >=20 > =C2=A0malloc/malloc.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= | 4 +++- > =C2=A0sysdeps/generic/not-cancel.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 | 2 ++ > =C2=A0sysdeps/mach/hurd/not-cancel.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = | 7 ++++++- > =C2=A0sysdeps/unix/sysv/linux/not-cancel.h | 8 ++++++++ > =C2=A04 files changed, 19 insertions(+), 2 deletions(-) >=20 > diff --git a/malloc/malloc.c b/malloc/malloc.c > index 198e78a162..bcb6e5b83c 100644 > --- a/malloc/malloc.c > +++ b/malloc/malloc.c > @@ -3139,7 +3139,9 @@ static uintptr_t tcache_key; > =C2=A0static void > =C2=A0tcache_key_initialize (void) > =C2=A0{ > -=C2=A0 if (__getrandom_nocancel (&tcache_key, sizeof(tcache_key), GRND_N= ONBLOCK) > +=C2=A0 /* We need to use the _nostatus version here, see BZ 29624.=C2=A0= */ > +=C2=A0 if (__getrandom_nocancel_nostatus (&tcache_key, sizeof(tcache_key= ), > + =C2=A0=C2=A0=C2=A0=C2=A0 GRND_NONBLOCK) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 !=3D sizeof (tcache_key)) > =C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tcache_key =3D random_bits (); > diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h > index d9a6cba443..2dd1064600 100644 > --- a/sysdeps/generic/not-cancel.h > +++ b/sysdeps/generic/not-cancel.h > @@ -51,6 +51,8 @@ > =C2=A0=C2=A0 __fcntl64 (fd, cmd, __VA_ARGS__) > =C2=A0#define __getrandom_nocancel(buf, size, flags) \ > =C2=A0=C2=A0 __getrandom (buf, size, flags) > +#define __getrandom_nocancel_nostatus(buf, size, flags) \ > +=C2=A0 __getrandom (buf, size, flags) > =C2=A0#define __poll_infinity_nocancel(fds, nfds) \ > =C2=A0=C2=A0 __poll (fds, nfds, -1) > =C2=A0 > diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cance= l.h > index 411f5796ae..69fb3c00ef 100644 > --- a/sysdeps/mach/hurd/not-cancel.h > +++ b/sysdeps/mach/hurd/not-cancel.h > @@ -76,8 +76,10 @@ __typeof (__fcntl) __fcntl_nocancel; > =C2=A0#define __fcntl64_nocancel(...) \ > =C2=A0=C2=A0 __fcntl_nocancel (__VA_ARGS__) > =C2=A0 > +/* Non cancellable getrandom syscall that does not also set errno in cas= e of > +=C2=A0=C2=A0 failure.=C2=A0 */ > =C2=A0static inline ssize_t > -__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) > +__getrandom_nocancel_nostatus (void *buf, size_t buflen, unsigned int fl= ags) > =C2=A0{ > =C2=A0=C2=A0 int save_errno =3D errno; > =C2=A0=C2=A0 ssize_t r =3D __getrandom (buf, buflen, flags); > @@ -86,6 +88,9 @@ __getrandom_nocancel (void *buf, size_t buflen, unsigne= d int flags) > =C2=A0=C2=A0 return r; > =C2=A0} > =C2=A0 > +#define __getrandom_nocancel(buf, size, flags) \ > +=C2=A0 __getrandom (buf, size, flags) > + > =C2=A0#define __poll_infinity_nocancel(fds, nfds) \ > =C2=A0=C2=A0 __poll (fds, nfds, -1) > =C2=A0 > diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/lin= ux/not-cancel.h > index 50483d9e74..2a7585b73f 100644 > --- a/sysdeps/unix/sysv/linux/not-cancel.h > +++ b/sysdeps/unix/sysv/linux/not-cancel.h > @@ -85,6 +85,14 @@ __writev_nocancel_nostatus (int fd, const struct iovec= *iov, int iovcnt) > =C2=A0 > =C2=A0static inline ssize_t > =C2=A0__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) > +{ > +=C2=A0 return INLINE_SYSCALL_CALL (getrandom, buf, buflen, flags); > +} > + > +/* Non cancellable getrandom syscall that does not also set errno in cas= e of > +=C2=A0=C2=A0 failure.=C2=A0 */ > +static inline ssize_t > +__getrandom_nocancel_nostatus (void *buf, size_t buflen, unsigned int fl= ags) > =C2=A0{ > =C2=A0=C2=A0 return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags)= ; > =C2=A0} --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University