🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26789

[PATCH net v2] net: mpls: clear stale inner state on pop

#26789
From: Lin Jiapeng
Date: Fri, 04 Dec 2026 07:06
107 lines
15671 bytes
From: Lin Jiapeng <jiapenglin@tencent.com>

Commit 78a86d75a70e ("net: mpls: clear inner_protocol when the last
label is popped") made skb_mpls_pop() clear the saved inner protocol when
the next protocol is not MPLS, so a later push records fresh inner state.
TencentOS Corvus AI audited the remaining Open vSwitch MPLS fragmentation
paths and got a KASAN slab-out-of-bounds report in prepare_frag().

That fix was incomplete. When every POP declares an MPLS next protocol,
an excessive pop can advance the current network header beyond the saved
inner_network_header without satisfying the clearing condition.
ovs_fragment() copies that stale offset into network_header; on an L3 port
it becomes -4, passes the signed MAX_L2_LEN check and is widened to an
unsigned memcpy length. Ethernet ports can also retain positive stale
offsets, so a negative-only downstream check is insufficient. The L3 case
produces this report and panic:
  [   44.274264] BUG: KASAN: slab-out-of-bounds in prepare_frag+0x3c2/0x4c0
  [   44.274757] Read of size 4294967292 at addr ff110001069fc044 by task ovs_frag_trigge/131
  [   44.275681] CPU: 0 UID: 1000 PID: 131 Comm: ovs_frag_trigge Not tainted 7.4.0-rc5 #1 PREEMPT(lazy)
  [   44.276170] Call Trace:
  [   44.277460]  __asan_memcpy+0x23/0x60
  [   44.277531]  prepare_frag+0x3c2/0x4c0
  [   44.277606]  ovs_fragment+0x578/0x860
  [   44.279078]  do_output+0x33e/0x5c0
  [   44.279210]  do_execute_actions+0x5eb8/0x7800
  [   44.279748]  ovs_execute_actions+0xdd/0x420
  [   44.280105]  ovs_dp_process_packet+0x23b/0x570
  [   44.280405]  clone_execute+0xe9/0x670
  [   44.280495]  do_execute_actions+0x16af/0x7800
  [   44.280987]  ovs_execute_actions+0xdd/0x420
  [   44.281155]  ovs_packet_cmd_execute+0xd69/0x14a0
  [   44.285198] Allocated by task 131:
  [   44.285393]  kasan_save_stack+0x30/0x50
  [   44.285738]  __kasan_kmalloc+0x7f/0x90
  [   44.285830]  __kmalloc_node_track_caller_noprof+0x27e/0x6d0
  [   44.285906]  kmalloc_reserve+0xc4/0x2f0
  [   44.285982]  __alloc_skb+0x143/0x650
  [   44.286062]  __netdev_alloc_skb+0x5f/0x6d0
  [   44.286157]  ovs_packet_cmd_execute+0x21a/0x14a0
  [   44.287020] The buggy address belongs to the object at ff110001069fc000
  [   44.287020]  which belongs to the cache kmalloc-2k of size 2048
  [   44.287125] The buggy address is located 68 bytes inside of
  [   44.287125]  allocated 2048-byte region [ff110001069fc000, ff110001069fc800)
  [   44.290904] Kernel panic - not syncing: KASAN: panic_on_warn set ...

Extend the existing invalidation in skb_mpls_pop(): after setting the
current network header, also clear the inner state when
skb_inner_network_offset(skb) is smaller than mac_len. Set
inner_network_header to the current network_header together with clearing
inner_protocol, because OVS can fragment immediately after the POP without
re-extracting its flow key. Packets whose inner header remains at or after
the current network header keep the old behavior.

Reproducing this needs CONFIG_OPENVSWITCH, CONFIG_USER_NS and
CONFIG_NET_NS. From uid 1000, create a user and network namespace, use
the OVS netlink interface to create a datapath and an L3 flow, install
MPLS push/pop actions and an output action with MRU=100, then execute
IPv4 and IPv6 packets through that flow with OVS_PACKET_CMD_EXECUTE. No
race or special hardware is required. The unfixed kernel emits the report
above and panics, while the patched kernel completes both runs without a
detector report.

Fixes: 78a86d75a70e ("net: mpls: clear inner_protocol when the last label is popped")
Cc: stable@vger.kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v2:
 - Move the fix from ovs_fragment() to skb_mpls_pop(), extending
   78a86d75a70e as requested by Jiri Benc.
 - Cover positive stale offsets on Ethernet ports and invalidate the saved
   inner_network_header for immediate consumers.
 - Rebuild and rerun the IPv4/IPv6 A/B reproducers and functional tests.

v1: https://lore.kernel.org/all/20261126083218.55429-1-ljp1205831794@gmail.com/

 net/core/skbuff.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 85d5caa08887..df700fb9f409 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -6834,12 +6834,15 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
 	}
 	skb->protocol = next_proto;
 
-	/* The last label is gone, so the inner header recorded by
-	 * skb_mpls_push() no longer describes this packet. Drop it, or a
-	 * later push keeps the stale offset.
+	/* Clear the inner state when the last label is gone or the recorded
+	 * inner header precedes the current network header. Point it at the
+	 * current network header so consumers cannot reuse a stale offset.
 	 */
-	if (!eth_p_mpls(next_proto))
+	if (!eth_p_mpls(next_proto) ||
+	    skb_inner_network_offset(skb) < mac_len) {
 		skb->inner_protocol = 0;
+		skb->inner_network_header = skb->network_header;
+	}
 
 	return 0;
 }

-- 
2.55.0
Technical Details
Message-ID: <20261204070712.82311-1-ljp1205831794@gmail.com>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377129-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377129-linux-kernel-netdev=dewy.ru
From: ljp1205831794@gmail.com (Lin Jiapeng)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] net: mpls: clear stale inner state on pop
Date: Fri,  4 Dec 2026 15:06:12 +0800
Organization: Usenet Network
Message-ID: <20261204070712.82311-1-ljp1205831794@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2698774"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pkm6YePlD3xl8X29DgS7dga1Elc= sha256:XEfKSrSrGd8qDdsP+ehfhAJPc8oTTUMHwWI2/cENbPY=
	sha1:FmQO2fawn4MD3Zh8F2t9n0qMxc0= sha256:VutvOslYJOfGBlHHFh+sevICKua/iH96rnvai0jU7zo=
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 53E4F117B3D; Fri,  4 Dec 2026 10:07:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.297
X-Spam-Status: No, score=-3.297 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001,
	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=gmail.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 UbDBEriJWhMk;
	Fri,  4 Dec 2026 10:07:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377129-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 2B42E117B3B; Fri,  4 Dec 2026 10:07:34 +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 C857126022; Fri,  4 Dec 2026 07:07:27 +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=1796368047;
	b=vGpe0epWyOiRvI6jRCIXRUZqa9CM8D+CAyZMIAjxBkOGDoybTPaoXyLubr2ml+cUzeFV
	 REQimMOEUkxd3POMxncLVTiGZaRYghjkFuUBK1DEm+r2TcA8pXMArR+kernLXXYZMoWxS
	 p2qkAOfVgJ1V8zReOUmHF2bIcuEalZAWkTvRNnZEkthiNgQwolaY+NMlNpy/81kMA1e57
	 7LYpx4gclMk+isA0BU3kH6+CdFVBt+y7daEzLGQ9sthsqELougE/kZU3ic0wqpBXgyhYI
	 P3LaqsimwXbdY56l2wFl3qeOzT8R7IXyGY31AExJzaEB9KWKVv2/dv32LWaMbTP9Glw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796368047;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=A8XAABXIyspm/ZYHFy4Tz8vWVb6kzDOthViu0xBUoPg=;
	b=D6rr5wiCaOS3UT8HBrwZYBR/Qh8rRHoUh+bLu4hrwp63YqswG4zbsDvbyTfKbtQX131/
	 6zB8RRSYFOUYaQhydZTOoAuTzXIVQa7rXrV/L1MDjYtvW4KTc1NXgm1kyS7H7HWf3A9zH
	 j7NzttMzyEYCcCzgTBOUo4ftidFFxITITUmdJTLL6IGVuB++qcQLeaNhaJ1zOKD0jU6mE
	 v439etDrdek5WygSIx00y3LtpiwVkw5pQxYNR53l32XnYxhdfLSGX4McOk01EwHPeN1yw
	 r6eH5kjHcGGm6fu0JeWYkGjSrkO7LyrKw6aK6lXfBkkdalIm3/LzLeDPp39w5X9jW3g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oHsj9Kqo;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.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 DEBF9606A32C;
	Fri,  4 Dec 2026 07:07:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oHsj9Kqo
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.175
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796368046;
	b=JjKEX0b/RDe8zKoiEVnCji3GYLFif3+JfVwdpKyBk49gnqDp2N2K3wdz67I7K3fJ2D1+
	 GGeUGDNcbmIwkYXg7aKE6lJ4eIoY9Ct5XdjuVUyR50GGGGBqL76X9fFj6TgGBHOdvyKwv
	 pNB9/4nvQyqTMNKi94q4bmO5mn/tYVsblIHjUftRLYc98e/sA5ilpXTQFvjOSblArIQLS
	 J/IPZ1ov30ny8PuDzYuuoC9S+s5wDz94hIowtrcBiN8pgsQXs+4GqOpktY9jAWq4INpjj
	 GeS69BvvwbYetaxCmkb1O3osBFg2DURBlVk3E3CVLsLSAiEY/Gzd3X8NixfKJEH/g7g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796368046;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=A8XAABXIyspm/ZYHFy4Tz8vWVb6kzDOthViu0xBUoPg=;
	b=r/dZGwD+qp3eUmUVyyuZqIjZN7SkV2Q6zGUTRi/vfQ1uYhFbaG15OFydLx9gqXE2cudD
	 V1FfucsHfcvD3Blq515TnVo076cXc7Yh0UyDTcjDGMHxpQR+Sz9wDHu77SPlpA2tUJNsI
	 J55V86sNk4/zY6n90V1E/lUcTg3id6LRXTA2t+q21ylNpRS43rIadqT8sNv7qgmBV5s2N
	 YTtYpSVCkQTUQGE4UkdSCSJC+LxdHi40oV1EXLYz+Ywyy8Jhc531vV9SQ/JRsSAzocAyo
	 Xih0Aj67Dmqb1LSftD90t2MY+yXwq6Z83Nh5QPNXqQGhOjZdfoPtafx99qo4cbpj0Zw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oHsj9Kqo;
	arc=none smtp.remote-ip=209.85.215.175
