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=ryojHlFl; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 9841B5A004F for ; Wed, 21 Aug 2024 04:51:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1724208670; bh=1nki9GgC9WX27Hh0SGpgyMS03/nxgjHRde4+w7XFybE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ryojHlFlMOA/aSGEbNj1miwRNgTpqQ3eonjsvpjHMwoyEgxjclEJlr+pO9Mwp2rqT jsKm7MpgmXhUl8uVYLNtmmmWwAbkTTY7vUjtr+cYLJvfClN+7WNF8ehW+eDZt95OvP iH8epWICuaicuNN/nBHSGrgFW4xZ+WxYr9rRIe8qP174LrKeXgg7RaIsbzSni2qooy /iHMHYvx+yRTQA7Orq4uD96GgGRRsAk2g4K+opLLoAa4kB0OxjfMMOp+/VRc116bo0 g5Omrrn1STv4e56TN+Nhfq+MYBnxy0WmYn9uQXp1FvRhON2FqPz2uqbK0ru7l6PaF1 sQayGUYjy2ziw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WpW720gmmz4x7B; Wed, 21 Aug 2024 12:51:10 +1000 (AEST) Date: Wed, 21 Aug 2024 11:38:43 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 2/2] util: Provide own version of close_range(), and no-op fallback Message-ID: References: <20240820215853.2166370-1-sbrivio@redhat.com> <20240820215853.2166370-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BO+Bbg/q7mRwxp0f" Content-Disposition: inline In-Reply-To: <20240820215853.2166370-3-sbrivio@redhat.com> Message-ID-Hash: A66EMIQBWYRZ6LDA5DIJP5EHBKNI4AME X-Message-ID-Hash: A66EMIQBWYRZ6LDA5DIJP5EHBKNI4AME 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: --BO+Bbg/q7mRwxp0f Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 20, 2024 at 11:58:53PM +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 | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) >=20 > diff --git a/util.h b/util.h > index cb4d181..9c95dcd 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,25 @@ 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)) > +/* cppcheck-suppress funcArgNamesDifferent */ > +int close_range(unsigned int first, unsigned int last, int flags) { > + return syscall(SYS_close_range, first, last, flags); > +} > +#else > +/* No reasonable fallback option */ > +/* cppcheck-suppress funcArgNamesDifferent */ > +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 --BO+Bbg/q7mRwxp0f Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbFRSIACgkQzQJF27ox 2GcYmg/8CBB+OGTxboXZKA+Z4GZi1gH6Pk+S9cLhSOuBBdF2eJxeTtVUeI3aWN9O 1MRtWwAvd/D58BGU5CPmw1LAvj7TLIHu1CalwhbaAORYw8qa30mNrjbAxy44Rxsi znQ4MRU+v65hYkSzyWVVaSPAPHZckTCnOSb6cop7j+WN+TMK5MbkDS2WEzdbSFB8 RQgoMEkRV6No86pH4TL/Swnw6RXlAP60TRRQ/FvuylZYJkY5QH8P3AFB1SvWN1m6 9oSrPULGatBKtJQUbBtTxRsysVNPTX9nF3i6ec9bGPAQg0uNFVP19aJDU3wwxlgI 43Ftt8/fbtpOYQLddM33oOiEC3/5JP7Jbwe0UHXoHmUA2+Xph9yVfzx4XEH6S8iW Vo9kVlCu6/VpK+z7jsAnET/G/zIhfPXetTnssr+7cWNLSQjW28gLuI6mahCw55GL /528FSAiHH2hjFPUjOjF1uo6YPIMiwgVws3ThocbEsDKb3Izdo+tBrf3MN0xdJRG b1rQsnPw+Qz3JKLOX4vkEqlv5n/L9qWQBDknVKi01yarEBDDYY8ELGGUITGlb0nv tGZx7CkZ5up7OqVFwN45rzzo+pDyXAx3Kd6dV3otY/8kTx0xfOsDyWZ8SQl3VqSF c6zjLCSsq/5WS0W09FV6+rYNfd4ov/mPH9tZkaaS1QWR4ytPrFQ= =MW81 -----END PGP SIGNATURE----- --BO+Bbg/q7mRwxp0f--