Article View: linux.kernel.netdev
Article #10112Re: [PATCH 02/14] xfrm: interface: validate the IP header on xmit
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 08:05
Date: Tue, 03 Nov 2026 08:05
136 lines
12489 bytes
12489 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท 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] In xfrmi_xmit() (net/xfrm/xfrm_interface_core.c), the new
header checks look only at skb->protocol.
--
xfrm: interface: validate the IP header on xmit
This patch adds a pskb_inet_may_pull() call to xfrmi_xmit(). It also
drops packets whose IP version does not match skb->protocol, and IPv4
packets with a malformed ihl. The aim is to stop xfrm4_transport_output()
from working on an unvalidated header when packets are injected into an
xfrmi device.
> diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c
> index 688306bf62c5a..9835fbe63ccb8 100644
> --- a/net/xfrm/xfrm_interface_core.c
> +++ b/net/xfrm/xfrm_interface_core.c
> @@ -531,8 +531,13 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
>
> memset(&fl, 0, sizeof(fl));
>
> + if (!pskb_inet_may_pull(skb))
> + goto tx_err;
> +
> switch (skb->protocol) {
> case htons(ETH_P_IPV6):
> + if (ipv6_hdr(skb)->version != 6)
> + goto tx_err;
> memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
> xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6);
> if (!dst) {
[Severity: Medium]
Can an skb marked ETH_P_IPV6 pass this check and still reach
xfrm4_transport_output()?
The new check in xfrmi_xmit() looks only at skb->protocol. The transform
that actually runs is picked by the dst family, and then by
x->props.family.
When skb_dst(skb) is already set, xfrmi_xmit() skips the route lookup.
The dst family is never compared with the header that was just checked.
In collect_md mode, xfrmi_xmit2() also swaps in a different dst after
this check:
net/xfrm/xfrm_interface_core.c:xfrmi_xmit2() {
...
if (md_info->dst_orig) {
struct dst_entry *tmp_dst = dst;
dst = md_info->dst_orig;
skb_dst_set(skb, dst);
...
}
xfrm_lookup_with_ifid() then takes the policy/state family from that
dst, not from the packet:
net/xfrm/xfrm_policy.c:xfrm_lookup_with_ifid() {
...
u16 family = dst_orig->ops->family;
...
}
A tc BPF program could reach this with the following sequence:
bpf_skb_set_xfrm_info()
info->dst_orig = skb_dst(skb); /* IPv4 rtable */
attaches the per-cpu metadata dst
bpf_skb_change_proto(skb, ETH_P_IPV6)
skb_valid_dst() is false for DST_METADATA, so the metadata dst
and the IPv4 dst_orig are both kept
program writes an IPv6 header with version 6
xfrmi_xmit() /* dst != NULL, only version check runs */
xfrmi_xmit2() /* collect_md swaps in IPv4 dst_orig */
xfrm_lookup_with_ifid() /* family is AF_INET */
...
xfrm_outer_mode_output()
xfrm4_transport_output()
A plain IPv4 rtable does not survive bpf_skb_change_proto(), because it
drops non-metadata dsts. So this appears limited to the metadata dst
ordering above.
With an AF_INET transport mode state, xfrm4_transport_output() takes ihl
from the low nibble of the IPv6 header's first byte. That nibble is the
top four bits of the traffic class, so it can be anything from 0 to 15:
net/xfrm/xfrm_output.c:xfrm4_transport_output() {
struct iphdr *iph = ip_hdr(skb);
int ihl = iph->ihl * 4;
...
__skb_pull(skb, ihl);
memmove(skb_network_header(skb), iph, ihl);
...
}
pskb_inet_may_pull() only made 40 bytes linear for IPv6. For a small
packet, skb->len can wrap and the memmove() can read past the end of the
data. If the skb has paged data and a linear length under 60 bytes,
__skb_pull() hits BUG() instead.
One step has not been confirmed end to end. It is not certain that an
AF_INET policy/state lookup matches a flowi that xfrm_decode_session()
filled in as IPv6. It looks plausible with a 0/0 selector, because the
ip4 address fields overlay ip6 address bytes that the sender controls.
This path also needs CAP_BPF/CAP_NET_ADMIN, a collect_md xfrmi, and an
AF_INET transport mode SA and policy.
The commit message says:
"xfrm4_transport_output() uses iph->ihl for __skb_pull() and memmove()
and expects the header to be valid."
Would it make sense to also drop packets whose final dst family (after
the collect_md dst_orig swap) does not match skb->protocol, so this path
is covered too?
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102100451.2505200-2-steffen.klassert%40secunet.com
Technical Details
Message-ID:
<179369310046.488856.2145189284558172500@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355272-linux-kernel-netdev=dewy.ruReferences:
<20261102100451.2505200-3-steffen.klassert@secunet.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355272-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 02/14] xfrm: interface: validate the IP header on xmit Date: Tue, 03 Nov 2026 08:05:00 +0000 Organization: Usenet Network Message-ID: <179369310046.488856.2145189284558172500@kernel.org> References: <20261102100451.2505200-3-steffen.klassert@secunet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3119438"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:PrH55MMG0PZ76SsnkSi9RPHyRRs= sha256:awAN57H1/BLMp4XjsvllJWV8j3y/8kIZVOPCp/xqvDQ= sha1:BNuRcHrHlz1DB/9ovNry6kh9E6M= sha256:UJx4t7ZjLr8oYNbHv7+8Eiay8hzdJ4m9/9aT1Cg92ZA= 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 AC3E3112768; Tue, 3 Nov 2026 11:09:35 +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 ViFd1Cs1ByjC; Tue, 3 Nov 2026 11:09:32 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-355272-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id C471C1126DB; Tue, 3 Nov 2026 11:09:18 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 340BE2A50F; Tue, 3 Nov 2026 08:05:05 +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=1793693102; b=icGBSktx7SMuWBfFGTh8trJ1yqU7TFbwga1hs5miRJa1+ApovQY6GaFp7q36XQ8ZXAgT onlBxuME39yzYzajVwvy1Mbd3LweFU8034OmXSP/dTswpQscKCfOIldfMbhXGbAt69+Yy f3/EpFANBRSBdfFkWZTZNOAZ7tHv2QU7+b2aOjVxHhkarfbNrkYmkymNOCzGCs1S9uRIE S62Swqj6qTNTq2rkkShwZW4qK9NseA6AGhQHWwdvcDsTLMquMiv59KwUFddzvzQ+4dNEz /tb4Std2YN7Ztv+2WeTtq8gw6CYCbqA6kl9v6pwGFcTg6yyogiv2+JSRQJlGfVPvJOA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793693102; 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=Is/N+iZUjDfSN1sneuH4OTqgyHfI3K+lOnHcdE9f2kI=; b=SJyRhD2l8fRARJSUzZ2fHgSePIs0FxRo8gBhzrfjEBRJcOPP7maDiN+Hx5CkZRg4Eq8K D1KblXO1YR9U3mZMfQVg429gPZZBSfVCCkjvdA0WOGnjahVI2+irYqZar1w0K/pexBkW9 F3SPmuF8EcJy7gaK/+Q4kCEoANNq+xhp1UZIgsVb4hvOK1Tzmv4s4EZSk0XXa/z8bzmUo 5J2fI2V/tVyS5Mpa4LTJSOtgBexgavDF7VoovMmXZq6KqgGph5IErpqSizBTgib7ZZLCv lYb0g6/kxwAeZw7L5Lmn50mRuePtbPMj4aJzEL3iId0OzGj+q0NnAJdMi/H16L9ah+g== 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=lTeTSc3Q; 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 86574606A331; Tue, 3 Nov 2026 08:05:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lTeTSc3Q 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=1793693101; b=Rk1rqdbhmhTvzggUpaarqMYsFEYo7ANKxcHgAJHr9iPg7k9UbfjB8DYmTgTCrJSIiH5I U1w/apgGLVrkCeSo8Lh7CF87owSUXPbPUh+UIC7Iy9hjTlvvyrMKjnrzIroQ8Nv6QN4AQ 9N1CfLQEaaDA69WqOS7sgavX239DVjlBuc7RlkrV6d3zsIKs4fY2HEFkjG7S25FpmTuuS /+1kT0UKf54sVlQYdTIa1A39SMG+L86espACA0oyY94VJfYKCYmQsmrQnIFjzM98qW2ie cRgGUbHxTBL582CT+56aWOjOsjP7KhMm66ljcZpnPfJOT10nmXJMS5QSk9JzNdd647Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793693101; 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=Is/N+iZUjDfSN1sneuH4OTqgyHfI3K+lOnHcdE9f2kI=; b=J7oeyWXP2HwlUCKp3ZoHZwHLXJLb4b7a07QAAL4z0tdL/duyet52nzpCCatcPt4Ahibr WtKtBakCXmHEXWNUqIyjsBS4Z5iRUYjm/1Ig6LpJ3Xl5dS5/MHRVlSJYqiYmF+e1ZNCkA 20tSNkjEm++xds+5g/thIVnRrQLUOyCMs5LuBx9I5PvTZSOwwsN4JZ8ycT+fXoOhiXO6G ka38x5oY/Cw7oJj4xzU8zho2Rv7sr0Ne8c1HlfS2zSr9aGGWcIhVMkv3ZEoisgouGB2By R52HX5ybloEF/GI4GwYREXhN+R5sCjdVszkoM6dyUcgtRYpsw+ls96PDxnfrDqu9VrA== 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=lTeTSc3Q; 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 61D96606A329 for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 08:05:01 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1C1E1F000C1; Tue, 3 Nov 2026 08:05:00 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793693101; bh=Is/N+iZUjDfSN1sneuH4OTqgyHfI3K+lOnHcdE9f2kI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=lTeTSc3QfYhWvuPfAwmmfB5lR1QE5T49UChRIxT4UelAEjq5Kvh3RqWFpAPm0RKqm fKSlWpSz6fHH1eVfOJeiiHC7GCgtEn8f3uMvlkGvEUZrkKyNPoy5ywBOolwNWLzQre JUH1oBijiFJk4HEFGSFNuIVY5tvXTe8P6tABoVwQM09En4O20hazimhsatFW3R2Boh uFSjHOtecr+fEONySdblZRn7Iy/1kdrHmQKOBVWvCJu91+AuxkXQ3s6Y/+hKWNzF1j YZ77toCQIdNdTCJgl7dIJN/FOD27YQSQ/5kh5PkxLA4gstQpQ+t/miYrUGUVnFlD9W zSQoKkKHWJOAA== X-Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au, netdev@vger.kernel.org X-In-Reply-To: <20261102100451.2505200-3-steffen.klassert@secunet.com> X-sashiko-severity: Medium 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