X-Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A54FF606A322
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 07:07:25 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A54FF606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-cdb2893531bso247510a12.1
        for <netdev@vger.kernel.org>; Thu, 03 Dec 2026 23:07:25 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796368045; x=1796972845; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=A8XAABXIyspm/ZYHFy4Tz8vWVb6kzDOthViu0xBUoPg=;
        b=oHsj9KqoPdkiIUkaSYnexkCS66oWD8kYIYYKplUVQtAvnBw3km9HH+KmiwTTEZ7NGn
         fFR2f3f+svNHFGaLexab03DhmwabkKVcMIYho0Qpi5SwqrxbNn0JKHXOd//PgG+9tx4w
         Ytb6+puvffZdvA0bVfLmqkJXr4zcoBtraw3jkoxSWt2kdUvhV8JTIGOPOVGds4ERbqIB
         EODxMlJuR2SJ8O7F+c5D7kh4c8LmPVEaPC/wpzsr+QGsxdKKWncZD+2ndb30/SPGFUP5
         B4936q2SHUkscbbW8nqQkgW5ZlE++JDDpo2XksgVWr/5wvfkRkd66aH4Ve30xWSYxdIB
         3YZQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796368045; x=1796972845;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=A8XAABXIyspm/ZYHFy4Tz8vWVb6kzDOthViu0xBUoPg=;
        b=WIp+U+kORteW3PdRMBvSqCSaQ8QdOesWIawUNgF1N9wWQ+E5yx/7CKGJcU8FpzILE8
         usGt7gm3/oD7a7xOvKvtRCG3BtTOVSESkWpw1xlV4FB8sEJ5Dh+nbBV/1neuLlRPgooI
         ReHvWo04KPzfRekH7Z+i94KDw+WrF1YYDaD7PiIP4XnBX/8U+CBDMuSpHdlrY3tP+fJY
         DpHcOGrby2qBmWFiG+k/BfAPMQPDwe2y5IJ83ANlKE+baM7IwFRwGC4kVuPiPJHI/Hgf
         rXDhsHSZiaCeEBteQoa/xtXLk5Zhconzh7Ceuq7kodkGuIQb2q/d0ixIyd00jq+NcCbU
         B+pQ==
