From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=C+5b0b6P; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B267A5A004E for ; Tue, 20 Aug 2024 02:50:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1724114993; bh=5WZxtunHufcKwW5U6weTnZnyBPwqUEd0QUp5E7eQXGs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C+5b0b6P74Pi74OqPAJhAbS38uQtd086PPDzSPolBMb3N9yuriqjiRnav/mLJIBdT qFT8InKjEyf+f7IugWPZsB/QlBTE2E4rkuFF+MoxzlIGD4l97rwTSpiNr/4SRxpHSa T//Kmp+Ic8kpD/2S7I1ZX5gsiQJjc39dHqKfb8RfZ9NB6xAPtwhPHPRMJcgEQ+miTQ iTQVTAdfInkxjOuywmpVa1rmjwLusNwogHpexrqPiEzggEisKVQNffMrBrMxQQHUPJ Pvh/Wv5OTOcLIHfrOasNGIvb4A38bPAnyUd2MRA/sqwBDKZD/h79ZLwYlv6hZhrcrm e8iTGe2vXuL+A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WnrTY3sVJz4x2J; Tue, 20 Aug 2024 10:49:53 +1000 (AEST) Date: Tue, 20 Aug 2024 10:48:06 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/2] util: Provide own version of close_range(), and no-op fallback Message-ID: References: <20240819231505.1481940-1-sbrivio@redhat.com> <20240819231505.1481940-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2C/Aq2DotyTLuBKa" Content-Disposition: inline In-Reply-To: <20240819231505.1481940-3-sbrivio@redhat.com> Message-ID-Hash: QZJXA35EGLO24AF2XARD2RW77GEAQ3M4 X-Message-ID-Hash: QZJXA35EGLO24AF2XARD2RW77GEAQ3M4 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, lemmi@nerd2nerd.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --2C/Aq2DotyTLuBKa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 20, 2024 at 01:15:05AM +0200, Stefano Brivio wrote: > musl, as of 1.2.5, and glibc < 2.34 don't ship a (trivial) > close_range() implementation. This will probably be added to musl > soon, by the way: > https://www.openwall.com/lists/musl/2024/08/01/9 >=20 > Add a weakly-aliased implementation, if it's supported by the kernel. > If it's not supported (< 5.9), use a no-op fallback. Looping over 2^31 > file descriptors calling close() on them is probably not a good idea. >=20 > Reported-by: lemmi > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > util.h | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) >=20 > diff --git a/util.h b/util.h > index cb4d181..a9deba5 100644 > --- a/util.h > +++ b/util.h > @@ -14,6 +14,9 @@ > #include > #include > #include > +#include > +#include > +#include > =20 > #include "log.h" > =20 > @@ -160,6 +163,23 @@ struct ctx; > =20 > /* cppcheck-suppress funcArgNamesDifferent */ > __attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i); } > + > +#ifdef CLOSE_RANGE_UNSHARE /* Linux kernel >=3D 5.9 */ > +/* glibc < 2.34 and musl as of 1.2.5 need these */ > +#ifndef SYS_close_range > +#define SYS_close_range 436 > +#endif > +__attribute__ ((weak)) int close_range(unsigned int first, unsigned int = last, > + int flags) { > + return syscall(SYS_close_range, first, last, flags); > +} > +#else > +/* No reasonable fallback option */ > +int close_range(unsigned int first, unsigned int last, int flags) { > + return 0; > +} > +#endif > + > int sock_l4_sa(const struct ctx *c, enum epoll_type type, > const void *sa, socklen_t sl, > const char *ifname, bool v6only, uint32_t data); --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --2C/Aq2DotyTLuBKa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbD58UACgkQzQJF27ox 2Gcqpg//duUMYWnONGPo6oyl1ZGg5nxzDnkD+rYXypLeFodYxYsgojNH8rmWEda2 EDAFQ2/3lImswhl3xa8i/JRc+iETQaeICA3+2y5Tm3/iqg8QI97izCTT4luLLIcB KyZJyp7ygdI8vcet6Mk3/RFggBJtOk3oEzagRAmfyJVxydsARMp+9SwhVh79+8Wd /nyxcrOuLfcUeb+CXkCK2VrMQLh/IihPFlols2pTLiSorjyyDPG8cG8OEFs8IzI2 w4UPqHyM3lg4+4AP9ak2dZqpWhLUqtOpuLUU7W2rVSEXY7HPu373jeg2nLT4cQEY M1XIFUyXacmcuk+feV5tGwB/2/WxOcEwH5lBdlDoXTQyS8Dc980ZOvP+9Ukae8nn X05ETx4DmehcXnx9/s606zcC9ZxsyhbDaQCKTFZcRv0ETLy6CEjnJ5EK6HpvZvnT SuECANuNMQ/noWfrEppLu9GfakawVgKJW+BND2ksoSTBB+RjhbpU9IBASkhAr+dH q+LZaY01XdMfkoayH3tSxMr3taz+pKrTmjouxAHQpK96X7mUMXk0/7YSgD/tPVLp Z93FjxFCL5KNKM+HjgrzkFWFOlXJSGwO+2+BuaDaIGGMCnVH1ZY1PaOrEWfRlNxL ojYkXhiw5NajwEKXERiu0JN5YvCKzef/kBonyx7zIzLbBHV+i48= =s5BX -----END PGP SIGNATURE----- --2C/Aq2DotyTLuBKa--