🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20411

Re: [PATCH net v2] tap: clamp zero-copy copylen to remaining payload length

#20411
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 12:10
175 lines
14278 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] Incomplete fix: tun.c has the same stale-heap leak and the patch
  leaves it alone.
- [Low] The commit message understates the impact.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the `if
  (!tap)` branch of tap_get_user() (drivers/net/tap.c:646-650) leaks the…

--

tap: clamp zero-copy copylen to remaining payload length

This patch clamps the zero-copy copylen in tap_get_user() to the payload
left after the virtio header. Without the clamp, tap_alloc_skb() sizes the
linear area from hdr_len or GOODCOPY_LEN. zerocopy_sg_from_iter() only
fills the payload bytes that exist, so stale heap contents can be
transmitted.

> For example, a 246-byte padded virtio header and a 14-byte Ethernet
> frame leave only 14 payload bytes, but a zero hdr_len makes copylen 128.
> With a 512-byte virtio header, a guest-supplied hdr_len of 256 also
> passes __tun_vnet_hdr_get(): it checks hdr_len before skipping the
> padding. That makes copylen 256 for the same 14-byte frame.
> Larger padded headers can raise copylen as far as good_linear.

[Severity: Low]
Does this description understate the exposure? Both examples use padded
vnet headers set up by the host. That reads as if an unusual vnet_hdr_sz
is needed.

tap_get_user() calls tun_vnet_hdr_get() with features=0, so parsed_size is
sizeof(struct virtio_net_hdr), which is 10. __tun_vnet_hdr_get() then does:

drivers/net/tun_vnet.h:__tun_vnet_hdr_get() {
    ...
	if (hdr_len > iov_iter_count(from))
		return -EINVAL;

	iov_iter_advance(from, sz - parsed_size);
    ...
}

At that check, the count still includes the sz - 10 padding bytes. With the
common 12-byte header (VERSION_1 / MRG_RXBUF), a guest can set
hdr_len = payload + 2. Before this patch that made copylen = payload + 2,
so 2 uninitialized bytes went out with each packet. With the 20-byte hash
header the overshoot is 10 bytes.

The new min_t() already handles these cases, so the code is fine. Could the
commit message say that the default header sizes are affected too? Stable
and security triage will rely on it.

> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> index 2f19fb07bb2d4..f25c58d6e986b 100644
> --- a/drivers/net/tap.c
> +++ b/drivers/net/tap.c
> @@ -608,6 +608,8 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
>  		struct iov_iter i;
>  
>  		copylen = clamp(hdr_len ?: GOODCOPY_LEN, ETH_HLEN, good_linear);
> +		/* The remaining payload may be shorter than copylen. */
> +		copylen = min_t(unsigned long, copylen, len);

[Severity: High]
Does tun_get_user() in drivers/net/tun.c need the same clamp? Its
zero-copy branch computes copylen the same way, and nothing bounds it by
len:

drivers/net/tun.c:tun_get_user() {
    ...
	if (msg_control) {
		struct iov_iter i = *from;
        ...
		copylen = min(hdr_len ? hdr_len : GOODCOPY_LEN, good_linear);
		linear = copylen;
		iov_iter_advance(&i, copylen);
		if (iov_iter_npages(&i, INT_MAX) <= MAX_SKB_FRAGS)
			zerocopy = true;
	}
    ...
}

When zerocopy is set, tun_can_build_skb() returns false and copylen is not
reset to len. From there the path matches tap:

tun_get_user()
  tun_alloc_skb(tfile, align, copylen, linear, noblock)
    skb_put(skb, linear)
  zerocopy_sg_from_iter()
    copy = min_t(int, skb_headlen(skb), iov_iter_count(from))

Nothing writes the tail of the linear head, and it goes out through the
host stack and any bridged link.

tun_get_user() also calls __tun_vnet_hdr_get(), which the commit message
blames for case B. A tun device with IFF_VNET_HDR always has SOCK_ZEROCOPY
set. With experimental_zcopytx=1, vhost_net uses zero-copy for guest TX of
256 bytes or more. Either of these looks like it reaches the leak:

  vnet_hdr_sz >= 242, hdr_len = 0 and a short frame (copylen = 128)
  any vnet_hdr_sz > parsed_size, hdr_len = payload + (sz - parsed_size)

Would it make sense to fix this in __tun_vnet_hdr_get(), or in both
callers? Otherwise the tun path stays exposed after a stable backport of
this patch.

>  		linear = copylen;
>  		i = *from;
>  		iov_iter_advance(&i, copylen);

[Severity: High]
This isn't a bug introduced by this patch, but tap_get_user() returns early
further down when q->tap is NULL:

drivers/net/tap.c:tap_get_user() {
    ...
	rcu_read_lock();
	tap = rcu_dereference(q->tap);
	if (!tap) {
		kfree_skb(skb);
		rcu_read_unlock();
		return total_len;
	}
    ...
}

This return comes before skb_zcopy_init(skb, msg_control) and before
uarg->ops->complete(). Can this leak the vhost zerocopy ubuf_info?

By this point, handle_tx_zerocopy() in drivers/vhost/net.c has already
marked the head as in progress and taken a reference on ubufs:

	vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS;
	...
	atomic_inc(&ubufs->refcount);

Because sendmsg returned success, vhost waits for vhost_zerocopy_complete()
to finish the job, and that callback never runs. The heads[] slot stays
VHOST_DMA_IN_PROGRESS, which blocks vhost_zerocopy_signal_used(). The
ubufs refcount never reaches zero.

Later, vhost_net_flush() (from release, set_backend or reset_owner) waits
with no timeout:

drivers/vhost/net.c:vhost_net_ubuf_put_and_wait() {
	vhost_net_ubuf_put(ubufs);
	wait_event(ubufs->wait, !atomic_read(&ubufs->refcount));
}

q->tap becomes NULL in tap_del_queues() when the macvtap/ipvtap link is
deleted while the queue fd is still attached to vhost-net:

	RCU_INIT_POINTER(q->tap, NULL);

>From then on, every zero-copy guest TX takes this path. The process
releasing /dev/vhost-net can then hang in D state. tun does not have this
problem because tun_sendmsg() returns -EBADFD once the device is gone.

