From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Mon, 30 Nov 2026 17:36:37 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 338E71F00898; Mon, 30 Nov 2026 17:36:36 +0000 (UTC) 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== Subject: Re: [PATCH net-next v2 3/5] packet: reset network header on all headerless devices 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 Date: Mon, 30 Nov 2026 17:36:35 +0000 Message-ID: <179606019574.3146.12031209728256474661@kernel.org> In-Reply-To: <20261129163327.893403-4-willemb@google.com> References: <20261129163327.893403-4-willemb@google.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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