]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commit
net/packet: fix TOCTOU race on mmap'd vnet_hdr in tpacket_snd()
authorBingquan Chen <patzilla007@gmail.com>
Sat, 18 Apr 2026 11:20:06 +0000 (19:20 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 23 Apr 2026 03:16:34 +0000 (20:16 -0700)
commit2c054e17d9d41f1020376806c7f750834ced4dc5
tree969614ac3dcb05512e41e2b90b8940d8a6b49b3b
parent3bfcf396081ace536733b454ff128d53116581e5
net/packet: fix TOCTOU race on mmap'd vnet_hdr in tpacket_snd()

In tpacket_snd(), when PACKET_VNET_HDR is enabled, vnet_hdr points
directly into the mmap'd TX ring buffer shared with userspace. The
kernel validates the header via __packet_snd_vnet_parse() but then
re-reads all fields later in virtio_net_hdr_to_skb(). A concurrent
userspace thread can modify the vnet_hdr fields between validation
and use, bypassing all safety checks.

The non-TPACKET path (packet_snd()) already correctly copies vnet_hdr
to a stack-local variable. All other vnet_hdr consumers in the kernel
(tun.c, tap.c, virtio_net.c) also use stack copies. The TPACKET TX
path is the only caller of virtio_net_hdr_to_skb() that reads directly
from user-controlled shared memory.

Fix this by copying vnet_hdr from the mmap'd ring buffer to a
stack-local variable before validation and use, consistent with the
approach used in packet_snd() and all other callers.

Fixes: 1d036d25e560 ("packet: tpacket_snd gso and checksum offload")
Signed-off-by: Bingquan Chen <patzilla007@gmail.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260418112006.78823-1-patzilla007@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/packet/af_packet.c