linux/arch/um/drivers
Eric Dumazet 44378d02c5 net: always dissect GSO packets in __virtio_net_hdr_to_skb()
Commit 9e8db59132 ("net: avoid false positives in untrusted gso
validation") added a '&& skb->network_header' check before flow-dissecting
GSO packets without VIRTIO_NET_HDR_F_NEEDS_CSUM in
__virtio_net_hdr_to_skb(), because some callers (such as tun_get_user(),
tun_xdp_one(), virtnet_receive_done(), and raw_verify_header()) called
virtio_net_hdr_*_to_skb() before initializing skb->network_header and
skb->dev.

Because __alloc_skb() and __build_skb_around() zero-initialize
skb->network_header to 0 (unlike mac_header and transport_header which
are initialized to ~0U), those four callers always had
skb->network_header == 0 and bypassed flow dissection in
__virtio_net_hdr_to_skb(). More generally, skb->network_header is an
offset from skb->head (where 0 is also a valid offset whenever
skb_headroom(skb) is 0), not a boolean flag.

Whenever the 'if (gso_type && skb->network_header)' branch was skipped,
the fallback 'else if (gso_type)' only pulled nh_min_len + thlen (40 bytes
for TCPv4) without dissecting the packet, without validating ip_proto or
n_proto, and without setting skb->transport_header.

If the packet has a malformed network header, it is not rejected and a
subsequent skb_probe_transport_header() also fails, leaving
skb->transport_header at ~0U (0xffff). Similarly, if an IPv4 packet
carries IP options (ihl > 5) or an IPv6 packet carries extension headers,
pulling only nh_min_len + thlen can leave the TCP header outside
skb->head. In both cases, tcp_hdrlen(skb) in skb_gso_transport_seglen()
reads out-of-bounds:

  BUG: KASAN: slab-out-of-bounds in skb_gso_transport_seglen
  Read of size 2 by task poc/133
  skb_gso_transport_seglen (net/core/gso.c:155)
  skb_gso_validate_mac_len (net/core/gso.c:270)
  tbf_enqueue (net/sched/sch_tbf.c:260)
  dev_qdisc_enqueue (net/core/dev.c:4227)
  __dev_queue_xmit (net/core/dev.c:4884)

In addition, checking virtio_net_hdr_match_proto() only inside
'if (!skb->protocol)' before flow dissection both skipped validation when
skb->protocol was pre-set by the caller and rejected VLAN-tagged frames
whose outer L2 protocol is ETH_P_8021Q or ETH_P_8021AD.

Fix this by:
1. Initializing skb->dev and skb->network_header (plus skb->protocol for
   IFF_TUN) before virtio_net_hdr_*_to_skb() in tun_get_user(),
   tun_xdp_one(), virtnet_receive_done(), and raw_verify_header(). In
   tun_get_user(), drop the redundant skb_reset_mac_header(skb) in the
   IFF_TUN case since __virtio_net_hdr_to_skb() unconditionally resets
   mac_header.
2. Removing '&& skb->network_header' and the unvalidated
   'else if (gso_type)' fallback in __virtio_net_hdr_to_skb() so all GSO
   packets without VIRTIO_NET_HDR_F_NEEDS_CSUM are flow-dissected, have
   their transport header pulled into linear data, and have
   skb->transport_header set.
3. Moving the virtio_net_hdr_match_proto() check to after
   skb_flow_dissect_flow_keys_basic(), validating keys.basic.n_proto
   against hdr_gso_type.

Fixes: 9e8db59132 ("net: avoid false positives in untrusted gso validation")
Fixes: d5be7f632b ("net: validate untrusted gso packets without csum offload")
Fixes: 924a9bc362 ("net: check if protocol extracted by virtio_net_hdr_set_proto is correct")
Reported-by: Weiming Shi <bestswngs@gmail.com>
Closes: https://lore.kernel.org/netdev/20260927163117.746432-2-bestswngs@gmail.com/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20261001191140.2818991-3-edumazet@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
History 2026-10-06 15:35:40 -07:00
..
chan.h um: chan: use blocking IO for console output for time-travel 2024-07-03 12:18:02 +02:00
chan_kern.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
chan_user.c um: Use os_set_pdeathsig helper in winch thread/process 2024-10-25 11:34:55 +02:00
chan_user.h tty: um: convert to u8/__u8 and size_t 2023-12-08 12:02:38 +01:00
cow.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
cow_sys.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cow_user.c um: drivers: call kernel_strrchr() explicitly in cow_user.c 2026-04-08 09:25:22 +02:00
fd.c um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
harddog.h um: harddog: fix modular build 2023-05-10 00:21:30 +02:00
harddog_kern.c [tree-wide] finally take no_llseek out 2024-09-27 08:18:43 -07:00
harddog_user.c um: harddog: fix modular build 2023-05-10 00:21:30 +02:00
harddog_user_exp.c um: harddog: fix modular build 2023-05-10 00:21:30 +02:00
hostaudio_kern.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
Kconfig um: virt-pci: Switch to msi_create_parent_irq_domain() 2025-07-11 08:49:01 +02:00
line.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
line.h tty: um: convert to u8/__u8 and size_t 2023-12-08 12:02:38 +01:00
Makefile um: Remove file-based iomem emulation support 2025-10-27 16:37:12 +01:00
mconsole.h um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
mconsole_kern.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
mconsole_kern.h um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
mconsole_user.c minmax: make generic MIN() and MAX() macros available everywhere 2024-07-28 15:49:18 -07:00
null.c tty: um: convert to u8/__u8 and size_t 2023-12-08 12:02:38 +01:00
port.h um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
port_kern.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
port_user.c um: port_user: Improve error handling when port-helper is not found 2022-03-11 10:55:55 +01:00
pty.c um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
random.c um: Rewrite the sigio workaround based on epoll and tgkill 2025-03-20 09:28:44 +01:00
rtc.h um: add a pseudo RTC 2021-02-12 21:38:52 +01:00
rtc_kern.c um: rtc: use RTC time when calculating the alarm 2025-01-10 13:50:00 +01:00
rtc_user.c um: rtc: Avoid shadowing err in uml_rtc_start() 2025-07-11 08:49:18 +02:00
ssl.c um: Fix help message for ssl-non-raw 2025-09-10 14:23:43 +02:00
stderr_console.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
stdio_console.c um: Do not initialise statics to 0. 2022-09-19 23:10:07 +02:00
stdio_console.h um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
tty.c um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
ubd.h um: ubd: Switch to the pthread-based helper 2025-03-20 09:26:38 +01:00
ubd_kern.c ubd: Use pointer-to-pointers for io_thread_req arrays 2026-02-23 14:35:16 -08:00
ubd_user.c um: ubd: Add missing error check in start_io_thread() 2025-06-25 09:25:49 +02:00
vector_kern.c um: vector: fix use-after-free in vector_mmsg_rx() 2026-07-23 21:31:14 +02:00
vector_kern.h um: vector: Replace locks guarding queue depth with atomics 2024-09-12 19:56:05 +02:00
vector_transports.c net: always dissect GSO packets in __virtio_net_hdr_to_skb() 2026-10-06 15:35:40 -07:00
vector_user.c vector_user: add VDE support 2024-09-12 20:16:42 +02:00
vector_user.h uml: vector: Remove unused definitions VECTOR_{WRITE,HEADERS} 2023-02-13 10:14:32 +01:00
vfio_kern.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
vfio_user.c um: Add VFIO-based virtual PCI driver 2025-05-05 10:25:24 +02:00
vfio_user.h um: Add VFIO-based virtual PCI driver 2025-05-05 10:25:24 +02:00
vhost_user.h um: virtio_uml: query the number of vqs if supported 2024-11-07 18:05:07 +01:00
virt-pci.c um: virt-pci: Switch to msi_create_parent_irq_domain() 2025-07-11 08:49:01 +02:00
virt-pci.h um: virt-pci: Refactor virtio_pcidev into its own module 2025-03-18 11:06:54 +01:00
virtio_pcidev.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
virtio_uml.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
xterm.c um: xterm: Update options for gnome-terminal 2025-05-05 10:21:15 +02:00
xterm.h um: Add SPDX headers for files in arch/um/drivers 2019-09-15 21:37:16 +02:00
xterm_kern.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00