From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D85A35A0262 for ; Wed, 8 Mar 2023 23:45:12 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PX6pF62CRz4xDt; Thu, 9 Mar 2023 09:45:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1678315509; bh=zBtm51OmJiofxdiN+3leU10p0RltHh51+p6bDMfb5Rg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JMwYnHZyxLNU0AZzjqWh7Slw7//1e2Erk9FcUhGu6a5/Fd7SHJgNTrvUaXWjdEzPM 3k+h3X4QvoukCv8hyM5mSQjRwnNr0LG6t21r8kvr23qzaNH81Mb39s4Ge/T/1BlLI3 WzALWQrRguEkmK9X+Tt0UaBjQU38WTuntEFmtESU= Date: Thu, 9 Mar 2023 09:06:50 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/4] netlink: Use 8 KiB * netlink message header size as response buffer Message-ID: References: <20230308073516.2189680-1-sbrivio@redhat.com> <20230308073516.2189680-2-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="i6M5+/9tmoEpIhlB" Content-Disposition: inline In-Reply-To: <20230308073516.2189680-2-sbrivio@redhat.com> Message-ID-Hash: NEQ77AFVO2GHRFE3GOYXMC554Y2KOKDJ X-Message-ID-Hash: NEQ77AFVO2GHRFE3GOYXMC554Y2KOKDJ 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, Chris Kuhn , lemmi 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: --i6M5+/9tmoEpIhlB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 08, 2023 at 08:35:13AM +0100, Stefano Brivio wrote: > ...instead of BUFSIZ. On musl, BUFSIZ is 1024, so we'll typically > truncate the response to the request we send in nl_link(). It's > usually 8192 or more with glibc. >=20 > There doesn't seem to be any macro defining the rtnetlink maximum > message size, and iproute2 just hardcodes 1024 * 1024 for the receive > buffer, but the example in netlink(7) makes somewhat sense, looking > at the kernel implementation. >=20 > It's not very clean, but we're very unlikely to hit that limit, > and if we do, we'll find out painlessly, because NLA_OK() will tell > us right away. >=20 > Reported-by: Chris Kuhn > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson I think controlling buffer sizes ourselves explicitly makes more sense, even if it weren't for the musl issues. > --- > netlink.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) >=20 > diff --git a/netlink.c b/netlink.c > index 8f785ca..0e0be4f 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -34,6 +34,8 @@ > #include "log.h" > #include "netlink.h" > =20 > +#define NLBUFSIZ (8192 * sizeof(struct nlmsghdr)) /* See netlink(7) */ > + > /* Socket in init, in target namespace, sequence (just needs to be monot= onic) */ > static int nl_sock =3D -1; > static int nl_sock_ns =3D -1; > @@ -105,7 +107,7 @@ fail: > static int nl_req(int ns, char *buf, const void *req, ssize_t len) > { > int s =3D ns ? nl_sock_ns : nl_sock, done =3D 0; > - char flush[BUFSIZ]; > + char flush[NLBUFSIZ]; > ssize_t n; > =20 > while (!done && (n =3D recv(s, flush, sizeof(flush), MSG_DONTWAIT)) > 0= ) { > @@ -121,7 +123,8 @@ static int nl_req(int ns, char *buf, const void *req,= ssize_t len) > } > } > =20 > - if ((send(s, req, len, 0) < len) || (len =3D recv(s, buf, BUFSIZ, 0)) <= 0) > + if ((send(s, req, len, 0) < len) || > + (len =3D recv(s, buf, NLBUFSIZ, 0)) < 0) > return -errno; > =20 > return len; > @@ -149,7 +152,7 @@ unsigned int nl_get_ext_if(sa_family_t af) > }; > struct nlmsghdr *nh; > struct rtattr *rta; > - char buf[BUFSIZ]; > + char buf[NLBUFSIZ]; > ssize_t n; > size_t na; > =20 > @@ -227,7 +230,7 @@ void nl_route(int ns, unsigned int ifi, sa_family_t a= f, void *gw) > struct nlmsghdr *nh; > struct rtattr *rta; > struct rtmsg *rtm; > - char buf[BUFSIZ]; > + char buf[NLBUFSIZ]; > ssize_t n; > size_t na; > =20 > @@ -336,7 +339,7 @@ void nl_addr(int ns, unsigned int ifi, sa_family_t af, > struct ifaddrmsg *ifa; > struct nlmsghdr *nh; > struct rtattr *rta; > - char buf[BUFSIZ]; > + char buf[NLBUFSIZ]; > ssize_t n; > size_t na; > =20 > @@ -446,7 +449,7 @@ void nl_link(int ns, unsigned int ifi, void *mac, int= up, int mtu) > struct ifinfomsg *ifm; > struct nlmsghdr *nh; > struct rtattr *rta; > - char buf[BUFSIZ]; > + char buf[NLBUFSIZ]; > ssize_t n; > size_t na; > =20 --=20 David Gibson | 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 --i6M5+/9tmoEpIhlB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmQJBvMACgkQzQJF27ox 2Gdhog/+KfyW2C0OptmSQ8zmFCJBns/vnUNlyCU2Q3D6e6OELhl0hxQhXchf89dg qXs2sQZa0s4trZ+/UCeE6Htl5AhyW3eoSmJFGlh37uqRo3JbhrTrNgLDf0KQBhw7 0v68/wncFYkF/l6PutqwyUDVeRJSC5YjVoa6wM6H85bskWF4wCzZWQW6V20cc7Xd N5joVAmWnWUALSoWd+s3Dzbn7I50Xz2PRGGj8rWgLVVdTFta4EsUdZl+pHWPpFuQ 1cWc0N/tMXDhuNDcoC3G+QeXGFgsGVeTsvXTjPVnyY+1KZJfTmfkn0A4XCRcN/a0 rxTpGZPQnPuvawtmgXKIRWC0/JTyFvI4NxUJJeYG29h/wxFQBhivLQxhaAVG8D/1 kqoJPBLqR0aFdruAx4tbzY92QFqy2vxwVVvZ8WGKpxmMpLY5kI1fJU7X1EzOIUVa JfeGtvNscChEr74KWjAYvyGaooqcxovRdoUGAxWAbgl41GWybWxx9fi8KgmMbj7g BmJ6+3qhY6TVU0pYJZ8b+k7asBaoIwYm3QtBWks/l2AMz6oY2UbXRfhhbNXQpPmh tMnv/GdgON9oaGxojGmubQwYOzeQZ8Tp0lESiIiuEilA8I3eG+rdQRMog76Dn+Pl n7VsX73aprMFrzoWC4TTUOyczB/riXyWg4IZbD2z+ZNwSjzDogI= =TDdu -----END PGP SIGNATURE----- --i6M5+/9tmoEpIhlB--