🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26893

Re: [PATCH net] net: mpls: clear inner_protocol when mpls_forward() pops the last label

#26893
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 11:04
121 lines
12443 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] The patch fixes only one source of the stale state, not the
  place where it is trusted, so the prepare_frag() overflow described in…

--

net: mpls: clear inner_protocol when mpls_forward() pops the last label

This patch clears skb->inner_protocol in mpls_egress() once the last MPLS
label has been popped by mpls_forward() and the packet is IPv4 or IPv6
again. skb_mpls_pop() already does the same. The goal is to stop a later
OVS push_mpls from reusing a stale inner_network_header, which leads to a
huge memcpy() in prepare_frag().

> diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
> index ad4ad6f2001ab..e2e5da8d757b8 100644
> --- a/net/mpls/af_mpls.c
> +++ b/net/mpls/af_mpls.c
> @@ -361,6 +361,9 @@ static bool mpls_egress(struct net *net, struct mpls_route *rt,
>  		break;
>  	}
>  
> +	if (success)
> +		skb->inner_protocol = 0;
> +

[Severity: High]
This closes the mpls_forward() source. Can the prepare_frag() overflow
still be reached from other paths that leave a stale inner_protocol and
inner_network_header behind?

skb_mpls_push() trusts the recorded state. It does not check that the
packet is MPLS or that the recorded offset is still valid:

net/core/skbuff.c:skb_mpls_push() {
    ...
	if (!skb->inner_protocol) {
		skb_set_inner_network_header(skb, skb_network_offset(skb));
		skb_set_inner_protocol(skb, skb->protocol);
	}
    ...
}

ovs_fragment() then installs that offset, and its only check is a signed
upper bound:

