๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10156

Re: [PATCH 02/14] xfrm: interface: validate the IP header on xmit

#10156
From: Steffen Klassert
Date: Tue, 03 Nov 2026 09:34
135 lines
14417 bytes
On Tue, Nov 03, 2026 at 08:05:00AM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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?

Not a regression of this patch, just a missing path.
Can be fixed by a followup patch.
Technical Details
Message-ID: <aumqnmq4CORk6k_7@gauss4>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355328-linux-kernel-netdev=dewy.ru
References: <20261102100451.2505200-3-steffen.klassert@secunet.com> <179369310046.488856.2145189284558172500@kernel.org>

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-355328-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 02/14] xfrm: interface: validate the IP header on xmit
Date: Tue, 3 Nov 2026 10:34:22 +0100
Organization: Usenet Network
Message-ID: <aumqnmq4CORk6k_7@gauss4>
References: <20261102100451.2505200-3-steffen.klassert@secunet.com>
 <179369310046.488856.2145189284558172500@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3133441"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:r0b40tW0iKp5Kcv5WkxtzrROk9w= sha256:9NFJT/KfWmBLL0HIkvRHHNMJtYCZoai80tvq/sOi6lc=
	sha1:UznxAwAR/Ejy9IlH3i2zEkbhDlo= sha256:n0FGi4wztuE/I28UL6cL+/BqLZMJV5S11M4Jkr3SwSo=
Content-Disposition: inline
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 1A63A11279A; Tue,  3 Nov 2026 12:41:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	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=secunet.com
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 PafM2YonPsRF;
	Tue,  3 Nov 2026 12:41:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-355328-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0D37B1127A3; Tue,  3 Nov 2026 12:40:59 +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 F33172FD32; Tue,  3 Nov 2026 09:34:29 +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=1793698469;
	b=P6P/gWmQKZXVGkV9iVQEmZBMcFKdUMV6e2nqV+cOivLBoKdazAVYXWtDOGtDr4z6LmUq
	 1dMyIidb5+4hF5W75ylM9PulF6NpNUfYrRH2l622TydV78qTz6XJCvH2kxPAUfA1nqpIX
	 vM3tM7AGDdSh1IN6jWvE7EqUCmxL7Pi2OM/zoP70oYIeW8Bm6nVAuC5Oiuvsmr/rDLiih
	 FwmVEsuWCFGBANzNljSsWh1X/kpz5lfb0rIFTOqLC6WGyTQuTV+J5tuEV9oc6vg40AZmC
	 mWMKkYGaZP5N2Q3sLENb2NxRsIT6SS4JOENEoog+AO9Pf9vNIceSWSmtaMF2TY5Mj7Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793698469;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:Date:
	 From:To:CC:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy;
	bh=XtO6LfrZVzR61+jJKzdUgwqYUQbw+cj9b2KqBtOJGgc=;
	b=sqnXyeV/BJCz4JHYM12vHD8gwHJw8XozHrSD7fAaPq5cyV34uGC5ogBe0jHXJrhb+VpU
	 imFIsC8uaEf+haakwj5Fd605AW8/XbIy3N5spvKVZOQbGrwMHVSfmw6xGIjJtPdYUkKOt
	 0F7+192aQ+SxZns7QILFRxd5+8CqZckHNe6ecG51T0TC8bvinGXge+vrQFrXhnsVuzrtN
	 tTWkaCKPPPiVQ4TNFSqLd6BXrQvUY2Ov17qEYRBjpB9Mc0H55cFLGdn/1zuVwpiIHi9ix
	 rSCJcJ0BME2hxOOFaws9szkgI2jJfymtK3RTcljJLeyO835+ZYhvwrDSAKTI4p7FRcA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=CCuUNukn;
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	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 1FABB606A330;
	Tue,  3 Nov 2026 09:34:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=CCuUNukn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793698468;
	b=RfZufreD0IWpeYtwIgXVZMPe9DvauNAxnd05otLLXQ268lwVVxTZ38BLcsBukxq3n96L
	 UUXrW0C6eGNNHc1kW4XJ6hiZPgXsnkwpzxmxUszRLjZFz66i67z8JmKJlV2O0w0ucqZJD
	 INIh16wy+SrO9Gu5DMeswMGJN+YjTrEHZwEFVQYF8NLQljpRiZTESf0v55uaW0/mmQ4gO
	 8zvK6iXqEInCV/9TDhHRBwkouls7fhz/nU92st2pBGbLmnGuIPj64R71p/ygt0btFmjAT
	 W6gpw6amImFooL4+zoSndPaKP5NptSKqH1bI4xNqjHB8Eo4dLsoZizTBzmelSW0VwBw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793698468;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy;
	bh=XtO6LfrZVzR61+jJKzdUgwqYUQbw+cj9b2KqBtOJGgc=;
	b=CjViSqAUZSQOnR4thIxNko3RDwL2K4LOgIrPmBBxpGJoQ+LGTGKgh7RVyZpMEgP5rwWQ
	 0bwszdRd5Kow1Wn6RwkxDXaYsAvj9+SXRMwRcA6rp3hblY124bXn4t91Y7mhJniuiiBxn
	 Oxyi+WE6scfAs+OgFSX0e94XDIGftu8N2+YdJF+uQD7EzUYNUzwcDylcRDiITn+ENC0B3
	 8GQlvsJA1pD8y8Kmytzfn+0InNu6N0Ed9NBP0u6lt2iN3Iw6ulDUZVl6sAnE9vh6vSNy3
	 K2HKgFTrKIwhPOqenpwLmpu/vAkNzbiE4Vv+VLycuWEyFyoXCU48Q+bGc6txDUbarbg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=CCuUNukn;
	arc=none smtp.remote-ip=62.96.220.36