This looks like it dates back to commit 4f61f133f354 ("net: tap: NULL
pointer derefence in dev_parse_header_protocol when skb->dev is null").

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118120102.3717000-1-graypanda.inzag%40gmail.com
Technical Details
Message-ID: <179534945117.3135.10312990191242874707@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368677-linux-kernel-netdev=dewy.ru
References: <20261118120102.3717000-1-graypanda.inzag@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368677-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tap: clamp zero-copy copylen to remaining payload length
Date: Sun, 22 Nov 2026 12:10:51 +0000
Organization: Usenet Network
Message-ID: <179534945117.3135.10312990191242874707@kernel.org>
References: <20261118120102.3717000-1-graypanda.inzag@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3629663"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zqIc9vokuiP647/g4FRPbvdFnS0= sha256:OF2Za4CJqKEwyo5Svixcdc3nh4zbrIT8jzFbJkdQosc=
	sha1:QD/UWrphgOq0adLoDM7zorET9oU= sha256:ETA6Kz0nLqlOoXNmYkh/Mzl/b287q6nQ+bDIu3HM8H0=
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 9C612125D73; Sun, 22 Nov 2026 15:11:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 QNdlp4dG2na4;
	Sun, 22 Nov 2026 15:11:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368677-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CCB6D125D6E; Sun, 22 Nov 2026 15:11:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id D4F1C2B731; Sun, 22 Nov 2026 12:10:58 +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=1795349458;
	b=3UnrxWbZMi+fUvFeiehM/98vIKcjKN4sj1dAXFufuENMjwEoi01b5wojHDQQIiAXPGNs
	 zZtQpn/z9w35az7tjcXLL4otkxHTmTnZ33uD2ha8KNzXZw3ttLi+YayZaSpK1nzj2Rx2h
	 lK/IxEUP92Or5Q7Jkz9EJjTP5M0htVV+lVws35Z+ZGIKPW4YslwgUIFfprVo2g7uUhTYW
	 AmKG4Ksn95wq5jVoL18NaWamAcXkY0qybmW224njDqHrY5y1kocat2B4Fskj4R6fU1JYZ
	 pkgXAP7WoAvngQea8+948izosNkIWiHawQdd/nJSNEch+NxNZWxIisTLvvyG/Ipc0eQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795349458;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=LWOiQEZX415zH0dHnkJ/TmM4Hrd10FxwQy/FS8wvlWk=;
	b=LQWW1F2cvluMffOCmW+3GhcVpiW+k8pW3WCnQFhen3iJBvuFsrqs7Ujc+tSi43z/UrjP
	 UZ3J4wuikT19iX+d6lId9DiaiQF5l+mh0DPl0Ld/jQ7aXatYSMxZY5lO9sjpmK/ULC9lF
	 cVsjYdR18ZQ9/bcY98K+xvJHBzncVaOnstilK7VO2NOkp0/oH/tRuu5MlU9h+e10giUz9
	 9Df3HKz76tcWLHHBg75cLOG9YOgzRJFMISBTrqmkoIJc7eNyK2h2K9AnWxvBrhjLQDFdv
	 sz7MTc4TRrmjA9+OmCyChuWDBCSxayNC+BYJA0HdCkJ6FWSAcRiyfRK8pV/wFo7wE7Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIQB1ODh;
	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 86DB7606A320;
	Sun, 22 Nov 2026 12:10:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIQB1ODh
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795349452;
	b=YekKSTnpIftAj3O4GZxetA2AetxnDqHzSkTP9AmDThGBbT+BABieX1DCTCn0LsbLUU2j
	 5xGKLJvmYcEWZUJFNleKVi8k5uAi4o34/fJzm9MbMxQowW3iNh9wRzQ1obN7LX9HWKDPe
	 ZeAtv94csqRpE7Dg59U1Y8EH7sG1nP5gRNRvy3XLMf68XYdO2FFIXSJ336oMTdrx8ijxV
	 fY74nKfmK1WKayuI3pN4BGjgJa/N/RtcTDo4Pd5BgPFYzoA7V/6CSYZGaKFFVsUi8R50k
	 x5D9+pw3AZj7z6Xp/stdjd6eFp4eOTNX1qeEtPHKQOPVE983ozXdppacIOf0+qWtkug==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795349452;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=LWOiQEZX415zH0dHnkJ/TmM4Hrd10FxwQy/FS8wvlWk=;
	b=s8wcP+U0smT6Bxg3pbCOMwlIxvihTo638JzrIhrZhqUlREZvsoVhETKxaxP8yX/CGAe3
	 UQl3gDQ4ZQCb3PL4TCqL/Gtys8t18trXLMYU/Xpc2PqLil27BM9t8z/peTTl0jxzobjZ+
	 8B5OBMLScBXBcH4sDI5jk0Xdqdw24o/CWi5v/lNwYiz+PDMep79KrQWlsIhh3c1cgFh34
	 j4ibH6H1TBJB4KE0uyzPhAqWotSNeuBO245SYtUG5baPpTQlywUo7e5r/6u7Yj1yfyJIw
	 sD0TmfyJWucFZGR1fmwSDFD5y8MK9AL01dgnLkn7l3KqfAPwqyTakFU1k/i5FAxIgjw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIQB1ODh;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4357606A32A;
	Sun, 22 Nov 2026 12:10:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A20891F000C6;
	Sun, 22 Nov 2026 12:10:51 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795349452;
	bh=LWOiQEZX415zH0dHnkJ/TmM4Hrd10FxwQy/FS8wvlWk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=WIQB1ODhD18O8TJIptE3MxXKgdiO9iLC7MPn8Cz0UwPviqgx/OsymDtOulqwccEaE
	 Dy/jhHne5LWPMnCtULBWKq+SOu1tAe2VOaJ/Tbx16VLjCF/A/vlHnR50shdnLkYsHs
	 tK38V8jTO3Z2EuzkncCxXStmoVKGmL7xp/xyViXCY1+z+LBzmMkER0B093/zVUHVfs
	 1GKMcS1/rwzJpBeATYkM1LBMdGLBLGhIYEQG8g+uWu/edsTz3FXJxvAFo/DD/cX0zC
	 n+9I6HWuHqwv+4OU6pqZ7u6amY3+G9m5PA+dwVfMA8XBtWSlEK5sDGHlUvBW7gE7jR
	 sNJxyv+Dju9iQ==
X-Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, gwanhyunlee@gmail.com,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261118120102.3717000-1-graypanda.inzag@gmail.com>
X-sashiko-severity: High
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