Article View: linux.kernel.netdev
Article #27413Re: [PATCH net v2] tun: reject iterators that are not user backed in NAPI frags mode
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 15:42
Date: Sat, 05 Dec 2026 15:42
174 lines
14180 bytes
14180 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 0 (1) ยท Medium: 1 ยท Low: 0
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).
- [Medium] tun: -EOPNOTSUPP in tun_napi_alloc_frags() triggers io_uring
EAGAIN retry loop
Pre-existing issues:
- [High] tun_napi_alloc_frags() can still build a malformed skb after
this patch.
--
tun: reject iterators that are not user backed in NAPI frags mode
This commit makes tun_napi_alloc_frags() reject iterators that are not
user backed, returning -EOPNOTSUPP. The reason is that the fragment loop
reads the iterator segments as struct iovec, and an io_uring fixed-buffer
write uses ITER_BVEC. Both early error paths now go through the free
label, so any skb cached in napi->skb is released.
Link: https://lore.kernel.org/netdev/willemdebruijn.kernel.3587ccd7685e2@gmail.com/
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index ae05b1e58abaa..f0e254a194c8a 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1502,9 +1502,16 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile,
> int err;
> int i;
>
> + if (unlikely(!user_backed_iter(it))) {
> + err = -EOPNOTSUPP;
> + goto free;
> + }
> +
> if (it->nr_segs > MAX_SKB_FRAGS + 1 ||
> - len > (ETH_MAX_MTU - NET_SKB_PAD - NET_IP_ALIGN))
> - return ERR_PTR(-EMSGSIZE);
> + len > (ETH_MAX_MTU - NET_SKB_PAD - NET_IP_ALIGN)) {
> + err = -EMSGSIZE;
> + goto free;
> + }
[Severity: Medium]
Can returning -EOPNOTSUPP here cause trouble for the io_uring path this
patch is aimed at?
tun_chr_open() sets FMODE_NOWAIT, so io_write() makes the first attempt
with IOCB_NOWAIT set. If ->write_iter() fails with -EOPNOTSUPP while
IOCB_NOWAIT is set, io_write() turns it into -EAGAIN:
io_uring/rw.c:io_write() {
...
if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
ret2 = -EAGAIN;
/* no retry on NONBLOCK nor RWF_NOWAIT */
if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT))
goto done;
...
}
For an IORING_OP_WRITE_FIXED or IORING_OP_WRITEV_FIXED write to an
IFF_NAPI_FRAGS queue, that leads to three different results.
With RWF_NOWAIT, userspace gets -EAGAIN. That looks like a temporary
condition, but the write can never succeed.
Without RWF_NOWAIT and with the device IFF_UP, the request goes to
io_arm_poll_handler(). tun_chr_poll() reports EPOLLOUT at once, so the
request is requeued and fails again in the same way. This continues
until apoll->poll.retries runs out (APOLL_MAX_RETRY is 128) and the
request is punted to io-wq. There the last attempt runs without
IOCB_NOWAIT and finally returns -EOPNOTSUPP. Every attempt also passes
through the drop label in tun_get_user(), so one rejected write adds
129 to rx_dropped.
Without RWF_NOWAIT and with the device down, tun_napi_alloc_frags() is
still called, since the IFF_UP check in tun_get_user() comes after skb
allocation. The error is rewritten to -EAGAIN as before, but
tun_sock_writeable() needs IFF_UP, so tun_chr_poll() returns 0. The
request then waits for EPOLLOUT instead of failing, and can stay stuck
until the interface is brought up.
The function already returns -EINVAL for a bad segment layout. Would
-EINVAL, or some other errno that io_write() does not rewrite, be a
better choice for this check?
[Severity: High]
This isn't a bug introduced by this patch, but can the same "sum of the
fragment sizes does not match skb->data_len" symptom still happen with an
ITER_IOVEC iterator that passes the new check?
Nothing here checks that len matches iov_iter_count(it). In tun_get_user(),
when msg_control is set (vhost-net zerocopy TX, TUN_MSG_UBUF), copylen is
cut short and zerocopy is set before the frags branch:
drivers/net/tun.c:tun_get_user() {
...
if (msg_control) {
...
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;
}
...
if (!zerocopy) {
copylen = len;
linear = min(hdr_len, good_linear);
}
if (frags) {
mutex_lock(&tfile->napi_mutex);
skb = tun_napi_alloc_frags(tfile, copylen, from);
...
zerocopy = false;
...
}
zerocopy is only cleared after the call, so the copylen = len reset is
skipped. tun_napi_alloc_frags() then gets copylen (128, or a hdr_len the
guest picks) while the iterator still covers the whole frame.
Inside tun_napi_alloc_frags(), linear is the length of the first
descriptor:
linear = iov_iter_single_seg_count(it);
err = __skb_grow(skb, linear);
...
skb->len = len;
skb->data_len = len - linear;
With a single 1500 byte descriptor, skb->len becomes 128 and
skb->data_len wraps to about 0xFFFFFAA4. skb_headlen() wraps back to 1500,
so the head copy and pskb_may_pull() both succeed. For a TAP device the
next step is:
tun_get_user()
eth_type_trans()
eth_skb_pull_mac()
skb_pull_inline()
__skb_pull()
That pull leaves skb->len below skb->data_len, and __skb_pull() calls
BUG().
Could a guest crash the host this way, just by sending a frame of 256
bytes or more in one descriptor with a zeroed vnet header?
A second case: the first descriptor is shorter than copylen and more
descriptors follow. Then data_len = copylen - linear, but frags[] gets the
full lengths of the later descriptors. That is the mismatch the commit
message describes, and the iterator is a valid ITER_IOVEC.
Reaching this needs vhost_net loaded with experimental_zcopytx=1, plus a
TAP queue created with IFF_NAPI_FRAGS (CAP_NET_ADMIN). vhost can still
attach to such a queue through tun_get_socket().
Would it make sense for frags mode to use copylen = len (or never set
zerocopy) in tun_get_user()? Another option is for tun_napi_alloc_frags()
to reject len != iov_iter_count(it).
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204152303.1731917-1-janislacis06%40gmail.com
Technical Details
Message-ID:
<179648532908.3146.9858580034054402326@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378036-linux-kernel-netdev=dewy.ruReferences:
<20261204152303.1731917-1-janislacis06@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378036-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] tun: reject iterators that are not user backed in NAPI frags mode Date: Sat, 05 Dec 2026 15:42:09 +0000 Organization: Usenet Network Message-ID: <179648532908.3146.9858580034054402326@kernel.org> References: <20261204152303.1731917-1-janislacis06@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3060171"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:2tbEYc4zg2e4Sr6m/bSUBz900bg= sha256:jejIIHm7baTZEQEDnKcO0RTOFX6UOGc1bbroGpNsRbk= sha1:5kuK67kP89aR0M4G4xlvbSdIcmQ= sha256:KB9ho+rHm/KbdNnKNlCj7TLJ9b/+U5OIOCo2HlU04bE= 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 01FFB117E4C; Sat, 5 Dec 2026 18:42:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.539 X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, 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 wGi-gqOh1jRi; Sat, 5 Dec 2026 18:42:23 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-378036-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 E439F117E02; Sat, 5 Dec 2026 18:42:13 +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 BAE5130276; Sat, 5 Dec 2026 15:42:11 +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=1796485331; b=0vXFu85uS6iEgayQb0KbovRiW3V5LU74guPrIx/FgF5WPKrLaQTZ7/4G0Rqss3XlHuzK /JqMC5O3xSm5jn3sWpL4NX6wtdHtP7mfUMC1fhZInNjNSXHx6XveCcKT6T5NMlnzGacry INAnpn2e1aD699b53tE0E1h5App587+TDRvtK6uJLaLWuLo7KDelC6tzGBp8mV4uhqTnu fMM4VAE0ycVjI7h+3RD056zReI9orkJhRsT4aX3GQRlkLZJzIidX4voz6KJex9+4N1xNe yeXVAJhnja1WtZyPMgdhWGPoS4xPRh+uJZzZBCKyyK0qxZNwnkQS3uxFDmtIO2ZDT2g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796485331; 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=3P12Xe7KPGYkYgzxXHi6eYh7xDGFMpMq4B4SUEAOUdg=; b=Fa3Tt1XZ/Y75Le21h5p9rmqmODxOIJSJMcSXkhs3M7ahYVGog8qbU96OPF/Qp9x+RHFu xE6oXl/KHGY2/rEgeB0zDsqZUofLltT3cX15oR7/12PwYzRotOB0M99FOJG8KqdU95e36 tUhy1F9T9CO/KprdIqK5Hav91iaPyN+IRvlUteClPW53tmZVFyKNytORdeAz9l/V2K/Mj S1IkNTxq9sQM2lmr9v/aeZY65mv9W8hWdjgnjm+0wW4tfvZvkQtxD+/LXzas3wOov5uoE 8+i79MGoJEJqp9lUnfh57UgE2nivWuWlH5m3BCmO83llph8jzZL1cgr4OSx0PIfSkNA== 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=OEp6gDMz; 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 896C0606A333; Sat, 5 Dec 2026 15:42:11 +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=OEp6gDMz 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=1796485330; b=gNU+0oWaVk3ZzlwYjq5bpPRtFfk93kre3VTRGHZDBUn9G4WkM7K5ajIqOUs7++uNeNCy 2mhbSjX5nJlqkrJttBfhn4F/++stqCdchpJkMeY+6H1Kah21+d28ppg5jrwN6+mbulivQ 8Y4dBlEduZHs/O9JL6DWj0X1f9qTXsiFxzCXT5zbcj1d+/T70dvKlhFr5xWObO5z6AEfX Tjnkd4Pd45ElWyCF0jAebJqvbfn/kjyfmHVTzr1M/I94BrbQ0/4KJu5U+anahFWXZaQMW Q4MWiCrv5hBMUzANIjY9isST1FvF/vOEoZrlACvH7sWzYdHKvnWNSVqb0tbTBv2sqSg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796485330; 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=3P12Xe7KPGYkYgzxXHi6eYh7xDGFMpMq4B4SUEAOUdg=; b=1ZNx8kZbpeFCgtd0uBX3CCmD2hkMiGOqlRL0MhjEUqH9iilbb7fQVOfLFNngAhVLh8te 6QkuSAzCWKl1obkCeHy6i/qXb0O34Z4PfG9EQaV7ZdutRl0FfYQdPCoK+IVFsrKmWEUOJ IQn6zbNPYaLbQJ2dG7ib/0KWXsXRxAITGUktVHnHAgUi73VReOi2yWHc2RIi+THJ0wGFm 0pwwskAzswhXZJLkCNHZ/yNXi9q0vZHzdRnmzwlSvKUBCVYhk++40eKDOGsT3AxJHPXOJ 4uvqryKQNtyQn344fb7nM9J8v24Rl2Ks36SvNSHxJ+4OlNsWuzzcyfH/brgaNzmy0hQ== 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=OEp6gDMz; 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 A5EBF606A322; Sat, 5 Dec 2026 15:42:10 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94CB71F0092B; Sat, 5 Dec 2026 15:42:09 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796485330; bh=3P12Xe7KPGYkYgzxXHi6eYh7xDGFMpMq4B4SUEAOUdg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=OEp6gDMzHGFmsFmR26egfj45VFy6rJnMB5ycojemwNVcJjd4+llLoP8cnfWcmu1UO t11genhEXI2B3enOZiL+ilrKW2NmgVjbXIz8nt7MbSRbQ7TLRMFGpaJLshsm1r8jBW 4bFeToMQDCFh6v026ka/96kLddm3VGDH6iZvYYQCXeySNI2C+290nPch/4HT/v4qMP oRj+mk3WjaEdckDBboHyk01nS8PfCINr8NmSMX0Ff5bEVlvOCr3u1l6JyAb+vtmt4p PIl2Xr1E+s2zDDDZUiNa7AMiciOe/+LXgjbA6GHWNDQI1w4dEM6QQiO84eTGW0uDrV N3xNi7m3zjdWA== X-Cc: netdev@vger.kernel.org, willemdebruijn.kernel@gmail.com, jasowangio@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, peterpenkov96@gmail.com, maheshb@google.com, stable@vger.kernel.org X-In-Reply-To: <20261204152303.1731917-1-janislacis06@gmail.com> X-sashiko-severity: Medium 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