Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: antonio@mandelbit.com
Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, ast@kernel.org,
	daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
	sdf@fomichev.me, netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] tun: don't probe the transport header of packets written by userspace
Date: Mon, 16 Nov 2026 15:25:49 +0000	[thread overview]
Message-ID: <179484274982.3136.10527408814471189308@kernel.org> (raw)
In-Reply-To: <20261112150612.3866546-2-antonio@mandelbit.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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] After the patch, a TAP packet that is neither GSO nor
  VIRTIO_NET_HDR_F_NEEDS_CSUM leaves tun_get_user() with…
- [Medium] On the default tun/tap receive path (no IFF_NAPI, so no GRO;
  delivery through tun_rx_batched()/netif_rx()), skb->transport_header…
- [Low] The patch removes skb_probe_transport_header() only from
  tun_get_user().

--

tun: don't probe the transport header of packets written by userspace

This commit removes the skb_probe_transport_header() call from
tun_get_user(). For NEEDS_CSUM and GSO packets it relies on
skb_partial_csum_set() and __virtio_net_hdr_to_skb() to set the transport
header, and for all other packets on the IPv4/IPv6 receive paths.

> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 8920c797acfd7..9fc60a73fb963 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1960,7 +1960,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>  		net_zcopy_complete(NULL, msg_control, false);
>  
>  	skb_reset_network_header(skb);
> -	skb_probe_transport_header(skb);
>  	skb_record_rx_queue(skb, tfile->queue_index);
>  
>  	if (skb_xdp) {

[Severity: Medium]
Without the probe, a TAP frame that is neither GSO nor
VIRTIO_NET_HDR_F_NEEDS_CSUM reaches tun's own do_xdp_generic() call with
transport_header still at the unset value (~0). This happens before
__netif_receive_skb_core() gets a chance to reset it.

Can the generic XDP copy path turn that sentinel into an offset that looks
valid but is wrong?

skb_xdp starts at 1 in tun_get_user(). It stays 1 for blocking, zerocopy,
large and IFF_NAPI_FRAGS writes, because tun_can_build_skb() rejects those.
These skbs come from tun_alloc_skb() with only tun->align of headroom, or
they are nonlinear, so they always take this branch:

net/core/dev.c:netif_receive_generic_xdp() {
    ...
	if (skb_cloned(skb) || skb_is_nonlinear(skb) ||
	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {
		if (netif_skb_check_for_xdp(pskb, xdp_prog))
    ...
}

That branch reallocates through skb_pp_cow_data() or pskb_expand_head().
Both of them end up here:

net/core/skbuff.c:skb_headers_offset_update() {
    ...
	skb->transport_header += off;
	skb->network_header   += off;
	if (skb_mac_header_was_set(skb))
		skb->mac_header += off;
    ...
}

Only mac_header gets a was_set check. 0xffff + off wraps in the u16 to
off - 1, which points into the new uninitialized headroom just before
skb->data. Because of that, skb_transport_header_was_set() returns true,
and the fallback in __netif_receive_skb_core() is skipped:

	if (!skb_transport_header_was_set(skb))
		skb_reset_transport_header(skb);

Anything that runs before L3 would then see this offset: tc ingress,
bridge or OVS forwarding into another device's xmit path, and
XDP_TX/XDP_REDIRECT through generic_xdp_tx(). ip_rcv_core() and ipv6_rcv()
overwrite it, so locally delivered IP traffic is not affected.

Before this patch, skb_probe_transport_header() had already set a valid L4
offset for dissectable IPv4/IPv6 frames, so the reallocation shifted a
valid value.

The missing sentinel check in skb_headers_offset_update() is older than
this patch. However, this patch exposes all well-formed tun frames to it,
not only the ones the dissector rejected. The commit message says these
packets are handled "as for packets from NICs". For NICs in non-DEBUG_NET
builds, __netif_receive_skb_core() resets the transport header before
generic XDP runs, and this tun-local XDP path skips that reset.

[Severity: Medium]
On the default receive path (no IFF_NAPI, delivery through
tun_rx_batched() or netif_rx()), will tc ematches that use layer transport
on a tun/tap ingress still match?

For non-GSO, non-NEEDS_CSUM packets, nothing sets the L4 offset before
__netif_receive_skb_core() anymore. In non-DEBUG_NET builds that function
resets transport_header to the network header before tc ingress runs. With
CONFIG_DEBUG_NET the reset is compiled out and the header stays unset.

em_cmp, em_nbyte and em_text get their base pointer from here:

include/net/pkt_cls.h:tcf_get_base_ptr() {
    ...
		case TCF_LAYER_TRANSPORT:
			if (!skb_transport_header_was_set(skb))
				break;
			return skb_transport_header(skb);
    ...
}

Take an existing filter like "cmp(u16 at 2 layer transport eq 80)". It
used to match the destination port. Now it would compare bytes of the IP
header, or never match at all on DEBUG_NET builds.

ip_rcv_core() and ipv6_rcv() only set the transport header after tc
ingress and bridge handling, so the commit message's "the IPv4/IPv6
receive paths set it" doesn't cover these users.

tun_xdp_one() still probes, so the same filter now classifies a packet
differently depending on whether it came in through write()/sendmsg or
vhost-net batched TX.

[Severity: Low]
Should tun_xdp_one() get the same change? It still has the probe:

drivers/net/tun.c:tun_xdp_one() {
    ...
	skb->protocol = eth_type_trans(skb, tun->dev);
	skb_reset_network_header(skb);
	skb_probe_transport_header(skb);
	skb_record_rx_queue(skb, tfile->queue_index);
    ...
}

That path also carries packets written by userspace: vhost-net batched
guest TX goes through tun_sendmsg() with TUN_MSG_PTR. It builds the skb the
same way and delivers it through netif_receive_skb() or the NAPI queue.
The argument for dropping the probe applies to it unchanged.

The subject says the probe is dropped for "packets written by userspace",
but the vhost-net batched path keeps it. The two receive paths of one tun
device now also set up the transport header differently. If this is
intentional, could the commit message mention it and give the reason?

The tap.c call sites in tap_get_user() and tap_get_user_xdp() are a
different case. Those packets go to dev_queue_xmit() on the lower device,
so the receive-path reasoning doesn't apply to them.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112150612.3866546-1-antonio%40mandelbit.com

  reply	other threads:[~2026-11-16 15:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 15:06 [PATCH net-next 0/3] tun: trim per-packet work on the write path Antonio Quartulli
2026-11-12 15:06 ` [PATCH net-next 1/3] tun: don't probe the transport header of packets written by userspace Antonio Quartulli
2026-11-16 15:25   ` netdev-bot+sashiko [this message]
2026-11-12 15:06 ` [PATCH net-next 2/3] tun: don't disable BHs for the XDP program check of every packet Antonio Quartulli
2026-11-16 15:25   ` netdev-bot+sashiko
2026-11-12 15:06 ` [PATCH net-next 3/3] tun: skip the virtio-net header parsing without IFF_VNET_HDR Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179484274982.3136.10527408814471189308@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=antonio@mandelbit.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox