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 3/5] packet: reset network header on all headerless devices
Date: Mon, 30 Nov 2026 17:36:35 +0000	[thread overview]
Message-ID: <179606019574.3146.12031209728256474661@kernel.org> (raw)
In-Reply-To: <20261129163327.893403-4-willemb@google.com>

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

Critical: 0 · High: 1 · Medium: 0 · 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).

- [High] packet_snd() (net/packet/af_packet.c) can build an skb whose
  network header lies past the end of the packet, on devices that have a…

--

packet: reset network header on all headerless devices

This replaces the min_header_len based heuristic in packet_snd() with a
!dev_has_header(dev) check before resetting the network header on
SOCK_RAW sends. It adds the same check to tpacket_fill_skb(). It also
switches packet_sendmsg_spkt() from dev->header_ops to
dev_has_header(dev).

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

[ ... ]

> @@ -3125,8 +3127,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
>  			goto out_free;
>  	} else if (reserve) {
>  		skb_reserve(skb, -reserve);
> -		if (len < reserve + sizeof(struct ipv6hdr) &&
> -		    dev->min_header_len != hard_header_len)
> +		if (!dev_has_header(dev))
>  			skb_reset_network_header(skb);
>  	}
>  

[Severity: High]
Can this leave skb->network_header past the tail of the skb on devices
that have header_ops->create? GRE with ipgre_header_ops is one example.

packet_snd() reads the header length once and uses it for reserve:

	hard_header_len = READ_ONCE(dev->hard_header_len);
	if (sock->type == SOCK_RAW)
		reserve = hard_header_len;

The later short packet check reads the device field again:

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

On GRE, hard_header_len can shrink at runtime under RTNL, and
packet_snd() does not hold RTNL:

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

This runs from ipgre_changelink() and ipgre_tunnel_ctl() when the
okey/csum/seq flags are cleared.

Take a saved value of 28 (GRE with key) and a user len of 24. If the
device value changes to 24 between the two reads, the 24 < 24 check
passes. The skb then has len 24 with network_header at data + 28.

The window between the two reads includes packet_alloc_skb(), which can
block on sndbuf. It also includes skb_copy_datagram_from_iter(), which
can fault.

Before this patch, the old condition reset the network header in this
case, because GRE leaves min_header_len at 0:

	if (len < reserve + sizeof(struct ipv6hdr) &&
	    dev->min_header_len != hard_header_len)

That is the same protection commit 993675a3100b ("packet: reset network
header if packet shorter than ll reserved space") added for the case
where "skb->mac_len may exceed skb->len".

Suppose a clsact egress filter with a mirred ingress action is installed
on the GRE device. The skb would then reach:

__dev_queue_xmit()
  sch_handle_egress()
    tcf_mirred_to_dev()

net/sched/act_mirred.c:tcf_mirred_to_dev() {
	...
	expects_nh = want_ingress || !m_mac_header_xmit;
	at_nh = skb->data == skb_network_header(skb);
	if (at_nh != expects_nh) {
		mac_len = at_ingress ? skb->mac_len :
			  skb_network_offset(skb);
		if (expects_nh) {
			skb_pull_rcsum(skb_to_send, mac_len);
	...
}

Here mac_len is 28 and the clone has len 24, so skb_pull_rcsum() hits:

	BUG_ON(len > skb->len);

On other paths, dev_queue_xmit_nit() would log "protocol %04x is buggy"
for this skb, and ipgre_xmit() would drop it in pskb_inet_may_pull().

The trigger needs CAP_NET_RAW and CAP_NET_ADMIN. An unprivileged user
can get both in a user namespace with its own netns.

The final state of the series ("net: remove unused
net_device::min_header_len") seems to have the same code here, so no
later patch fixes it.

Could len be checked against the saved hard_header_len, the value used
for reserve and linear, instead of re-reading dev->hard_header_len?
Alternatively, could the network header still be reset when
len < reserve?

-- 
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
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 [this message]
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=179606019574.3146.12031209728256474661@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