From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B1EYiYhq; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id A9D9A5A026E for ; Mon, 23 Feb 2026 15:10:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771855835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U0aeEadkE+gFOL4QnaAlQAKmkr9XWp/V0uBNxtWhQ5w=; b=B1EYiYhqYjnSMkmCuijOsNXky54KSL1TmXkFAnEGg06rE59BoJez+nMq1+8G2AOY35aZsX m9rNrrliBLurvNcZmuuTu8B5j7wjO0KKYXzDlQfsVZH+NRQcOjIoB6P7ugXAMRMh5ayIWc 1xPrUdjSMzBzBZIZ8cgGb/Is6yAQ4f4= Received: from mx-prod-mc-03.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-500-2btujtOvOiSh4YCyNk2w4A-1; Mon, 23 Feb 2026 09:10:32 -0500 X-MC-Unique: 2btujtOvOiSh4YCyNk2w4A-1 X-Mimecast-MFC-AGG-ID: 2btujtOvOiSh4YCyNk2w4A_1771855832 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB03C195607C for ; Mon, 23 Feb 2026 14:10:31 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.34.158]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 017CF30001BE; Mon, 23 Feb 2026 14:10:30 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 1/2] tcp_vu: vu_pad() expects l2 length Date: Mon, 23 Feb 2026 15:10:26 +0100 Message-ID: <20260223141027.2205762-2-lvivier@redhat.com> In-Reply-To: <20260223141027.2205762-1-lvivier@redhat.com> References: <20260223141027.2205762-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fFZCycpoep2rkJUVJy7BoJx4wstnLVcOnjArgFD0UsM_1771855832 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: REH4GFLELKULILTBMFH3Z756THP256VN X-Message-ID-Hash: REH4GFLELKULILTBMFH3Z756THP256VN X-MailFrom: lvivier@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 CC: Laurent Vivier 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: tcp_vu_hdrlen() returns a length that includes VNET_HLEN (the virtio net header), but vu_pad() expects the Layer-2 frame length, which should not include the virtio header. Passing the inflated length means short frames aren't padded to the minimum 60-byte Ethernet frame size (ETH_ZLEN). Subtract VNET_HLEN from hdrlen when computing the l2 length passed to vu_pad() in both tcp_vu_send_flag() and tcp_vu_data_from_sock(). Fixes: 0cb8f9003654 ("tcp, udp: Pad batched frames for vhost-user modes to 60 bytes (802.3 minimum)") Signed-off-by: Laurent Vivier --- tcp_vu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index 3847a4e92087..2c9ddba0c9a4 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -71,8 +71,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) { struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; - size_t optlen, hdrlen; struct vu_virtq_element flags_elem[2]; + size_t optlen, hdrlen, l2len; struct ipv6hdr *ip6h = NULL; struct iphdr *ip4h = NULL; struct iovec flags_iov[2]; @@ -137,7 +137,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, NULL, seq, !*c->pcap); - vu_pad(&flags_elem[0].in_sg[0], hdrlen + optlen); + l2len = optlen + hdrlen - VNET_HLEN; + vu_pad(&flags_elem[0].in_sg[0], l2len); if (*c->pcap) pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN); @@ -446,6 +447,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) int buf_cnt = head[i + 1] - head[i]; ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen; bool push = i == head_cnt - 1; + size_t l2len; vu_set_vnethdr(vdev, iov->iov_base, buf_cnt); @@ -457,7 +459,8 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push); /* Pad first/single buffer only, it's at least ETH_ZLEN long */ - vu_pad(iov, dlen + hdrlen); + l2len = dlen + hdrlen - VNET_HLEN; + vu_pad(iov, l2len); if (*c->pcap) pcap_iov(iov, buf_cnt, VNET_HLEN); -- 2.53.0