From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Mon, 30 Nov 2026 17:15:09 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15F241F00899; Mon, 30 Nov 2026 17:15:09 +0000 (UTC) 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== Subject: Re: [PATCH net] tun: reject iterators that are not user backed in NAPI frags mode From: netdev-bot+sashiko@kernel.org To: janislacis06@gmail.com 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 Date: Mon, 30 Nov 2026 17:15:08 +0000 Message-ID: <179605890863.3146.9327234366805987306@kernel.org> In-Reply-To: <20261129171337.815175-1-janislacis06@gmail.com> References: <20261129171337.815175-1-janislacis06@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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