net/openvswitch/actions.c:ovs_fragment() {
    ...
	if (eth_p_mpls(skb->protocol)) {
		orig_network_offset = skb_network_offset(skb);
		skb->network_header = skb->inner_network_header;
	}

	if (skb_network_offset(skb) > MAX_L2_LEN) {
    ...
}

A negative offset passes that check and becomes the memcpy() length in
prepare_frag():

	unsigned int hlen = skb_network_offset(skb);
	...
	memcpy(&data->l2_data, skb->data, hlen);

IP tunnels such as ipip seem to leave the same stale state without any
MPLS forwarding. Take two nested ipip tunnels and a packet that is neither
GSO nor CHECKSUM_PARTIAL (for example ICMP fragments):

ipip_tunnel_xmit()
  iptunnel_handle_offloads()
    skb_reset_inner_headers()     <- encapsulation was 0
    skb->encapsulation = 0;       <- not GSO, not CHECKSUM_PARTIAL
  skb_set_inner_ipproto()         <- shares a union with inner_protocol

The second ipip xmit also sees encapsulation == 0. It resets
inner_network_header to the middle IP header.

On receive, ipip_tunnel_rcv() runs twice, through
__iptunnel_pull_header() and ip_tunnel_rcv(). skb_scrub_packet(),
iptunnel_pull_offloads() and ip_tunnel_rcv() never clear inner_protocol
or inner_network_header. The recorded inner header now points at the
stripped middle header, 20 bytes before the real IP header.

Suppose the packet is then forwarded out a veth into an OVS port.
__dev_forward_skb2() does not clear these fields. OVS ct() reassembles
the fragments, and skb_morph() copies the fields over.

A push_mpls action then calls skb_mpls_push() with encapsulation == 0 and
a non-zero inner_protocol, so the stale offset is kept. On output,
skb_network_offset() in ovs_fragment() would be -6, and prepare_frag()
would copy 0xFFFFFFFA bytes.

This path comes from reading the code and has not been reproduced. Every
step needs only CAP_NET_ADMIN in a user namespace, the same setup the
commit message describes.

This would be the third point fix for the same sink. The first was
78a86d75a70e for skb_mpls_pop(), and the second is Lin Jiapeng's patch for
the OVS PUSH_MPLS/POP_MPLS path.

Would a check at the point of use be more robust? For example,
skb_mpls_push() could reuse the recorded inner header only when
eth_p_mpls(skb->protocol) is already true. ovs_fragment() could also
reject skb_network_offset(skb) < 0.

>  	return success;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179607412883.627473.3063198838105400446%40gmail.com
Technical Details
Message-ID: <179638227378.3146.17732161383387547386@kernel.org>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377276-linux-kernel-netdev=dewy.ru
References: <179607412883.627473.3063198838105400446@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377276-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: mpls: clear inner_protocol when mpls_forward()
 pops the last label
Date: Fri, 04 Dec 2026 11:04:33 +0000
Organization: Usenet Network
Message-ID: <179638227378.3146.17732161383387547386@kernel.org>
References: <179607412883.627473.3063198838105400446@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2746962"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tj2xQyeuKH5OwkK5jg5st+vloQ8= sha256:Iaf2VdYvtCJ0kvG0TJEzhFflnsRIED94CSKQC5DpnYg=
	sha1:HT5NmgahdwyCWEk/Akb3LY5KONA= sha256:C396RkUTcCUWTRG2a5yFooDtjQSqYTnUaPkzlMiuQGE=
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 D8D1F117BBB; Fri,  4 Dec 2026 14:04:56 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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, URIBL_BLOCKED=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 gDwk6R4ghnQh;
	Fri,  4 Dec 2026 14:04:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377276-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 30EE8117BA5; Fri,  4 Dec 2026 14:04:42 +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 7590F283D9; Fri,  4 Dec 2026 11:04:36 +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=1796382276;
	b=2PkxKJLdZPqx38mj67R+xwCgLGi7cHmrnIXGU0+W7jXctnGYq640Gyksptlc/oradnW3
	 QNlHudPkh3oJaKAaNkctyND6uSDA3VosF3eSpVjroHQBllJbvRymNTgap1ZE1HlKWfD0K
	 YTXZduiI/YZknbWGHLzCkka1i+7UzVejdS1FM3hqDGChrEgwu74f3x5ieAaaN3dta0VC7
	 l6Ekruo17YJjGgxi3hdYOCIlAhPA/o8DUp2f/yj2vVBIuDyHz1Gwdh2WiYth9K5gISd03
	 DcwwqDPHjPvZdFatGtTSLnXT2VsKureQ1aW6BSGTL/j5tee9eBXJ9fBX9mNx6/ymt+A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796382276;
	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=WoCGAX0HaAWsuWksQ9blNy6RGug/fREPmVFITg9/67k=;
	b=WASMJExOvwh9AD6vCCeINV3eHCiDqZIUGYSzITvskaZiFjQzD+yio0g1iF9SGnq4s2Xn
	 TCcZhy/s+FUQaGYZDSX6jg7t7bKvxvN1nAGocV1GECzhbmibey3TUtFecFFowps0WliDa
	 rp2vO7lsOp/rfEwPgh/6u3wQvNPBStXCOmzb6zEpwTz37OjDeeQNcwZCDQIGY+Fvz7ZsL
	 fXoW0O/q2DepewmngYlwZkg/sFKT0zZajbMuRvac9xrNQSdCcLOBzu4RJwa9BYxRMwiQF
	 Wd3+o1SExVem3iihqFqXuGPmQVsUqnXRXQ5T+bvmr1LxxjvfeOyGePyi2yKzgJq+gdw==
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=oh8B5HME;
	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 034D6606A330;
	Fri,  4 Dec 2026 11:04:36 +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=oh8B5HME
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=1796382275;
	b=HZn9Sb2Upk6nGaMUZYmNA3Ilxo+HIPHHcRLyhHLM+LsInudrrTqvaXmtku6a329fpFGF
	 jJoc3T1XC3I8CS7ze6RDV+TeR9TwM/sdFQrQyLnUv6lMWpZeOTElmwtQSx087l/f+Qmpz
	 PgQRXsixeCQcEM8OStgWbInshaLgrojrCMrUhxeEpSTmjcGobuE0BFw5pDBHmjWDOLnUu
	 w1pdApGKmJQaKPuhrEcS7QvcslMzUvJwdrWr4Adckyt1oJDWQsiZRowc6PTcQdFavYbeJ
	 4WFZQFufg09gAjr9pIh+AEJJZp0fFJ9FO8j5X0s17cigLqEbyuskg8Ll7TLUnn7+5VA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796382275;
	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=WoCGAX0HaAWsuWksQ9blNy6RGug/fREPmVFITg9/67k=;
	b=iIgFnNPif/61sc1OiEEwJlb0baCnkTKCTXsl6yDD5AN+DSm+kLKvT9Pa7F8rIh0l1bhT
	 SSZoZeZ4fW2JfIfYSrpYW6qSE5/q8FN9VFhNAGgt7x1X8Ps0Dhbvetkizip1SpDW7oDuj
	 vL4isnM6T+etc0HFW7LVx47ay1ULwF1efMr97g5enhSbb6eAWppIRjffmcmMnXIHZSOrk
	 eKzTAVdOBhe7uGPTJ8GgBCQ+eLoFm4dXWIObKEe7+eTHAGQRr5CawJGujI+3O0LMsUsY5
	 X0j3KBhC9g3QE2m/pHPchIKwyuDoJlr4NRDPVrSpjVEACLOBsEoHSxpLnwMXnQF8n2g==
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=oh8B5HME;
	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 268CC606A336
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 11:04:35 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FFAE1F000C2;
	Fri,  4 Dec 2026 11:04:34 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796382275;
	bh=WoCGAX0HaAWsuWksQ9blNy6RGug/fREPmVFITg9/67k=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=oh8B5HMEfiJdBa8v0ZR3CP9xHg4JsZTPs+MlsA3/Am0IBHYT3n/9B9hdnVWr0VNAG
	 ElCT9vdMfTYV5oZwVmdHyRhHlHrOWlkV6ngAZCBLbHo37CfkNBSjz1Z6oNCzEOXJ1o
	 ffyc/T1GGviISd+7j98Wh0qJWtdJTsHIXg4rMDH6qB1afJ2qiVQ+yCtKdCtTRyvHEi
	 TuoJffdbsXNwl2IHTwabm+lPQB7Vp7vCmKguFjzDCzSug0AQsf8CcTFNO/tWurRKmS
	 A6yhl1WKBbvrxGwrXV2KfapKKKpp4l6FyVAx1QmrVtiu069TXmLUEMiYAYjPvYWqVp
	 Tt+uEYd3wwlew==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, willemb@google.com, horms@kernel.org, dsahern@kernel.org,
 littleddfu@gmail.com, aconole@redhat.com, echaudro@redhat.com,
 i.maximets@ovn.org, jbenc@redhat.com, jiapenglin@tencent.com,
 netdev@vger.kernel.org
X-In-Reply-To: <179607412883.627473.3063198838105400446@gmail.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