🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12002

[PATCH net v2 2/3] vsock/virtio: bound the send credit by bytes not yet consumed by the transport

#12002
From: Oleg Drokin
Date: Fri, 06 Nov 2026 05:02
78 lines
11737 bytes
The send credit is

    min(peer_buf_alloc, buf_alloc) - (tx_cnt - peer_fwd_cnt)

where peer_fwd_cnt is taken unchecked from every header the peer sends.
A peer that never consumes what it is sent but keeps reporting
fwd_cnt == tx_cnt gets unlimited credit: every send() is accepted and
the skbs pile up in the transport's queue (on a host, vhost's
send_pkt_queue, for a guest that posts no rx buffers). The skbs are
GFP_KERNEL allocations charged to no memory cgroup. The peer learns
tx_cnt easily when the host side relays a stream it also controls.

Commit 8ee784fdf006 ("vsock/virtio: cap TX credit to local buffer size")
bounded peer_buf_alloc, but not peer_fwd_cnt.

bytes_unsent (maintained for SIOCOUTQ) counts what was handed to the
transport and not yet consumed by the device. It is local knowledge, so
bounding it by the same window limits a lying peer to one window of
queued data per socket.

For an honest peer, bytes_unsent can exceed tx_cnt - peer_fwd_cnt only
by data the peer already has but the transport has not yet released:

 - on a host, the delivered part of an skb that vhost splits across rx
   buffers smaller than the skb: the peer acknowledges the pieces, but
   bytes_unsent drops only once the whole skb is delivered, so at most
   one skb (64 KiB);
 - in a guest, tx buffers the host has consumed but
   virtio_transport_tx_work() has not reaped yet: vhost passes the
   packet to the host socket before it marks the buffer used, so the
   host's credit update can arrive first.

Either way the window shrinks only until the transport catches up;
nothing stalls and nothing changes on the wire. The writer is woken by
sock_wfree() once enough of the queued skbs are freed, as it already is
when credit comes back.

With a user-space vhost-vsock "guest" that posts no rx buffers and
acknowledges everything, one host socket queued 256 MiB in under 2 s
(SIOCOUTQ 268304384, where the test stops); with this patch it stays at
one window (SIOCOUTQ 262144).

