From: Justin Iurman <justin.iurman@gmail.com>
To: Hangbin Liu <hangbin.liu@linux.dev>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Hangbin Liu <liuhangbin@kylinos.cn>,
Sashiko <netdev-bot+sashiko@kernel.org>
Subject: Re: [PATCH net v2] ipv6: ioam6: do not modify shared tuninfo eh.nexthdr
Date: Thu, 5 Nov 2026 17:13:05 +0100 [thread overview]
Message-ID: <2a63b050-ad39-4a32-ba68-4c9151dcfd15@gmail.com> (raw)
In-Reply-To: <20261105-ipv6_ioam_lock-v2-1-8f0ea30c4ffa@kylinos.cn>
On 11/5/26 10:34, Hangbin Liu wrote:
> 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.
>
> 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
> 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 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 | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
> index cfb2c41634a0..b23f8a0cbaa9 100644
> --- a/net/ipv6/ioam6_iptunnel.c
> +++ b/net/ipv6/ioam6_iptunnel.c
> @@ -276,12 +276,12 @@ 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);
> + ((struct ipv6_opt_hdr *)skb_transport_header(skb))->nexthdr = hdr->nexthdr;
>
> hdr->nexthdr = NEXTHDR_HOP;
> hdr->payload_len = cpu_to_be16(skb->len - sizeof(*hdr));
> @@ -314,8 +314,8 @@ 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);
> + ((struct ipv6_opt_hdr *)skb_transport_header(skb))->nexthdr = NEXTHDR_IPV6;
>
> hdr = ipv6_hdr(skb);
> memcpy(hdr, inner_hdr, sizeof(*hdr));
Thanks, Hangbin. This is a fix I had in my queue but failed to send it
due to a lack of time. LGTM, except a small change worth adding in a v3:
consider making tuninfo as const now that it's not modified anymore. Let
me add my review tag for v3 already:
Reviewed-by: Justin Iurman <justin.iurman@gmail.com>
prev parent reply other threads:[~2026-11-05 16:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 9:34 Hangbin Liu
2026-11-05 16:13 ` Justin Iurman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2a63b050-ad39-4a32-ba68-4c9151dcfd15@gmail.com \
--to=justin.iurman@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuhangbin@kylinos.cn \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®