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=D2ru6vyy;
	dkim-atps=neutral
Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])
	by passt.top (Postfix) with ESMTPS id 4164B5A004C
	for <passt-dev@passt.top>; Fri, 20 Sep 2024 03:00:33 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=gibson.dropbear.id.au; s=202408; t=1726794016;
	bh=xQVqrWpU508EUQmu4rB9o2OTKzr8A6whtrxA2TIFf28=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
	b=D2ru6vyy32H1OzdnzOmq2WP2aSON//xq+UvkaBlm9Pb9/09yMGmodvHbFVBHmTS0M
	 lEKNTZ9qGkSEsUk1iC797QFMUTmCaJSpGWvI0/mmnqyuZnyrIpp909I+0Gj3QtBzXo
	 nNGxWNAjSKdyotwiEdGFhQ2jA0OXqPZdAlmjfYnS4HtUEew8GBjec9zcD86O7pLUdL
	 LcOMWLPxPX3nSat0DgyozLJFFkEVoNvKJsE94v0vWd4Si2bICjk/OiZDIci7nYdn75
	 /nrnt4AFe52w55TinkImRleV1BcpTrl6SDVYYhWW2GumKVYXe924yN/J8KunVL/0IK
	 I73yNvkc6d7sA==
Received: by gandalf.ozlabs.org (Postfix, from userid 1007)
	id 4X8vFD4Jjmz4xQf; Fri, 20 Sep 2024 11:00:16 +1000 (AEST)
Date: Fri, 20 Sep 2024 01:36:16 +1000
From: David Gibson <david@gibson.dropbear.id.au>
To: Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v3 2/2] util: Remove possible quadratic behaviour from
 write_remainder()
Message-ID: <ZuxE8NNp61jREyNx@zatzit.fritz.box>
References: <20240918104406.3050878-1-david@gibson.dropbear.id.au>
 <20240918104406.3050878-3-david@gibson.dropbear.id.au>
 <87plozsz4d.fsf@pond.sub.org>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="dPpPaC59coRM+/nv"
Content-Disposition: inline
In-Reply-To: <87plozsz4d.fsf@pond.sub.org>
Message-ID-Hash: CUHEMCRYLQDJSA5JKM3LZFZFUDL4BUQS
X-Message-ID-Hash: CUHEMCRYLQDJSA5JKM3LZFZFUDL4BUQS
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, Stefano Brivio <sbrivio@redhat.com>
X-Mailman-Version: 3.3.8
Precedence: list
List-Id: Development discussion and patches for passt <passt-dev.passt.top>
Archived-At: <https://archives.passt.top/passt-dev/ZuxE8NNp61jREyNx@zatzit.fritz.box/>
Archived-At: <https://passt.top/hyperkitty/list/passt-dev@passt.top/message/CUHEMCRYLQDJSA5JKM3LZFZFUDL4BUQS/>
List-Archive: <https://archives.passt.top/passt-dev/>
List-Archive: <https://passt.top/hyperkitty/list/passt-dev@passt.top/>
List-Help: <mailto:passt-dev-request@passt.top?subject=help>
List-Owner: <mailto:passt-dev-owner@passt.top>
List-Post: <mailto:passt-dev@passt.top>
List-Subscribe: <mailto:passt-dev-join@passt.top>
List-Unsubscribe: <mailto:passt-dev-leave@passt.top>


--dPpPaC59coRM+/nv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Sep 19, 2024 at 12:42:58PM +0200, Markus Armbruster wrote:
> David Gibson <david@gibson.dropbear.id.au> writes:
>=20
> > write_remainder() steps through the buffers in an IO vector writing out
> > everything past a certain byte offset.  However, on each iteration it
> > rescans the buffer from the beginning to find out where we're up to.  W=
ith
> > an unfortunate set of write sizes this could lead to quadratic behaviou=
r.
> >
> > In an even less likely set of circumstances (total vector length > maxi=
mum
> > size_t) the 'skip' variable could overflow.  This is one factor in a
> > longstanding Coverity error we've seen (although I still can't figure o=
ut
> > the remainder of its complaint).
> >
> > Rework write_remainder() to always work out our new position in the vec=
tor
> > relative to our old/current position, rather than starting from the
> > beginning each time.  As a bonus this seems to fix the Coverity error.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  util.c | 27 +++++++++++++++++----------
> >  1 file changed, 17 insertions(+), 10 deletions(-)
> >
> > diff --git a/util.c b/util.c
> > index 7db7c2e7..87309c51 100644
> > --- a/util.c
> > +++ b/util.c
> > @@ -597,10 +597,15 @@ int write_all_buf(int fd, const void *buf, size_t=
 len)
> >  	size_t left =3D len;
> > =20
> >  	while (left) {
> > -		ssize_t rc =3D write(fd, p, left);
> > +		ssize_t rc;
> > +
> > +		do
> > +			rc =3D write(fd, p, left);
> > +		while ((rc < 0) && errno =3D=3D EINTR);
> > =20
> >  		if (rc < 0)
> >  			return -1;
> > +
> >  		p +=3D rc;
> >  		left -=3D rc;
> >  	}
>=20
> Uh, shouldn't this be squashed into PATCH 1?

Bother, yes it should.  But, it's merged now, so never mind, I guess.

--=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

--dPpPaC59coRM+/nv
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbsROEACgkQzQJF27ox
2GeHBhAAk7elnq1ImP7gGDxI7GuRDjOZy5klEBQWE6Gct5rc1jY0vVTliCNFyU0V
QLnkr0chRzkKgV9C1aSc9wd3WmxrdU3DtS26QUhSpdYpNxbxdmFWtsjPSQC/wdqH
uVCvhz4ApLtq3fsGKcWrFq8ySp4fag9rFh6IxgtZgbG3XfSz5JNZ1K/GlOi+29pP
ZgZfABD7a+jSvq+FHA1jIg4ZHDlOwykwpwM08Vhd9nG3e5pi9gg5szM6eXpeGT84
a1pStoJ8mReGDvJ2oZNQh5Uwp7jM6IxeFm+rI3bvnSfSjbCDgqagBiV1Al1D+OAD
xsKx+M9s3Bt3SSNRvIrxxcDQ87/2Z9kRsO7kRbUFGygRcJRKpKAj9OTA+kJ7UC3K
0FDRDLs3IQudqZ6QJYbAk6e/ST/E7w6vxQvPXIgC9wziC8Mo6B4pyIW2cNgvKeDO
uE0D9YHg2HH0MVnO6chUox2cFOgcmpvnFqVITZdHFxTv2KTHE1NHse+S+yA762p1
6twnKcH1J0u5VazC/EoNP5r3zQiYqZFZEsm/91o5PaYwD9NdgIT459sh9q1i/Sp2
ETc8fM4ADhNGjoUolignbEcfPzwoLhceeaPXK37rPnbEhFAay6+EQNmxpSCUbhxb
+EhLRA1lL/dPNGfkuewBMu1YDExoeW071EIJ4G+pcKXxuSbxIbA=
=e3Zt
-----END PGP SIGNATURE-----

--dPpPaC59coRM+/nv--