X-Forwarded-Encrypted: i=1; AL+hErGTQcFNXpbphuJY8q5JWNNeQNfksZivC/iHk3g6/uXC72sX6dJeaBgPBCXavefc3JvBhqfrGjM=@vger.kernel.org
X-Gm-Message-State: APuU4Z/NRN93wyQVUDtf6bidkYCUoa0QNfMa9zKkGgwSzHWkRzRMQzy/
	JckueAgsjioMT9qxtBMFEGGIuAuMwYDLrA0NgbWYh0gOtr1d+xojkTkh
X-Gm-Gg: AZFdTZfmu1ILqyWr5ZalmpsCNPSGBCaVCwlEdqXHyOS3PefAkDsB5x7zci4McUHfjfi
	8LLUYINs03SYEhg+C2ZSvA8NV181fNhp9vvV0SlurFNsRUSteJkV4x0SRB0jdYiJjSTrjZT7uw+
	8W59alU1KFF6VV54IarHus/Jb98r2TxogYrSUqRbsZr7XL/8xs8gZeUzhVpPcryZxtKrFcEQu3w
	i2rZ1Kdx3mpAep2g3bUKM6oTfS3w3JuoGI8Y1l8eJMexkxrgDyw05PHtfIEitfMcyxy5PusRVF4
	ADxOaf7V8AvPnDmhj3FFfrwR3uqKCFDJ2LH0xxkgwU0tGoh0Gu7nJyLuR6dVWbqf8lOYouTammS
	RJi4Sz0sRV/uYe0dzyXAUsbzyV5BkmPEts4mN7zu91Q76ZpoHzT4b3NPSAOZKG453wQaD6GJcEI
	/tnfjub0ozQgzMF6CSTCECIH+CMmmtqrKJfq09bldgccFh3pR32lteamAO7HGcij4VxJqteuhV3
	UpeXz3tMbaZMTVTX/DQqUsHe+cCDAFte17ZjddAMFfJ+oAZdkluwl1EKytr42w8LX42FG04ZgWB
	6iUYBLROXzwMAnaMEFm0xflF1XXfUUcnj8lOeI6CBbvUdjDfmidBbEW6Zmhsk1Hnca86lYgqULA
	=
X-Received: by 2002:a17:90b:53d0:b0:3b5:6f17:c2f1 with SMTP id 98e67ed59e1d1-3b5e06a4f49mr906371a91.63.1796368044476;
        Thu, 03 Dec 2026 23:07:24 -0800 (PST)
X-Received: from JIAPENGLIN-MC0.tencent.com ([43.132.141.21])
        by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc37998sm2380352a91.10.2026.12.03.23.07.20
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Thu, 03 Dec 2026 23:07:23 -0800 (PST)
X-Cc: Lin Jiapeng <jiapenglin@tencent.com>,
	stable@vger.kernel.org,
	TencentOS Corvus AI <corvus@tencent.com>
X-Mailer: git-send-email 2.55.0
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