Article View: linux.kernel.netdev
Article #14913[PATCH net v4] ipv6: ioam6: do not modify shared tuninfo eh.nexthdr
From: Hangbin Liu
Date: Thu, 12 Nov 2026 05:46
Date: Thu, 12 Nov 2026 05:46
118 lines
13117 bytes
13117 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
ioam6_do_inline() and ioam6_do_encap() stored the next header into
the shared ilwt->tuninfo template and then memcpy()ed it into the
skb. The lwtstate is used from multiple CPUs without locking, so
another packet can overwrite eh.nexthdr between the store and the
memcpy.
The packet can then leave with an HBH nexthdr that does not match its
payload (e.g. TCP labelled as UDP, or a local packet labelled
IPPROTO_IPV6). Set nexthdr on the per-packet Hop-by-Hop copy after
memcpy instead, leave the shared template read-only.
Mark the tuninfo argument const now that the shared template is no
longer modified, and drop the unnecessary (u8 *) cast in memcpy.
Fixes: 3edede08ff37 ("ipv6: ioam: Support for IOAM injection with lwtunnels")
Fixes: 8cb3bf8bff3c ("ipv6: ioam: Add support for the ip6ip6 encapsulation")
Reported-by: Sashiko <netdev-bot+sashiko@kernel.org>
Closes: https://lore.kernel.org/netdev/179336082844.3134.1265197633714491521@kernel.org
Reviewed-by: Justin Iurman <justin.iurman@gmail.com>
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
The issue is reported by Sashiko. It was confirmed with concurrent TCP
and UDP traffic through a shared ioam6 inline route on a multi-CPU host.
Without the fix, a packet can leave with an HBH nexthdr that does not
match its payload (e.g. hbh->nexthdr=17 with a TCP segment after the HBH,
or hbh->nexthdr=6 with a UDP segment). With the fix, the same load reports
no HBH/L4 mismatch: nexthdr is written only on the per-packet Hop-by-Hop
header after memcpy, never on the shared tuninfo template.
---
Changes in v4:
- Use a temp variable for the ipv6_opt_hdr setting (Jakub Kicinski)
- Link to v3: https://patch.msgid.link/20261109-ipv6_ioam_lock-v3-1-a86195859d1e@kylinos.cn
Changes in v3:
- make tuninfo as const (Justin Iurman)
- Link to v2: https://patch.msgid.link/20261105-ipv6_ioam_lock-v2-1-8f0ea30c4ffa@kylinos.cn
Changes in v2:
- Add one missed Fixes tag. No code change.
- Link to v1: https://patch.msgid.link/20261104-ipv6_ioam_lock-v1-1-4f24c41b261b@kylinos.cn
---
net/ipv6/ioam6_iptunnel.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
index cfb2c41634a0..e8be0d922f74 100644
--- a/net/ipv6/ioam6_iptunnel.c
+++ b/net/ipv6/ioam6_iptunnel.c
@@ -254,10 +254,11 @@ static int ioam6_do_fill(struct net *net, struct sk_buff *skb)
}
static int ioam6_do_inline(struct net *net, struct sk_buff *skb,
- struct ioam6_lwt_encap *tuninfo,
+ const struct ioam6_lwt_encap *tuninfo,
struct dst_entry *cache_dst)
{
struct ipv6hdr *oldhdr, *hdr;
+ struct ipv6_opt_hdr *opt_hdr;
int hdrlen, err;
hdrlen = (tuninfo->eh.hdrlen + 1) << 3;
@@ -276,12 +277,13 @@ static int ioam6_do_inline(struct net *net, struct sk_buff *skb,
hdr = ipv6_hdr(skb);
memmove(hdr, oldhdr, sizeof(*oldhdr));
- tuninfo->eh.nexthdr = hdr->nexthdr;
skb_set_transport_header(skb, sizeof(*hdr));
skb_postpush_rcsum(skb, hdr, sizeof(*hdr) + hdrlen);
- memcpy(skb_transport_header(skb), (u8 *)tuninfo, hdrlen);
+ opt_hdr = (struct ipv6_opt_hdr *)skb_transport_header(skb);
+ memcpy(opt_hdr, tuninfo, hdrlen);
+ opt_hdr->nexthdr = hdr->nexthdr;
hdr->nexthdr = NEXTHDR_HOP;
hdr->payload_len = cpu_to_be16(skb->len - sizeof(*hdr));
@@ -290,7 +292,7 @@ static int ioam6_do_inline(struct net *net, struct sk_buff *skb,
}
static int ioam6_do_encap(struct net *net, struct sk_buff *skb,
- struct ioam6_lwt_encap *tuninfo,
+ const struct ioam6_lwt_encap *tuninfo,
bool has_tunsrc,
struct in6_addr *tunsrc,
struct in6_addr *tundst,
@@ -298,6 +300,7 @@ static int ioam6_do_encap(struct net *net, struct sk_buff *skb,
{
struct dst_entry *dst = skb_dst(skb);
struct ipv6hdr *hdr, *inner_hdr;
+ struct ipv6_opt_hdr *opt_hdr;
int hdrlen, len, err;
hdrlen = (tuninfo->eh.hdrlen + 1) << 3;
@@ -314,8 +317,9 @@ static int ioam6_do_encap(struct net *net, struct sk_buff *skb,
skb_mac_header_rebuild(skb);
skb_set_transport_header(skb, sizeof(*hdr));
- tuninfo->eh.nexthdr = NEXTHDR_IPV6;
- memcpy(skb_transport_header(skb), (u8 *)tuninfo, hdrlen);
+ opt_hdr = (struct ipv6_opt_hdr *)skb_transport_header(skb);
+ memcpy(opt_hdr, tuninfo, hdrlen);
+ opt_hdr->nexthdr = NEXTHDR_IPV6;
hdr = ipv6_hdr(skb);
memcpy(hdr, inner_hdr, sizeof(*hdr));
---
base-commit: 145480b28ca82e9fae789427cc4569e596515a32
change-id: 20261103-ipv6_ioam_lock-65102ca54908
Best regards,
--
Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID:
<20261112-ipv6_ioam_lock-v4-1-89e3381be525@kylinos.cn>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361528-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361528-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: [PATCH net v4] ipv6: ioam6: do not modify shared tuninfo eh.nexthdr Date: Thu, 12 Nov 2026 13:46:44 +0800 Organization: Usenet Network Message-ID: <20261112-ipv6_ioam_lock-v4-1-89e3381be525@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1020725"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Lpa7NyPm31hcnh2R/qvJii2qO4g= sha256:VeGJvK+g6fwHumGM3+IeLbcF17fF3noXpicEwQm1/6o= sha1:YwJ0GE2FK6/2Y1IPgB7+QkCF/YY= sha256:q1ljZ2prNUXO4XPb3ip6V/TUP00VGvcuiQ7GKrRgUUQ= 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 90BA4114115; Thu, 12 Nov 2026 08:54:06 +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 (1024-bit key) header.d=linux.dev 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 1d5xqAzSuvT8; Thu, 12 Nov 2026 08:54:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361528-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 1560B112037; Thu, 12 Nov 2026 08:53:52 +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 ABD9E4622E; Thu, 12 Nov 2026 05:47:11 +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=1794462430; b=hrPZwOyc3UNx8/TzEH/fEKo8cNvbnYtLbbqroC277r6uWoBGmnECVB1wliI8szhW4VpH o24O7DT2WB6XYQAaiTIqVg1fF0ClC7sS6h2mCJ2J7j0OTsRqLW/dVzCFp0CcLBXTzYMR4 iWensdxVejUD1s/6D5yuScqymYbpkWJFZRuekJghr9JTbNZEyOdU+BhoFZck2EfHQaz2G 4xEoLJPAOX8+F0R3YfYvC1jKVeOCeU9gEUJRRVEOzIi62u5krwHYa7/etZicbmvpoVIHM C7qpsQBvBpDqrnInnr3GGWVI7FFpQck4q9jTfS141xW6s6wWFp/yeLPh9uNrGOLpv+g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794462430; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc: X-Mailer; bh=f5zZSofPOE7pOeadwcOvAoWM5g2nJttE3jMN5ZTD1KM=; b=SUpG/qsgFOekOSMd99SHWgTmhs2SJkQmetbgtt5JEeLQIoLJywoazXU7aeTTVPRkd+nx q/04LXvHHm+TiS3OGafCBdnwekPcgBjTUT0OpEhKBCKBfXLRkQQQqEO99ADbVeVqOC118 NJ0vuWK7aSkTO5u5egzaEBu1CYdu47GhtG6xTL0chbc5wECEQsYuDzohOk9XQAbBtuDRy KeTxt7iDr6es12yWRoPOnSDUzNC8nsNpNajAO8AMyluiu9vpIrfBe3Gwd5GyIU1WOKWDE m1M5z6Qtvw+klG7epO+jxpRjiO33228h6iKVLZ2aTb5gwHe9AogN29PlayCPE44bSDg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=goivygNS; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 9C43A606A334; Thu, 12 Nov 2026 05:47:10 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=goivygNS X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.224 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794462429; b=pd9ppoK7s5BuD+m8H9Wg5cYAG+z1v49z8R6hn61zi8bZL+BxlM33UFaAloQnzeR3wrFb S1uBJB3vP+V7fpnyoMvTR2MLoIIxMuh1kc5WkvJ4ZaByDDwX2FqWqwWzIW2+HbE0G9mVx oM+8T4umW+XKwTtCYHd7AVPEgfHCCDZAJ+4cDUlnriunT86CqWHYeFvCmd2HAd+ARqceu nFtB71wgioJT3X2r7idH6Vhb60C7myCG3FcDXrXtgrbXP+FhCPrDJDMSXazGC3F6IhN1w xsskCB7wtI16xkqY5hWB3qkwl9vaR6f4ppYq2pieBO19FtE+WEaO52pR6278791rS4g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794462429; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer; bh=f5zZSofPOE7pOeadwcOvAoWM5g2nJttE3jMN5ZTD1KM=; b=k6iNTN37i1d/1O2TbQoDI9hwgy5wsj2VyH3AvGFHx1FUuiQKmSDG2TBn1WxGWcYcPfRm T2invjMNyMbqt42skINV+DD0UJJNBrdP1T86czlAdDa8ueuZFA8BEd5hJ0gxgH7XKEVvo eyq0EsiJvI2UgT42Fdj//abJ9s32XYO0Y29E2jTgeesS3Jwg6KnmAk01G7tadWAOdu8w8 kq1zsbvm2YbWNwf3ype3qyAz2TsqAO4zyoaOWt4fliBPEjG5qzDsChjWb3FJCfaMC2fnu Mz/0e0Bxv25KZl8xj/SZf0QihRODGIvIs3QvCSnHPJ4CgVz7gqy91fJ3bCjftfbAR6Q== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=goivygNS; arc=none smtp.remote-ip=95.215.58.224 X-Received: from mta1.migadu.com (out-224.mta1.migadu.com [95.215.58.224]) (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 C6814606A321 for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 05:47:08 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6814606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=Yc0v2vfQ0O7Xkps+Yu8K3w1Y6vmIMR7uOHhL3n0bXUY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794462426; v=1; x=1795067226; b=goivygNSyXEwoFusujkN+y4PjvFBczyVOWVYkNQ+cu4vcx5eR33089ezgBjje1JC/Wdv5KoX H8xYm5XRk0p2yOYEmxq0gpFtey0EbMZZSsOUygzEl6SoCO2nSyHvammUwPYmILaf21/TKCm9p+q dgtbQoJo+rf7tjT4WZNbf4uI= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta12.migadu.com with ESMTPS id 7497ed603e4f674f; Thu, 12 Nov 2026 05:47:06 +0000 X-Mizu-Trace-ID: 7497ed603e4f674f X-Migadu-Flow: FLOW_OUT 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-B4-Tracking: v=1; b=H4sIAAAAAAAC/2XNTQ7CIBAF4KsY1mIYCk3rynsYYygOOv5AUyrRm N5drC7ULmfyvvceLGJHGNly9mAdJooUfD7UfMbswfg9ctrlm0khSwBRcGpTuaVgLttzsCdeahD SGq1qUbGM2g4d3cbCNfPYs837Ga/NEW3/qnrFDhT70N3H2QRj+LOg/hcScODKSWUVNDnSrE73M /kQF9aP7Ul+ez3xMvvKCTSFsMo5M/HFt68nvsjeVCXUutL1DvDHD8PwBOYRwP9EAQAA X-Change-ID: 20261103-ipv6_ioam_lock-65102ca54908 X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hangbin Liu <liuhangbin@kylinos.cn>, Sashiko <netdev-bot+sashiko@kernel.org> X-Mailer: b4 0.16.0