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=1796060196; b=UXaRhkJjjI0hg9GBk6kKwhz090Sa7Dyd756ftwiWYvtPoWFiZ2LreKdV7coZ9wByF5sZ 1hS5ACSaycq1EoynYbi7WMq0Nlr1lZtBHKFMIbqcos8qBbS/2PgkebKHvt/bK+CJTQyAe UraMOqdYxUnx1NjtoJOHch/MEXU6JiZzOBkMgHpLeI0vt8Ecy2WX8+t24cuDJElbXb49e RMiH7zOlj1HYtXUtTDEH48qTzrTn/z2DgxEOH9XEwmqlRRhG49FulvAOy6LPhCl7kOvps 1yDrdpeQfSsDwaKlrfHksaAd1HGrH6fpQ9iisFdB2rvqWMJTGK4Sh4N7dpxpw4/ZC6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060196; 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=XgkZvR8AJevoy0RxzcR61uyxyAVDfD/QX7iLRvmcLjI=; b=5WyvUkNtIAjPDZpz62pZ00y3SO2fkhCDv6XJtu67h5qR5Yt3VRLROknXgbmpxJW8K2r6 EEqRonXp4BB6o/5pPzFvLWBhSUo/Kxv1dV2+r6CD0j91RbanAtizjPoYvbBjfHkv1ocng Z16V34vh5UNT738sopqEf+/e85B7W7quLHcOIhp5ocELwgSsUsIRmb465Q3h/T+jPKk0e mM7IqaNSNDrGefvZ4OxEkUcrQZD1Fooz6GD1epdkDmTKkoXOLIQNgaDMe8nGDahRfjCf3 8jjhFrkh7nXMVIjMcz0ylrSYfqD66Je4vgX6+4AfwQ/brdMytdhXZmSGvTIR3C46TSQ== 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=VlAJt9+E; 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 3C9C6606A31C for ; Mon, 30 Nov 2026 17:36:35 +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=VlAJt9+E Received: by smtp.kernel.org (Postfix) with ESMTPSA id D54491F00896; Mon, 30 Nov 2026 17:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796060195; bh=XgkZvR8AJevoy0RxzcR61uyxyAVDfD/QX7iLRvmcLjI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=VlAJt9+EutfGvrO0JbrOWFCR94KFS5cY5sCpc52bLwuJjhoDHxRNnLpJJfd8el0Zs mfQY80RuSWcsKKAibElSNz7WFguBixnCuIEAa+u8SezaeuK0oje98/QyFEHc3JXnLJ fhTFKdn96/kRf0b7OiRcRTfihIyw37A49dRU0Q5eDGU4j3qmYW5gefVX0QAvt1Ql5l B/99T9eE0gQ5iK8lFL5FPy5t78GRcxu833clsC4n+ZY7SGOJ+mbyW3iRSca0ls8a2S SUlareLqPGl9kscrhTdNKbe4+Kbb+lwvG6SlUqaI9cmSp7yz5586F8GuUUWqZ392sk XmGwQ4XTSwzDA== Subject: Re: [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() 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:34 +0000 Message-ID: <179606019437.3146.10783592066760126998@kernel.org> In-Reply-To: <20261129163327.893403-3-willemb@google.com> References: <20261129163327.893403-3-willemb@google.com> X-sashiko-severity: Medium 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: 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