🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24720

Re: [PATCH net-next v2 3/5] packet: reset network header on all headerless devices

#24720
From: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 17:36
131 lines
12196 bytes
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
Technical Details
Message-ID: <179606019574.3146.12031209728256474661@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder3.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374351-linux-kernel-netdev=dewy.ru
References: <20261129163327.893403-4-willemb@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder3.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374351-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179606019574.3146.12031209728256474661@kernel.org>
References: <20261129163327.893403-4-willemb@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="1487191"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZMONBakZ0AaHFNlMb8eeDhoYAQc= sha256:j4lIE7NnC6HmpEhT/JcaUPxvSd3w5b9UfaZ2PcHLfEU= sha1:5Ml6Q1cCL5vwlZbJq+FtMsfEZls= sha256:HIA8bZU9Ln/gk8jXO72lGptxLREauZ9zt0bouO5a+MQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 35496125FFA; Mon, 30 Nov 2026 20:36:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fds8hr8iUWXu; Mon, 30 Nov 2026 20:36:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374351-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 7161A125FFB; Mon, 30 Nov 2026 20:36:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 447CC2B023; Mon, 30 Nov 2026 17:36:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796060198; b=eyjTkPi8FDGFLtFyVntE3dZKrLXtHCXJzQaBifI1TYYb7giqhIWDpSmaJH9ohcVP2Uqi NvAjgbwmZdm4UI0Zd0jNkvfX7LL9Bee2OOzw1luSq+q7p4Q0F6+hpSTFRsQg5zR4ZCAnP S8rW6XXhyS4CrtdntvRFNmxv/r6wT0RPmcL+frUErXMFHOKmxcLy/FDOqiWKcwOLn48Ah zLrVTfRUHV5dkShxm1ZihazYdMmjAOeR9z372bMsV+bBQqsdD+7cccVsw/qPPxl9kVbSm 3KMEXj+I9DM51LGnd003e8CAqCLydTrJ4OS6GLhxiRBxn2HkaV1HabnhkOJcY2WQDjg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060198; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=fz3a1sqhNfIGZhkKo/jItegHmQUDmRDIjXoxA29qErI=; b=CbpoeapmBUfGRylvCzI4X4oCRA0gqA5qh8Zkzayjxs6clDqQntoUJ8fzvPleGj1u8wSI goLkYC4qnxAaKeXO+flV3GMMr4X7t31ttryrd71S88u5WCGC/Pb4wteHIgh8pYifMR8ZU 1q7gWTOrDSSF/8WSwj4RYwO6ClCSl8E5GuNioGHjUUZsq7zoaETNyIgNOBjIP1mtKMGWs R4Gzvv/SCnjozoJZYSvv5fFbo2PpP+geEQxNB1MhSWT8WKwEnezRvTRcdn46vTMeyfAwX 6nxRLlcA83LMvSKbHqlgLLSxH0F2KxMy6kO2y2rtAXj/vvWs+CeYLVdrcbjn6M4c0ww==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U8y7Ckze; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C481606A31C; Mon, 30 Nov 2026 17:36:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U8y7Ckze
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060197; b=dgfaoomUKGchJsiwqzBzE7QoRpOYZxI6XLQImcry2/QA+T/dmIRnnI/b2lcV0UFKsgPb 8rTFENCgj8YQa3Hb0HR4PfVindd3TBe9OnRUa5QauhSSPUXSENwGkoc6XPQc7CdDixliR N5M2rwIhykyR6+ExI0FCpZgcrXJfzgA9gVjXJDga2BTwDmmj3+AszW2Eq8/nfDVeR0KQ3 MbiM4rOoV+jzVY3o/LXaps+5wZDdF5x9U8qqO689k2McWz/+ajcnpYf7Nft1BHgrixvI6 rj95dKYFv62GHwxHf67uhxOda4hWcx1cFZ+c/T9jAuC/QUDW4g87H3PCSYmsBQ2iOUw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060197; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=fz3a1sqhNfIGZhkKo/jItegHmQUDmRDIjXoxA29qErI=; b=JBZkIYgCeQtKZ2rQz8/5go+1msmV44QufcSJRLvwI2yv1/x3pAYBwwdExhDNyRiYXm7t HU1xk+cSDPI7T/yb7b+JU5ourdvekjQYyVBXhC6h+OgQcbF95HUAptKzpWyGaqXrHsQ+8 YQi4JKKfvg2/+5Bzvp2q9rzUc4Xz0RN8bImRSBgykO/RRDQnCzR5rOLEhKP14XAWAitf2 e/NmkWic89b5FgwbSAZ5yWG67352MIZUEXouzdO5HuiI/KSY2bP2sZ/jKTR3t9eg9U88u Go8EFhvTv6v9BBVSvZrEzSzX0/f9I3cevz16CH9a8CDuCxBiozOQLqJJ9vQna7MuPZw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U8y7Ckze; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B30C606A32D for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 17:36:37 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 338E71F00898; Mon, 30 Nov 2026 17:36:36 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796060196; bh=fz3a1sqhNfIGZhkKo/jItegHmQUDmRDIjXoxA29qErI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=U8y7Ckze4/nYjWvZDbQkyNXpQbY1gEniJt+43DyJn1//LWk0Yz9t0lN4KSXT2dcEV wWOns+2QMz+PMwHegB9m9vrnMEs2hZ+BF400+y6J6mfLH6GYc1pCqJdVgtEmd30S2V DhlildzzLpdYMqpwUL09z7U1m/6ocoHSBwHjyDYO43ZymxQIkey/K3e+ZR1Hd0+jCe ht6saZKb8ABVnVXy8yTlXcpzGI4l8rPPFJVVfbs2uH5MGh4OMPP5ESAuLNTEqwwYTa vAViumuST6WGu4O+1OjrCG4snx9n65SV6jOXteLcAiOW69UX9pW9iKRAN/rZCRdDqm 6ob88TcTAxfMg==
X-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
X-In-Reply-To: <20261129163327.893403-4-willemb@google.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list