From: netdev-bot+sashiko@kernel.org
To: willemdebruijn.kernel@gmail.com
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, elder@kernel.org,
willemb@google.com
Subject: Re: [PATCH net-next 3/6] packet: validate TX header length before skb allocation
Date: Wed, 25 Nov 2026 20:06:12 +0000 [thread overview]
Message-ID: <179563717264.3135.14653977581584751949@kernel.org> (raw)
In-Reply-To: <20261124170551.1874487-4-willemdebruijn.kernel@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] In packet_sendmsg_spkt() (net/packet/af_packet.c), the header-
length check (`len < hard_header_len || !len`) now runs only on the…
--
packet: validate TX header length before skb allocation
This patch moves the TX header length checks in packet_sendmsg_spkt(),
tpacket_snd() and packet_snd() ahead of skb allocation. The checks now
compare against the snapshotted hard_header_len. It also drops the
network header reset in packet_sendmsg_spkt(), which can no longer be
reached, and the hdrlen clamp in tpacket_fill_skb().
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 230b16742346c..e8326cade94af 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2024,8 +2024,13 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
> }
>
> /* Keep the allocation-time header length across retry. */
> - if (!skb)
> + if (!skb) {
> hard_header_len = READ_ONCE(dev->hard_header_len);
> + if (len < hard_header_len || !len) {
> + err = -EINVAL;
> + goto out_unlock;
> + }
> + }
>
> err = -EMSGSIZE;
> if (len > dev->mtu + hard_header_len + VLAN_HLEN + extra_len)
[ ... ]
> @@ -2060,10 +2063,6 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
> goto retry;
> }
>
> - if (len < hard_header_len || !skb->len) {
> - err = -EINVAL;
> - goto out_unlock;
> - }
> if (len > (dev->mtu + hard_header_len + extra_len) &&
> !packet_extra_vlan_len_allowed(dev, skb)) {
> err = -EMSGSIZE;
[Severity: Medium]
With this check removed, is len ever validated against the device that
actually transmits the skb?
The new check in the first hunk only runs while skb is NULL. It uses the
device returned by the first dev_get_by_name_rcu() lookup. After that,
packet_sendmsg_spkt() drops the RCU read lock and calls sock_wmalloc()
with GFP_KERNEL and then memcpy_from_msg(). Both can sleep. It then jumps
back and looks the device up again by name:
retry:
rcu_read_lock();
dev = dev_get_by_name_rcu(sock_net(sk), saddr->spkt_device);
Suppose spkt_device now names a different netdev (renamed, or deleted and
recreated) with a larger hard_header_len. Only the MTU checks remain
before dev_queue_xmit().
For example, a 1 byte frame sized for a tun device (hard_header_len 0)
could be sent on a veth device (hard_header_len 14). This needs
CAP_NET_RAW and CAP_NET_ADMIN. Both are available inside an unprivileged
user plus network namespace.
On veth the call path is:
veth_xmit()->veth_forward_skb()->__dev_forward_skb()->eth_type_trans()
->eth_skb_pull_mac()
eth_skb_pull_mac() reads the ethhdr at skb->data even when skb->len is
less than ETH_HLEN:
include/linux/etherdevice.h:eth_skb_pull_mac() {
struct ethhdr *eth = (struct ethhdr *)skb->data;
skb_pull_inline(skb, ETH_HLEN);
return eth;
}
Would eth->h_proto and the pkt_type classification then come from
uninitialized bytes past skb->len?
Before the series, dev_validate_header(dev, skb->data, len) ran after the
retry. It checked the live transmit device, inside the same RCU section
as dev_queue_xmit().
The earlier patch "net: remove header_ops->validate and
dev_validate_header()" switched that check to the snapshotted value. This
patch then removes the post-retry check. The gap is still there at the
end of the series ("net: remove unused net_device::min_header_len").
Could len be checked here again against READ_ONCE(dev->hard_header_len)
of the retry device? Another option is to bail out if the device changed
between the two lookups.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124170551.1874487-1-willemdebruijn.kernel%40gmail.com
next prev parent reply other threads:[~2026-11-25 20:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 17:05 [PATCH net-next 0/6] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-24 17:05 ` [PATCH net-next 1/6] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-24 17:57 ` Alex Elder
2026-11-24 17:05 ` [PATCH net-next 2/6] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
2026-11-25 20:06 ` netdev-bot+sashiko
2026-11-24 17:05 ` [PATCH net-next 3/6] packet: validate TX header length before skb allocation Willem de Bruijn
2026-11-25 20:06 ` netdev-bot+sashiko [this message]
2026-11-24 17:05 ` [PATCH net-next 4/6] packet: reset network header on all headerless devices Willem de Bruijn
2026-11-24 17:05 ` [PATCH net-next 5/6] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
2026-11-25 20:06 ` netdev-bot+sashiko
2026-11-24 17:05 ` [PATCH net-next 6/6] net: remove unused net_device::min_header_len Willem de Bruijn
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=179563717264.3135.14653977581584751949@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=elder@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--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