🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24703

Re: [PATCH net] tun: reject iterators that are not user backed in NAPI frags mode

#24703
From: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 17:15
190 lines
14691 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · 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).

- [Medium] The new early return `if (!user_backed_iter(it)) return
  ERR_PTR(-EOPNOTSUPP);` in tun_napi_alloc_frags() runs before…
- [Low] The commit message understates what the bug does.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the same 'skb
  lengths do not match the fragment layout' bug stays reachable with a…

--

tun: reject iterators that are not user backed in NAPI frags mode

This commit adds a user_backed_iter() check at the top of
tun_napi_alloc_frags(). Iterators that are not user backed, such as the
ITER_BVEC used by io_uring fixed-buffer writes, are now rejected with
-EOPNOTSUPP. Before this, the fragment loop read bio_vec entries as if
they were iovec entries.

Link: https://lore.kernel.org/netdev/willemdebruijn.kernel.3587ccd7685e2@gmail.com/

> This can result in an SKB where the sum of the fragment sizes does
> not match skb->data_len. This was reproduced using an io_uring
> fixed-buffer write to a TAP device, see the reproducer code below.

[Severity: Low]
The code change itself is fine, but does this description understate
what the bug does?

In tun_napi_alloc_frags(), bvec[i] is read as a struct iovec. On 64-bit
little-endian, iov_len overlays bv_len | (bv_offset << 32), so fragsz is
4096 when bv_offset is 0:

    const struct iovec *iov = iter_iov(it) + i;
    size_t fragsz = iov->iov_len;
    ...
    frag = netdev_alloc_frag(fragsz);

netdev_alloc_frag() does not zero the memory. Later, tun_get_user() calls:

    err = skb_copy_datagram_from_iter(skb, 0, from, len);

This fills only data_len bytes of the frags and returns 0 once len is
used up. The skb is then passed to napi_gro_frags().

With the reproducer output (len=5042, data_len=946, frag_bytes=4096),
3150 bytes of stale page-frag memory sit inside a frag labelled 4096
bytes.

Could anything that walks frags by skb_frag_size() read or transmit that
memory? Two examples are an SG-capable NIC driver after bridging or
forwarding, and skb_segment().

If so, could the commit message mention the possible kernel memory
disclosure, so stable and security triage can weigh it properly?

> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index ae05b1e58abaa..864945f2fac20 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1502,6 +1502,9 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile,
>  	int err;
>  	int i;
>  
> +	if (!user_backed_iter(it))
> +		return ERR_PTR(-EOPNOTSUPP);
> +

[Severity: Medium]
Can this early return leak a recycled skb cached in tfile->napi.skb?

The return happens before napi_get_frags(), and before the free label
that calls napi_free_frags().

tfile->napi.skb can still hold an skb from an earlier write. That
happens when napi_gro_frags() returns GRO_MERGED_FREE:

net/core/gro.c:napi_frags_finish() {
    ...
    case GRO_MERGED_FREE:
        if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
            napi_skb_free_stolen_head(skb);
        else
            napi_reuse_skb(napi, skb);
    ...
}

napi_reuse_skb() ends with napi->skb = skb, and tun_get_user() then
just unlocks napi_mutex.

Now suppose the next write is an io_uring IORING_OP_WRITE_FIXED
(ITER_BVEC) to the same IFF_NAPI_FRAGS device. tun_get_user() jumps to
drop with an ERR_PTR skb:

drivers/net/tun.c:tun_get_user() {
    ...
free_skb:
    drop_reason = drop_reason ?: SKB_DROP_REASON_NOT_SPECIFIED;
    if (!IS_ERR_OR_NULL(skb))
        kfree_skb_reason(skb, drop_reason);

unlock_frags:
    if (frags) {
        tfile->napi.skb = NULL;
        mutex_unlock(&tfile->napi_mutex);
    }
    ...
}

The ERR_PTR skb is not freed. Then tfile->napi.skb = NULL drops the
only reference to the recycled sk_buff and its head buffer.
napi_free_frags() at NAPI teardown cannot reclaim it either, because
napi->skb is already NULL.

A write that GRO merges followed by a fixed-buffer write would then leak
one skb per pair, with no limit. Before this patch, the bvec write
reused the cached skb instead.