X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86EAA606A324
	for <netdev@vger.kernel.org>; Tue,  3 Nov 2026 09:34:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86EAA606A324
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com
X-Received: from localhost (localhost [127.0.0.1])
	by mx1.secunet.com (Postfix) with ESMTP id 8E7BC201AA;
	Tue,  3 Nov 2026 10:34:24 +0100 (CET)
X-Virus-Scanned: by secunet
X-Received: from mx1.secunet.com ([127.0.0.1])
 by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id q70V1dalfaGg; Tue,  3 Nov 2026 10:34:23 +0100 (CET)
X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mx1.secunet.com (Postfix) with ESMTPS id D6F3B20184;
	Tue,  3 Nov 2026 10:34:23 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com D6F3B20184
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1793698463;
	bh=XtO6LfrZVzR61+jJKzdUgwqYUQbw+cj9b2KqBtOJGgc=;
	h=Date:From:To:CC:Subject:References:In-Reply-To:From;
	b=CCuUNuknDaKoBt1fGk76DQHARQ+Ok8QMgbJgB/QyJaJyS7epLbweVibl4QVxIvlaD
	 bC7FccaOvgafHPit9RcDcaZWQjlzyF5sd2EDZB4d/tgVjyEfwLIqVL9PIA380+pNZB
	 jwOd2rY+H21YDcPqxm5K/meOMqZDRJB+wSSKwuEsY4nYvy0Jr/xyVkObic5NvMdBYr
	 5dd5DIe1I50oqCZVSScfFdOAdMu10YojYwnUTLO1rGv+PTJlxAnHsDqrbQKvEbwI+6
	 WOhkpPKbA/JHBww/5YpXpN3OFSAzqwWEhTQoabta36w0fiSLxnyeySJo34atVSQeZf
	 tffd++NeUoung==
X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 3 Nov
 2026 10:34:22 +0100
X-Received: (nullmailer pid 3726600 invoked by uid 1000);
	Tue, 03 Nov 2026 09:34:22 -0000
X-CC: <davem@davemloft.net>, <kuba@kernel.org>, <herbert@gondor.apana.org.au>,
	<netdev@vger.kernel.org>, Qihang <q.h.hack.winter@gmail.com>
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
X-In-Reply-To: <179369310046.488856.2145189284558172500@kernel.org>
X-ClientProxiedBy: EXCH-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de
 (10.32.0.171)