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=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=OxAarA1u; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 99BE55A0279 for ; Wed, 04 Sep 2024 04:25:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725416717; bh=dAUfxA+BPuCy4P4kRtKosBGiEptYRQRM3dzoYxFBeaw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OxAarA1unzQoOz2E+2kdAmR8FxYrKMpgvXl27o17DETVNLlonxq0azPmT4gv+QAG+ FCqqjmEmioKHkZlvbeP5DWBuxTeDcNh9iviBn4Rrf2QekpCJRtgGXOTdt7/XbXWPmg NA+U1Yaa6CP1/KoNaOILfEr5Bjychxk9Xr+qOM2PDsKZ02LyyaclRq9Hf1VWcK+z8l eWNMQ92qIIz9fl0rtKLfVv0bL0GQ5vwrMVoZsI6sl5ifSOa9a+oftoiQ7KFxQgGVB5 ruqPyvuWGrrXFyIWOm2gcnTnfXf0mXlaRz0lbcedPpp1kMdwTc0Qg8UV1jGOtOBYYH lUeiWcbPLQACw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Wz5tj27Tkz4xDT; Wed, 4 Sep 2024 12:25:17 +1000 (AEST) Date: Wed, 4 Sep 2024 11:33:59 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 4/6] tap: Don't risk truncating frames on full buffer in tap_pasta_input() Message-ID: References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-5-david@gibson.dropbear.id.au> <20240903212546.144bae19@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="G5ReScZWCCkTzj/g" Content-Disposition: inline In-Reply-To: <20240903212546.144bae19@elisabeth> Message-ID-Hash: R73SS7YDJSVFYC75UGSENTPD42E2GO3D X-Message-ID-Hash: R73SS7YDJSVFYC75UGSENTPD42E2GO3D 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 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: --G5ReScZWCCkTzj/g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 03, 2024 at 09:25:46PM +0200, Stefano Brivio wrote: > On Tue, 3 Sep 2024 22:02:33 +1000 > David Gibson wrote: >=20 > > tap_pasta_input() keeps reading frames from the tap device until the > > buffer is full. However, this has an ugly edge case, when we get close > > to buffer full, we will provide just the remaining space as a read() > > buffer. If this is shorter than the next frame to read, the tap device > > will truncate the frame and discard the remainder. > >=20 > > Adjust the code to make sure we always have room for a maximum size fra= me. > >=20 > > Signed-off-by: David Gibson > > --- > > tap.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > >=20 > > diff --git a/tap.c b/tap.c > > index 71742748..2fbcef04 100644 > > --- a/tap.c > > +++ b/tap.c > > @@ -1076,8 +1076,8 @@ static void tap_pasta_input(struct ctx *c, const = struct timespec *now) > > =20 > > tap_flush_pools(); > > =20 > > - for (n =3D 0; n < (ssize_t)TAP_BUF_BYTES; n +=3D len) { > > - len =3D read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n); > > + for (n =3D 0; n < (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n +=3D len) { >=20 > Logically speaking, this should be TAP_BUF_BYTES - ETH_MAX_MTU + 1, I > guess, because if we have ETH_MAX_MTU bytes left, we can read another > frame. Only if we have strictly less than that we might truncate > one. Good point. I've changed the < to <=3D to correct. >=20 > In any case, not a strong preference, and perhaps this version is > actually more readable. >=20 > > + len =3D read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU); > > =20 > > if (len <=3D 0) { > > if (errno =3D=3D EINTR) { >=20 --=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 --G5ReScZWCCkTzj/g Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbXuQcACgkQzQJF27ox 2Gdlzg//aqlRo2QuqT+uGDUiAviqfzEP58EKRNA7SRHZMTMoGNOzD9e/+7C64qaq gtKOgysdmrEu4NRSaCG+Rrt2Xbzhg6aOmScE62Uzp9GcGHjDhJEQfKzYP3IQzCYF Kt4WNJuJI409ttJlPts/64s+Gz9Sz5sZQF08SQ1DcVzgyxYrzg8f1yUn6rPSzFYC YJUiDiHSvdtB7gzL1Va+87GA8UdHuW6sQxfJe/4wdVzqfyem//qemuXzLzOG4QZU JyE7EICBcZcqq9IsHKGOfb0gKAo2Gc94kt6vu/g9bOle63qz2ndEhoVqNa/OzHqT 3j6XMZEGNMFTQRykxVS97kbL8da/uFAAgYvZ4rddXb4DEygflwBwQZZWL6lBCj8a 38IdnpJFyqOAQJbDTn9dzyDmpP9geX5dPEPuxh6Kv+E11b2PVlOy6IE6mFMAiVx2 o193fYXr3dgSe9KLwMeDjgIzm3BajUBzTMxxMPT5huvWxKDTxVQauzCnu3vxK9+0 XMd9C3R0IkztmQ0y1vlhWd0s9qbETRjmLl6jjqWZS1cCC8n9NtyLO9Kg0xXPW01g Acu49absozkbK5v3SD8uVcux4CERRJWYsDgHuT9dz4Wiyw8RI08jsaUSERA2Kjre KKdIGfI1GWOKq7LNXKw1tnwsGtQ2/BB4Taa3p+ROT8oPYSoDfFo= =/WXz -----END PGP SIGNATURE----- --G5ReScZWCCkTzj/g--