The existing -EMSGSIZE early return just below has the same flaw.
However, this check adds an easy way to trigger it for a whole class of
iterators.

Would it be better to do the user_backed_iter() check in tun_get_user()
before taking napi_mutex? Another option would be to clear
tfile->napi.skb in unlock_frags only when it was actually used or freed.

>  	if (it->nr_segs > MAX_SKB_FRAGS + 1 ||
>  	    len > (ETH_MAX_MTU - NET_SKB_PAD - NET_IP_ALIGN))
>  		return ERR_PTR(-EMSGSIZE);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Can
the same mismatch between skb lengths and frag layout still be reached
with a user-backed ITER_IOVEC iterator? The new check lets those
through.

When tun_get_user() is called with msg_control set (the vhost-net
zerocopy TX path, TUN_MSG_UBUF), zerocopy is true and copylen stays
short:

    copylen = min(hdr_len ? hdr_len : GOODCOPY_LEN, good_linear);
    ...
    if (frags) {
        mutex_lock(&tfile->napi_mutex);
        skb = tun_napi_alloc_frags(tfile, copylen, from);
        ...
        zerocopy = false;
    ...
    err = skb_copy_datagram_from_iter(skb, 0, from, len);

Inside tun_napi_alloc_frags(), linear is the length of the first
segment, which the guest controls:

    linear = iov_iter_single_seg_count(it);
    err = __skb_grow(skb, linear);
    ...
    skb->len = len;
    skb->data_len = len - linear;
    skb->truesize += skb->data_len;

Suppose the first segment is longer than copylen, for example 1500 vs
128. Then skb->data_len wraps to roughly 0xFFFFFAA4 and truesize wraps
as well, while skb->len is 128.

Would the following eth_type_trans()->skb_pull_inline()->__skb_pull()
then see skb->len < skb->data_len and hit BUG()?

If the first segment is shorter than copylen, the frag sizes exceed
data_len instead. That is the symptom this commit describes.

It looks like the cause here is the length argument passed in, not the
iterator type.

Reaching this needs an IFF_NAPI_FRAGS tap used as a vhost-net backend
with experimental_zcopytx=1. Once that is set up, the guest's TX
descriptor layout decides whether it triggers.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129171337.815175-1-janislacis06%40gmail.com
Technical Details
Message-ID: <179605890863.3146.9327234366805987306@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.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!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374332-linux-kernel-netdev=dewy.ru
References: <20261129171337.815175-1-janislacis06@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374332-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tun: reject iterators that are not user backed in NAPI frags mode
Date: Mon, 30 Nov 2026 17:15:08 +0000
Organization: Usenet Network
Message-ID: <179605890863.3146.9327234366805987306@kernel.org>
References: <20261129171337.815175-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="1481166"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BVsfBGHCeI3Mo1XmvDO/RRrVuCw= sha256:gcG6QyfbkhtKln4vXnMf/vqCqy17TTxIQn05ZhvVLuc= sha1:LyH7gYyb+omyabvOGcH22eCDp5k= sha256:ky4hSEDBvEmmN4iIdKPVRWIpYzwMTVGFniBQfIzIFWA=
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 3DC02125FF7; Mon, 30 Nov 2026 20:15:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 deVZ58gXl-Pv; Mon, 30 Nov 2026 20:15:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374332-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 89F1B125FF6; Mon, 30 Nov 2026 20:15: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 0B54633117; Mon, 30 Nov 2026 17:15: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=1796058910; b=PlRw8WNDt2OscbNN0Qa0Ly3XT81ej8mU+/jUX0sL3NkHyoUi/4B7ZKrKkQaTzGk4nJPm 3rRv1LHdSiZ/4wwnyVUFOVlw+ZpeVTAuEsHXdelZo78w6EMvviKx6SrTFc9n8bZIVOmw+ F5H+TK4s7gNDd83ybnHtpYnzD81wEsUwbIc264HAJr4fOfhRic4EVBRbpFJEcwr/fYuNy LYmmZpHkvzfkt/gzVD9fDpqe7rgmP/vHr9N1rftpL+t4x0vnEfqrdFl+Dp9B2qyTm93/q GIP2xAKp2eHTijGfbE0ZLa3U3j/vdZv/FOs+Tgoo2s8M5GRv6a5eoVPaMS6rnWajZ3Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058910; 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=slAOK90RArsz+CMaFX3GfT2hU+gEHZ3po5cbxt5ACPs=; b=og2xTpc4Yh2OXaoP1SzLg8/sPpKnpSwR3q4QcgKgMLXw3OvaX97G81wF9q+yYOncd4u4 +YWqOXHc6ZB1plFMmvUMg+0GOQqdIZKPlzAckrq/5F1BJzE5rO91sTstME26ZPnq90NIm +cgXPSu+QYB28bKj7ujPn0ipPFwoW4+8b9TSYkcFUolPndjlQ5ve95BPDvibY1ioWscml RFCMduzUMKrzssUbOPdqOtLGlFZ9qfgHGqzF3XelPl+hjabDNrAmINurc3HlvbfaFtDBN 6uzYknPChScR9D1H/wQyDsB5+D/DDgaJxw833UrR4IiAt4duq0dGBZJLglFyvXk1IXw==
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=NXcIlqiY; 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 D5468606A333; Mon, 30 Nov 2026 17:15:10 +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=NXcIlqiY
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=1796058910; b=sLbWoW+4yWrHGc7nChB4Esa4nwqRHR+gSeE9tvusKeULXDSx1EjV6Xp/ExdfQ8wTG5l3 5vjt/Qvl3wm/uU8qjMNAqEBgphna3ZwHrzUBCH9LvjLDW8ccCLnARdu037fJBIwJZ2dYa PfugWi3E4xnw/W+iLuOTumrYLV3KwBa69EyhhLD4G677Z/81sdCZiNUuSEsUtdASInyvj epaJX+wahErDfaUkde1z+j+HmiMFwL1Q+ZCVVpHvrUVya6ARAoD/G+jgmF1O83K3JBWM8 BQV0YJKSEaKfJ6RliRDdbjhvqmSsjU/hqK2fh9Vvs8tqhwpKm3Fc8kmDnKm0dtXmdCA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058910; 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=slAOK90RArsz+CMaFX3GfT2hU+gEHZ3po5cbxt5ACPs=; b=atadb2iupioGlxFSGEhkAe5GklT6ktEi7NqHegw3tVXpZrCp2WA4lXZCpR/plf2UjKQB 7VYPZcmR3ctgIrhjTvcvQfd0Nc6K3J/jRTB9PqXllvb2Ff6MsphVIG0m2szlsZsNXxNiT Qh9U3M6ZBkjFCuZJB5CcIyT0u3d3wxKyqKAbcUQmc/HNV4Bv71z9RFwgHMs9ovEkdbmd/ OnKXz3fTztRl8Ct4LescBS9lGTvgRxolbDBjS/IMZWF8Q0n50ZIUjDF1OhyqUUE7A4rEW pLzOm0EA6AYfjEZ4Vr8IHvscwbRE+8YldoxJc/a3dmBnYkhUrAQDitbwLTKI7Fxm7qQ==
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=NXcIlqiY; 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 F3EC8606A32C for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 17:15:09 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15F241F00899; Mon, 30 Nov 2026 17:15:09 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796058909; bh=slAOK90RArsz+CMaFX3GfT2hU+gEHZ3po5cbxt5ACPs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NXcIlqiY4iY/zhF8jdgWFcyb4eXTG51Tq6Zh2ixcfP10FTJuMCQnYbxnUlkQDIm5o L4/kYXEwkngRDfAN9d1dgom4Ug7lushcnInHDKAdaKb1vmJG10J2Wn5bOvjm8gEAWz EDGb1uVvNG8wADfj4z4G5AXT0DIRi1YeWIpSuvBSJuhB0Xl6ckRyYD0HtKcok+mOlo zyxBIEcQj1AwmPYu8YNAkZFoHXnk2pxFGNVuBjVJ2U2jy0ZDL5xg5IeaQKbX6ho42q FoPXhCMS5LIjX4quiam68zsr06zIgApRaMWR8oqgEDcweavXnz49YFVpswLK3Bo1eL +cjPmJ/2AF33w==
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
X-In-Reply-To: <20261129171337.815175-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
X-Received-Bytes: 14432