Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: willemb@google.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
Subject: Re: [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header()
Date: Mon, 30 Nov 2026 17:36:34 +0000	[thread overview]
Message-ID: <179606019437.3146.10783592066760126998@kernel.org> (raw)
In-Reply-To: <20261129163327.893403-3-willemb@google.com>

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

Critical: 0 · High: 0 (1) · 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] packet: re-reading hard_header_len in packet_snd() and
  tpacket_fill_skb()

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
  rewrites the exact comparison involved and keeps it inconsistent.

--

net: remove header_ops->validate and dev_validate_header()

This commit removes header_ops->validate and dev_validate_header(). AX.25
was the only validate implementation and has been removed, and the
CAP_SYS_RAWIO bypass is also gone. The three af_packet callers now compare
directly against READ_ONCE(dev->hard_header_len).

> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 037b4e55ca3df..0ea3036bee249 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c

[ ... ]

> @@ -2664,7 +2664,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
>  		err = skb_store_bits(skb, 0, data, hdrlen);
>  		if (unlikely(err))
>  			return err;
> -		if (!dev_validate_header(dev, skb->data, hdrlen))
> +		if (hdrlen < READ_ONCE(dev->hard_header_len))
>  			return -EINVAL;

[Severity: Medium]
This patch did not introduce this issue, because the removed
dev_validate_header() read dev->hard_header_len the same way. Since
these three checks are being rewritten anyway, could they compare
against the local hard_header_len snapshot rather than doing a second
READ_ONCE()?

packet_snd() takes the snapshot once and lays out the skb from it:

packet_snd()
    hard_header_len = READ_ONCE(dev->hard_header_len);
    if (sock->type == SOCK_RAW)
        reserve = hard_header_len;
    ...
    linear = max(linear, min_t(int, len, hard_header_len));
    skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear, ...);
    skb_reset_network_header(skb);
    ...
    skb_reserve(skb, -reserve);

Take a SOCK_RAW socket on a device that has header_ops. The network
header stays at offset reserve from skb->data. Suppose
dev->hard_header_len shrinks between the snapshot and this check, for
example through ipgre_link_update() when GRE key/csum/seq flags are
dropped. A frame with len below the snapshot, but at or above the new
value, then passes. skb_network_offset(skb) ends up larger than
skb->len and points past skb_tail_pointer(skb). Is everything after
packet_parse_headers() and packet_xmit() prepared for a network header
that sits beyond the end of the packet?

packet_sendmsg_spkt() has the same pattern. It keeps hard_header_len
across the unlocked sock_wmalloc() and the retry lookup, and it uses
that value for the headroom and the MTU checks. The retry lookup by
name may resolve to a different net_device. Even so, the length check
re-reads dev->hard_header_len. The layout there resets the network
header when len < hhlen, so the effect looks limited to the check not
matching how the skb was built.

The tpacket_fill_skb() hunk has the same mismatch. There it is worse,
because the skb can go out with linear bytes that skb_store_bits()
never wrote.

Triggering this needs CAP_NET_RAW to send, plus CAP_NET_ADMIN to
reconfigure the device concurrently. Would something like this be
enough?

	if ((sock->type == SOCK_RAW && len < hard_header_len) ||
	    !skb->len) {

and in packet_sendmsg_spkt():

	if (len < hard_header_len || !skb->len) {

That would make all three checks match the value used to size and lay
out the skb, which is what the earlier "packet: use consistent
hard_header_len" changes seem to have intended.

[Severity: High]
This is a pre-existing issue that this patch did not introduce. Since this
line is being rewritten anyway, should it compare against the
hard_header_len parameter instead of reading dev->hard_header_len again?

The linear area just above is sized from a snapshot that tpacket_snd()
takes once, before its frame loop:

tpacket_snd()
    hard_header_len = READ_ONCE(dev->hard_header_len);
    ...
    do {
        ...
        copylen = max_t(int, copylen, hard_header_len);
        ...
        tp_len = tpacket_fill_skb(po, skb, dev, data, tp_len, proto,
                                  addr, hlen, copylen, hard_header_len,
                                  &sockc);

In tpacket_fill_skb(), skb_push() and skb_put() set skb->len to copylen.
However, skb_store_bits() only writes hdrlen = min(copylen, tp_len) bytes.

Suppose dev->hard_header_len shrinks after the snapshot. A SOCK_RAW
TX_RING frame with tp_len between the new value and the snapshot value
then passes this check. to_write becomes 0, so no frags are added. The skb
is sent with bytes [tp_len, copylen) never written, and those bytes come
from sock_alloc_send_skb(), which does not zero memory.

One way to shrink it at runtime is ipgre_changelink()->ipgre_link_update()
on a GRE device that has header_ops, when key/csum/seq flags are removed:

net/ipv4/ip_gre.c:ipgre_link_update() {
    ...
	if (dev->header_ops)
		dev->hard_header_len += len;
    ...
}

In that case len is negative. ipgre_xmit() then pulls only the current
tunnel->hlen + sizeof(struct iphdr). Couldn't the leftover uninitialized
bytes then be sent as GRE payload, and also be visible to packet taps?

The race window can be wide, because tpacket_snd() keeps using the
snapshot across wait_for_completion_interruptible_timeout(). The trigger
needs CAP_NET_RAW and CAP_NET_ADMIN in the netns, and an unprivileged user
namespace provides both.

The removed dev_validate_header() read dev->hard_header_len the same way,
so this patch does not change the behavior. The snapshot parameter has
been in scope here since commit 21b5953e7494 ("packet: use consistent
hard_header_len in TX_RING send path"). Would something like this close
it?

	if (hdrlen < hard_header_len)
		return -EINVAL;

This check is still unchanged at the end of the series, after "net: remove
unused net_device::min_header_len".

packet_snd() and packet_sendmsg_spkt() have the same mismatch between the
snapshot and the second read. They copy the whole payload, though, so the
effect there looks limited to an inconsistent network header offset rather
than uninitialized bytes.

>  
>  		data += hdrlen;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129163327.893403-1-willemb%40google.com

  reply	other threads:[~2026-11-30 17:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
2026-11-30 17:36   ` netdev-bot+sashiko [this message]
2026-11-29 16:30 ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices Willem de Bruijn
2026-11-30 17:36   ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
2026-11-30 17:36   ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 5/5] 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=179606019437.3146.10783592066760126998@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 \
    /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