Netdev List
 help / color / mirror / Atom feed
From: Jianbo Liu <jianbol@nvidia.com>
To: <netdev@vger.kernel.org>, <ipsec@lists.linux.dev>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"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>, Florian Westphal <fw@strlen.de>,
	<linux-kernel@vger.kernel.org>, Jianbo Liu <jianbol@nvidia.com>,
	Carolina Jubran <cjubran@nvidia.com>
Subject: [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage
Date: Wed, 25 Nov 2026 03:34:09 +0200	[thread overview]
Message-ID: <20261125013412.1123866-2-jianbol@nvidia.com> (raw)
In-Reply-To: <20261125013412.1123866-1-jianbol@nvidia.com>

gclist currently shares storage with bydst, and dev_gclist
shares storage with bysrc.

This is unsafe for bydst and bysrc, which can be traversed under
RCU without holding xfrm_state_lock. __xfrm_state_delete() unlinks
these nodes with hlist_del_init_rcu(), so a reader that started before
the unlink may still be following their linkage after the state has
been removed from the hash table.

Later, when the last reference is dropped, __xfrm_state_destroy()
adds x->gclist to xfrm_state_gc_list. Since gclist and bydst
currently share the same storage, adding the state to the GC list can
overwrite the bydst linkage while an RCU reader is still using it.
The same issue applies to dev_gclist and bysrc.

Give gclist, bydst, and bysrc separate storage so their hash-list
linkage remains valid for outstanding RCU readers. Share dev_gclist
with byseq instead. byseq has no RCU readers, only
__xfrm_find_acq_byseq() under xfrm_state_lock, and the state is
unlinked from byseq before dev_gclist is used. Sharing keeps the
growth of struct xfrm_state at 16 bytes rather than 32.

Fixes: d737a5805581 ("xfrm: state: don't use lock anymore unless acquire operation is needed")
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
---
 include/net/xfrm.h    | 10 ++++------
 net/xfrm/xfrm_state.c |  1 +
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 445223a8dc6f..bc59a979a4d3 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -189,16 +189,14 @@ enum xfrm_replay_mode {
 /* Full description of state of transformer. */
 struct xfrm_state {
 	possible_net_t		xs_net;
-	union {
-		struct hlist_node	gclist;
-		struct hlist_node	bydst;
-	};
+	struct hlist_node	bydst;
+	struct hlist_node	bysrc;
+	struct hlist_node	gclist;
 	union {
 		struct hlist_node	dev_gclist;
-		struct hlist_node	bysrc;
+		struct hlist_node	byseq;
 	};
 	struct hlist_node	byspi;
-	struct hlist_node	byseq;
 	struct hlist_node	state_cache;
 	struct hlist_node	state_cache_input;
 
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f4a4ddaeb9b3..3eb012ed8657 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -751,6 +751,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
 		INIT_HLIST_NODE(&x->state_cache);
 		INIT_HLIST_NODE(&x->bydst);
 		INIT_HLIST_NODE(&x->bysrc);
+		INIT_HLIST_NODE(&x->gclist);
 		INIT_HLIST_NODE(&x->byspi);
 		INIT_HLIST_NODE(&x->byseq);
 		hrtimer_setup(&x->mtimer, xfrm_timer_handler, CLOCK_BOOTTIME,
-- 
2.39.3


  reply	other threads:[~2026-11-25  1:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:34 [PATCH ipsec 0/4] xfrm: Fix device state teardown races Jianbo Liu
2026-11-25  1:34 ` Jianbo Liu [this message]
2026-11-25  1:34 ` [PATCH ipsec 2/4] xfrm: Serialize device state teardown Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 3/4] xfrm: Wait for an RCU grace period before freeing device state Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" Jianbo Liu

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=20261125013412.1123866-2-jianbol@nvidia.com \
    --to=jianbol@nvidia.com \
    --cc=cjubran@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.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