From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 6BF995A0265 for ; Mon, 09 Nov 2026 23:13:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794262429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GbzWTATU4XhPJAkpjp9ApVTTGoEyaWv90pcYh3QR2yQ=; b=AL8gpFHsVRmQ05xc+VBEjuvoz3dNVZPosZl+XIeMUN0la7TQ+MICGjwVbpq6nwYFuXj96/ 92sVDoKTwEVk5JFz6s29g0qXGrHzKuwHaYrPVyQ0LdjZJVYR/hqX7bZ024G4uIwlHCwYxp +pW1L4dr3DEQXBMmGLdZEQyyfl5PNwU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-eRYC4lbRPqq2T3OnI0Loqg-1; Mon, 09 Nov 2026 17:13:46 -0500 X-MC-Unique: eRYC4lbRPqq2T3OnI0Loqg-1 X-Mimecast-MFC-AGG-ID: eRYC4lbRPqq2T3OnI0Loqg_1794262425 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1EE821955F21; Mon, 9 Nov 2026 22:13:45 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42520431; Mon, 9 Nov 2026 22:13:43 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH] tcp_vu: Fix assert/error-check order in tcp_vu_sock_recv() Date: Mon, 9 Nov 2026 17:13:42 -0500 Message-ID: <20261109221342.380271-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: I9mzS9ASwupx60b99K_HeJOBPcYj1Rb2VkYh1T7EozM_1794262425 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: L3ERKIENZYHWJ3XEIWYBMFKKOKZYKUN7 X-Message-ID-Hash: L3ERKIENZYHWJ3XEIWYBMFKKOKZYKUN7 X-MailFrom: jmaloy@redhat.com 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 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: iov_tail_clone() returns a ssize_t. However, the assert comparing it against (ARRAY_SIZE(iov_msg) - j), which yields size_t, comes before the negative-value check. Hence, when iov_tail_clone() fails and returns -1, the signed-to-unsigned promotion turns -1 into SIZE_MAX, and causes the assert to fire. We fix this by moving the error check before the assert, while casting the counter and the index inside the assert to size_t. Signed-off-by: Jon Maloy --- tcp_vu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcp_vu.c b/tcp_vu.c index 868a35b9..c052d8e2 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -291,9 +291,9 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, cnt = iov_tail_clone(&iov_msg[j], ARRAY_SIZE(iov_msg) - j, &data); - assert(cnt < ARRAY_SIZE(iov_msg) - j); if (cnt < 0) die("Missing entries in iov_msg"); + assert((size_t)cnt < ARRAY_SIZE(iov_msg) - (size_t)j); j += cnt; } -- 2.52.0