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=202508 header.b=HsSIYyfK; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id CE7D55A0279 for ; Wed, 10 Sep 2025 04:29:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1757471394; bh=GQWVZDdEEpmziPW/kv2WsfmIdL3PgYaB5lau6TWonwY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HsSIYyfK+iIK5TRHqe7EPSVlULjS3OvrbP4xxxQVDK94X9sTnHjUgtxt8TF99Mf0y Fzn2Vj0luAV28n5jFl/HQsEWvjX7GFaISgg+vXqCmPRiERYSDauiYdWL6K3VP3e6Us 4Ml1gKe08PCVxRpu5hdYfmN/5+hhgiPZNaNZb3jIE0fef4NGt6+U5b9hn3XlSnXoGF DRKSHuCIzbciFOeWtrIz0xzaBK5cBK/Cq2GwwKiZS4GynCtMNvfMYjcYDLQ4QAfQNa eXgzIb9By4JHNyiJsqfECYKusBiCHZgH0jYJ1xorsMvTWLb2PIAJKwHHHfSxgOan5l 7Gj/UgdhudlUg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cM4Qp4g7Wz4w9Y; Wed, 10 Sep 2025 12:29:54 +1000 (AEST) Date: Wed, 10 Sep 2025 12:21:24 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v4 6/8] tcp: Cast operands of sequence comparison macros to uint32_t before using them Message-ID: References: <20250909181655.2990223-1-sbrivio@redhat.com> <20250909181655.2990223-7-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="34zPGBe4tg2WoTsQ" Content-Disposition: inline In-Reply-To: <20250909181655.2990223-7-sbrivio@redhat.com> Message-ID-Hash: STNKUC3HAA7DTMQT3CASSL7B3JQ3KXTW X-Message-ID-Hash: STNKUC3HAA7DTMQT3CASSL7B3JQ3KXTW 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, Jon Maloy , Paul Holzinger 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: --34zPGBe4tg2WoTsQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 09, 2025 at 08:16:53PM +0200, Stefano Brivio wrote: > Otherwise, passing signed types causes automatic promotion of the > result of the subtractions as well, which is not what we want, as > these macros rely on unsigned 32-bit arithmetic. >=20 > The next patch introduces a ssize_t operand for SEQ_LE, illustrating > the issue. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson C macros and promotion rules strike again :/. Personally I'd probably switch to inline functions, but this is fine too. > --- > tcp_internal.h | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) >=20 > diff --git a/tcp_internal.h b/tcp_internal.h > index d0009f8..ce6fee2 100644 > --- a/tcp_internal.h > +++ b/tcp_internal.h > @@ -21,10 +21,14 @@ > sizeof(struct ipv6hdr), \ > sizeof(uint32_t)) > =20 > -#define SEQ_LE(a, b) ((b) - (a) < MAX_WINDOW) > -#define SEQ_LT(a, b) ((b) - (a) - 1 < MAX_WINDOW) > -#define SEQ_GE(a, b) ((a) - (b) < MAX_WINDOW) > -#define SEQ_GT(a, b) ((a) - (b) - 1 < MAX_WINDOW) > +#define SEQ_LE(a, b) \ > + ((uint32_t)(b) - (uint32_t)(a) < MAX_WINDOW) > +#define SEQ_LT(a, b) \ > + ((uint32_t)(b) - (uint32_t)(a) - 1 < MAX_WINDOW) > +#define SEQ_GE(a, b) \ > + ((uint32_t)(a) - (uint32_t)(b) < MAX_WINDOW) > +#define SEQ_GT(a, b) \ > + ((uint32_t)(a) - (uint32_t)(b) - 1 < MAX_WINDOW) > =20 > #define FIN (1 << 0) > #define SYN (1 << 1) > --=20 > 2.43.0 >=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 --34zPGBe4tg2WoTsQ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjA4KMACgkQzQJF27ox 2GfMrA//Rauco1VEt+arHZvi7ScgJ3PEGsH5MmfQRqYq2vp8qDEbmyB8vYroiIDF O8pzRtsu330XWaQ7bmUXMyF0clr1bLCYVy64XtCus8niaVJZAsu10tb1B+Z8xWI3 83mRkNqzPFlNxwFcCnt+7teoc4O0og3kCTogbYvLiIa85CTSgca3gw+ydDCVadGL RY6/3Ni1OcxKtgMksuKijGeoudu59B0OrDh9ubQFR0uVP4yExUP7tY5LQT2Ue4Zt XsIJPXhAwxtZnaB4YU4OxE/bJcFhZfjdZyKhUg+r9X5FDW7CpFQfp9F+YfSRC06l KKRO3eQxh4Ha2x8WpHlvJEh5Wh9ngXSRGhodVoWKl5i7pTVnDh8UcTlRBwC8l1e8 oZH6L3fx8UEA/jLKUEkU+5xLg3x5oSpbX24uBwcM0YcYfOYTCklumgFQH9+l3rzY LdkCBHutDQOLTIvlWa0yVUEBLKWfVOnTmkL4y5i2waEIm/lNm1C0sU2S1snA6EIb iG6W2QKKsZnIFV2UreGKU6KA2g6K9oFycI9syo0Mn9EsuTEwE6lS72clilEMjZ5V j2eFUT1PcVI/ElMHkqXE7gExhaKJdx/5j+bDRO27QPOXZVhgC5Ygr8BbEhHUISMJ mbxtSC1SsIya1AJAts5grI5uiMbxe/jchW9iQIUEzhfdXeXaTBg= =I5sj -----END PGP SIGNATURE----- --34zPGBe4tg2WoTsQ--