From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D316146A66 for ; Sun, 12 Apr 2026 22:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776034303; cv=none; b=fb+IDvWSDwZXZIQcZGee75Mnu7lTzHunK4QlSQVN+7UGqV0EgtsRdMEVtxEoJrOxEXLGISEnA5cUCaPr82o1pf/fAs7CLwk9DsPHEgF/NmzV5AaPT3UbK5CHBVHPYQWDOg9WPILZUqIl4dtRhTRGwCtnJhwdCpRR4Daym5fGucI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776034303; c=relaxed/simple; bh=9QeYRr7hEjqnp69Cd116s2nHALLqQ2uz7slGWSXSBLE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DHvsZZT2hkzdo44xdSomxCXvINZLUk8wtLFaUyl7APwEi0U8CLhsjxAkVnwSlist26wWsHH+Q/6qg6OY+7u4oNF5VOt6w8ingbUHHixVoXGfWYtkQ7GUkCldw9AohxN7lac20Sq5fZgMg226unoubjXiOD+3hNKxhrANbMF34N0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p5se7dEo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p5se7dEo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 659B7C19424; Sun, 12 Apr 2026 22:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776034303; bh=9QeYRr7hEjqnp69Cd116s2nHALLqQ2uz7slGWSXSBLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5se7dEosGlrR/EpMKo3geiPXEX9iPAwJFMtfatm9+GGlmaB3evgpxp7oKQEhpcAR o2u2nli5bV38Ios34y+OldvDGCgbPK+gsd1OsmY2o5noE99TM4W/meveupPXMkhGt2 XbllIaj0tvL32pAshcBV59W2+ToMW2je5pS1yUA0m6yvvNwTL0EzTP/kCQRG28bdxM KY2QsdcnKamI7LuPXIHAFGcORentkoxxDLzrZen5M1VhyWfiETvyG7dIG0/cSfpTR8 U4nooiWHGwFyvhq6pQA57Fcuz+FwML9FnDaqhAnPLVuevDSgoxMfsxbp+M2ZoHflFF l2AAju9U+kZAg== From: Sasha Levin To: stable@vger.kernel.org Cc: Andrea Mayer , Nicolas Dichtel , Justin Iurman , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10.y] seg6: separate dst_cache for input and output paths in seg6 lwtunnel Date: Sun, 12 Apr 2026 18:51:40 -0400 Message-ID: <20260412225140.2461891-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026041205-decent-bottle-51e5@gregkh> References: <2026041205-decent-bottle-51e5@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrea Mayer [ Upstream commit c3812651b522fe8437ebb7063b75ddb95b571643 ] The seg6 lwtunnel uses a single dst_cache per encap route, shared between seg6_input_core() and seg6_output_core(). These two paths can perform the post-encap SID lookup in different routing contexts (e.g., ip rules matching on the ingress interface, or VRF table separation). Whichever path runs first populates the cache, and the other reuses it blindly, bypassing its own lookup. Fix this by splitting the cache into cache_input and cache_output, so each path maintains its own cached dst independently. Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels") Cc: stable@vger.kernel.org Signed-off-by: Andrea Mayer Reviewed-by: Nicolas Dichtel Reviewed-by: Justin Iurman Link: https://patch.msgid.link/20260404004405.4057-2-andrea.mayer@uniroma2.it Signed-off-by: Jakub Kicinski [ adapted cache field references ] Signed-off-by: Sasha Levin --- net/ipv6/seg6_iptunnel.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 986459a85fbd1..5da46c76d335a 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -45,7 +45,8 @@ static size_t seg6_lwt_headroom(struct seg6_iptunnel_encap *tuninfo) } struct seg6_lwt { - struct dst_cache cache; + struct dst_cache cache_input; + struct dst_cache cache_output; struct seg6_iptunnel_encap tuninfo[]; }; @@ -326,7 +327,7 @@ static int seg6_input(struct sk_buff *skb) slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate); local_bh_disable(); - dst = dst_cache_get(&slwt->cache); + dst = dst_cache_get(&slwt->cache_input); skb_dst_drop(skb); @@ -334,7 +335,7 @@ static int seg6_input(struct sk_buff *skb) ip6_route_input(skb); dst = skb_dst(skb); if (!dst->error) { - dst_cache_set_ip6(&slwt->cache, dst, + dst_cache_set_ip6(&slwt->cache_input, dst, &ipv6_hdr(skb)->saddr); } } else { @@ -363,7 +364,7 @@ static int seg6_output(struct net *net, struct sock *sk, struct sk_buff *skb) slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate); local_bh_disable(); - dst = dst_cache_get(&slwt->cache); + dst = dst_cache_get(&slwt->cache_output); local_bh_enable(); if (unlikely(!dst)) { @@ -384,7 +385,7 @@ static int seg6_output(struct net *net, struct sock *sk, struct sk_buff *skb) } local_bh_disable(); - dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr); + dst_cache_set_ip6(&slwt->cache_output, dst, &fl6.saddr); local_bh_enable(); } @@ -461,11 +462,13 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, slwt = seg6_lwt_lwtunnel(newts); - err = dst_cache_init(&slwt->cache, GFP_ATOMIC); - if (err) { - kfree(newts); - return err; - } + err = dst_cache_init(&slwt->cache_input, GFP_ATOMIC); + if (err) + goto err_free_newts; + + err = dst_cache_init(&slwt->cache_output, GFP_ATOMIC); + if (err) + goto err_destroy_input; memcpy(&slwt->tuninfo, tuninfo, tuninfo_len); @@ -480,11 +483,20 @@ static int seg6_build_state(struct net *net, struct nlattr *nla, *ts = newts; return 0; + +err_destroy_input: + dst_cache_destroy(&slwt->cache_input); +err_free_newts: + kfree(newts); + return err; } static void seg6_destroy_state(struct lwtunnel_state *lwt) { - dst_cache_destroy(&seg6_lwt_lwtunnel(lwt)->cache); + struct seg6_lwt *slwt = seg6_lwt_lwtunnel(lwt); + + dst_cache_destroy(&slwt->cache_input); + dst_cache_destroy(&slwt->cache_output); } static int seg6_fill_encap_info(struct sk_buff *skb, -- 2.53.0