]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
packet: use consistent hard_header_len in non-ring send paths
authorQihang Tang <q.h.hack.winter@gmail.com>
Wed, 5 Aug 2026 12:57:28 +0000 (20:57 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 6 Aug 2026 16:27:21 +0000 (09:27 -0700)
commit03390aa32e669cc4ecd7d34108e2e1afc13d689d
treef2a2370f5ba973723f5a837fc8fc3c07ff821bc0
parent3b9a324e646d3657a8d9806dfbfe4f3e4066e882
packet: use consistent hard_header_len in non-ring send paths

packet_snd() reads dev->hard_header_len multiple times while allocating
and constructing an skb. Device reconfiguration can change this value
concurrently, for example through bonding device type changes.

For SOCK_RAW, packet_snd() can save a larger value in reserve and later
allocate headroom using a smaller value. Moving skb->data back by reserve
then places it before skb->head, and the following copy from userspace can
attempt an out-of-bounds write.

packet_sendmsg_spkt() has the same issue because it calculates its
reservation and header offset from separate reads before dropping the RCU
read lock to allocate the skb.

Add LL_RESERVED_SPACE_EX() for callers that already saved a header length.
Read hard_header_len once in packet_snd() and use it for allocation and
construction. In packet_sendmsg_spkt(), preserve the allocation-time value
through the device lookup retry.

The separate SOCK_DGRAM consistency problem between hard_header_len and
header_ops->create is not addressed here.

Fixes: b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")
Cc: stable@vger.kernel.org
Signed-off-by: Qihang Tang <q.h.hack.winter@gmail.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260805125729.19220-3-q.h.hack.winter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netdevice.h
net/packet/af_packet.c