Found by an LLM-assisted security review of vhost-vsock, done while
porting a project from Xen to KVM, and reproduced as above.

Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
 net/vmw_vsock/virtio_transport_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a480df4..74a8fdf825d5 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1031,14 +1031,17 @@ EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_has_data);
 
 static s64 virtio_transport_has_space(struct virtio_vsock_sock *vvs)
 {
+	s64 tx_buf_size = virtio_transport_tx_buf_size(vvs);
 	s64 bytes;
 
 	/* Use s64 arithmetic so if the peer shrinks peer_buf_alloc while
 	 * we have bytes in flight (tx_cnt - peer_fwd_cnt), the subtraction
 	 * does not underflow.
 	 */
-	bytes = (s64)virtio_transport_tx_buf_size(vvs) -
-		(vvs->tx_cnt - vvs->peer_fwd_cnt);
+	bytes = tx_buf_size - (vvs->tx_cnt - vvs->peer_fwd_cnt);
+
+	/* peer_fwd_cnt is peer-controlled, bytes_unsent is not. */
+	bytes = min_t(s64, bytes, tx_buf_size - (s64)vvs->bytes_unsent);
 	if (bytes < 0)
 		bytes = 0;
 
-- 
2.56.0
Technical Details
Message-ID: <20261106050244.602625-3-green@linuxhacker.ru>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357752-linux-kernel-netdev=dewy.ru
References: <20261106050244.602625-1-green@linuxhacker.ru>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357752-linux-kernel-netdev=dewy.ru
From: green@linuxhacker.ru (Oleg Drokin)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 2/3] vsock/virtio: bound the send credit by bytes not yet consumed by the transport
Date: Fri,  6 Nov 2026 00:02:43 -0500
Organization: Usenet Network
Message-ID: <20261106050244.602625-3-green@linuxhacker.ru>
References: <20261106050244.602625-1-green@linuxhacker.ru>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3797656"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0zwmVaF2i704mX9YvEB51iV1V/s= sha256:BI3+Y//8aNUBBq4GPYEHkKdds3iIGSqSeVIWzShUS5w=
	sha1:APZGMT3SiXBvnFFKRDmHivhWGF8= sha256:DdwmxnXAUCeU717tmCi98dnuGW8MaY65PieJk2X3nZQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9240B113165; Fri,  6 Nov 2026 08:03:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=linuxhacker.ru
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id NRsJzBkeyvur;
	Fri,  6 Nov 2026 08:03:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-357752-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linuxhacker.ru
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 8593E113161; Fri,  6 Nov 2026 08:03:35 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 3DE65603509; Fri,  6 Nov 2026 05:03:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793941391;
	b=O+TwTKKkmrComC6Pkw2BmBWw2u+G6rcc/rEUJvnusUlfgyIkBNJHcqS1LcGmHdLfydpn
	 gJDBoJZ0/nq/bZq1+OOXuAZJ4lyeCoRgH/ONLyQbdodyDvndjhRxI3KA9AoG1AxTkjGUT
	 PI7D6KTScirGAN/bB6WfIKwLLiOg0esCI2O2nGx9IwWrNt4Ewo/PwWaB8QBRlpJoXz/zy
	 K+svRtvVAZKIrsld0cCelGAFgS9teYJYbeWprf3akSQHNi7Z7vNtwBO2q3ZnVlCtNZr7b
	 w10f+pAyVk8eYBiN1TX+kQWb3KXPqaKKXQJ2qVmaYlqPRfXoXd+1/mPXztpGyM1LJIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793941391;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Filter:
	 DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=LmdTj8g581thkbq3W6hV05B622ecW9OswUVr0f7diMI=;
	b=YcsLtulj4eyIE285cfT2khnTxa2e4QkSqEuCLZppBNrf41VY8VG9zJvVoSezaH3DFKDh
	 g9eC60O7K9+JcOR5mavWveNVeJyYAn9V+iliYfHKi/XPrrLSlvtsNCt7wy3Hk/qCpSOd0
	 KvjecxyRoPYYlvRdCVjru650aKXneGovzTTJ/JP6BznwYBqWnKK0UJwepTKrO+hxXaPGd
	 I7LYklI6rRuCavjiIoiYY6SNpwAwldAJ+67zConJnHiyOq90Cuf9Ps71rK4IqGUc+Hbjj
	 gd5Kq7nBupWoH7FzLuJomZJKO1P2womI4p95qcJLlqqlQLzTrWb9PzA5MUAcVWIA1tA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linuxhacker.ru header.i=@linuxhacker.ru header.a=rsa-sha256 header.s=mail header.b=fPJnRPDk;
	dmarc=pass header.from=linuxhacker.ru;
	spf=pass smtp.mailfrom=linuxhacker.ru;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 191D6606D828;
	Fri,  6 Nov 2026 05:03:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=linuxhacker.ru header.i=@linuxhacker.ru header.a=rsa-sha256 header.s=mail header.b=fPJnRPDk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=159.69.87.85
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793941390;
	b=OOIiejOdbZ60UwzLIt8bs2hbg59tHk1cYVcKDMRcYyoFqqgR/sAORui24JRIdoAGBONm
	 OrjACpiN493c2iJjVSM3gpY5S8O2bEaffEjRNC97rgUeByS/n7w/S/MvhlZPvaCv5qmGf
	 lcSFmdVgaSPpBgCeDvTJyyF4IgpOAp9CpfkbTKbRnTPGhSI2DYoouniXkX3XnKcj4UePD
	 u4p5R2c+Eg9eUdpENOFXr5WAjaT2SjPsT4o16W6V7fJdu/X1tlw5WB2ruT4oRjkbWdJE+
	 jQ6yOY81s/upcJRpMesxxdr5goLrbJNLbgxIqA1BDc11zOLjTrtne5Uoc4lmThPRmlA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793941390;
	h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=LmdTj8g581thkbq3W6hV05B622ecW9OswUVr0f7diMI=;
	b=jzkwiyI/HkxlvRPS9PR7JwgvCwUPDvQqutWFEpAhM4pqcQ1fIoItYNr2wxzf+z4ZqnuY
	 q49xR74sMwN8U77xnBDLYy1pKdSHi1gQMy8lWHYFfEufe071Si+vdFV3j//gMUO8reAjw
	 SYsOy4KLegvVjMQBaoqaB7BC4yc22i3VI0fP/389y9VlAa3BXr5dJIZUQeQu64kgHc3e+
	 mFPI1aCRZQjQNAAvBy4lsVSQbLHbq+lXZ6H7vPfXfifwJWn9iBhxty6DKawOvjpseaJDS
	 XY+PE8rRikuWy/PKHlETKkPlho10xMe8YWZfuYVMmAAWbeWESWeGOoiWhGE2p4hQyTQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linuxhacker.ru;
	spf=pass smtp.mailfrom=linuxhacker.ru;
	dkim=pass header.d=linuxhacker.ru header.i=@linuxhacker.ru header.a=rsa-sha256 header.s=mail header.b=fPJnRPDk;
	arc=none smtp.remote-ip=159.69.87.85
X-Received: from eagle.linuxhacker.ru (linuxhacker.ru [159.69.87.85])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B56AD606A333;
	Fri,  6 Nov 2026 05:03:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B56AD606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxhacker.ru
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxhacker.ru
X-Received: from intelbox1.virtnet (unknown [162.81.204.199])
	by eagle.linuxhacker.ru (Postfix) with ESMTPSA id 965B2BEE69;
	Fri,  6 Nov 2026 05:03:06 +0000 (UTC)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 eagle.linuxhacker.ru 965B2BEE69
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxhacker.ru;
	s=mail; t=1793941388;
	bh=acMYEvEpV8jfvisnvb63rQCzMw51WKbSROFjMmVDins=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=fPJnRPDk8sveS2rigxh9EIUBYzGo2kNg3EHZjvTkkqBhTj/k1tPNpeN0W9NXP6Uf3
	 cxgYkpQaftFUDsDNX5dC5Q2FUuT9pQ3JpV2eJ84PxRpGdT0gamegSsmmDbeJp4V9q8
	 sIRFCFe4C8QDP6EngQgbuq20hxYZqKdyzQZiT7WjImMAswaW/hasi7Bsv5tEWz/I40
	 nUFtA0Ks1RYTvkAOXhYqkCbwPU83n65/QiCmfttU4bCQZhO6Wt3EcZLBLgsIeZiPiQ
	 lD3RKjw2ctoYITpspevINK9CPuTfSCpmZlluejmVl40Bdd/h07zIk7QhP9RELlZDGB
	 2SsbVKPXEdCjA==
X-Cc: jasowangio@gmail.com,
	eperezma@redhat.com,
	xuanzhuo@linux.alibaba.com,
	bobbyeshleman@meta.com,
	davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	netdev@vger.kernel.org,
	virtualization@lists.linux.dev,
	kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261106050244.602625-1-green@linuxhacker.ru>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list