Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129053; b=Z2kMiAO+dsJzFhVYFwd10068YvQx8+K8He1UT878/4iBmHOErEDD79fdWvVg4iOpiDMz jdAVBF0Unn4E6FuOhs/ebZrB6Ejxki9lZFfHX6kYBBQxD0q5fQdIF/F0NSkm5VrSTyS7D lWiQumy/4YuTER6oymOTyzJMAeVfdV6YulIDoX2xDaIepyqlk6whApWQbp8GQXFSSJ4oi jbormAxZLXKmOFFULLfPmJFujiPRyHCKWm6Hf+QFd2jabOh+/+FG4EOq3bU03y/26hKdw QjFYXiYni0K+rNUHmjmQ6vvQqkPRE2GHBWc9XOr8bZ2GqZrQyJueM8RC/Yc9DwsN4EQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129053; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=DWsFuFFZ1UU7v5EMncGc3Az6dAIJDhsrt9m7KeHBb1I=; b=tPdoVpRAozw806ckmhNZCuVqVnlPAMfuniQrSvBrY4YnHCj7t2OxZlN8YyIDE0/wbX6d 4NwtSxXWKTW8brzAz5WAyyGv+19FZG2QGlj0587h9aecOiWG1lHvrqzAJsdPyASbSUgRF f0gQ3j3kadYYt8CqEmb97umUmpghZquvT0FYM/CjbaIY06nyRECM/Opf7wBqhytAJJOKp Rm00WyYESU+ieQfHRfBalc6s6M4sLzmas9KG4H+EKQY59GHbVNTEqlRfQt9qykky5wIPp E+FX79lekDz8Wc1n4Plz9YTIfrJ80dcfWZI/fG1r6iQCV4es5uwBJZVtSa7Ul9Fk4Vg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=kE19E6Ej; arc=none smtp.remote-ip=62.96.220.36 Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54B5B606A68F for ; Tue, 1 Dec 2026 12:44:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54B5B606A68F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=kE19E6Ej Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id 25045207FB; Tue, 1 Dec 2026 13:44:11 +0100 (CET) X-Virus-Scanned: by secunet Received: from mx1.secunet.com ([127.0.0.1]) by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2s_NRkFYcWu4; Tue, 1 Dec 2026 13:44:10 +0100 (CET) Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.secunet.com (Postfix) with ESMTPS id 817AF20684; Tue, 1 Dec 2026 13:44:10 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 817AF20684 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129050; bh=DWsFuFFZ1UU7v5EMncGc3Az6dAIJDhsrt9m7KeHBb1I=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=kE19E6EjpNMJ0rNHKI+XX54kE/FVO0fE0Id+XWIf/SAGjgKqqEzsL4lQl7lsrDkkP cGbILD8OWeaOZr4kg+YSD0AkETqvPVAxkoEfarLSIlNiIgo2f6gHAx5ohMzovnsn2I Lwp0UuObaDY8O3bkQ8Wmf1Z+O0opSCkGjwgSeamg3f2GepFkSJsAZu4LbeGT5V5F3U 7NlaRkXBCFcBeqSDaomnlkbqLxQUJT+tOLFeErQEfVIukqk9BjqEgnbZX1gao3PtK4 TThnxy+De6/6Bcamn6p7RZzWd4iBnoV5Kvp3i9EVmnOPk/5msnO6NuUj+WrtCxm6z8 tZauS5CK37GQQ== Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 1 Dec 2026 13:44:09 +0100 Received: (nullmailer pid 1165829 invoked by uid 1000); Tue, 01 Dec 2026 12:43:56 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 18/22] xfrm: Give GC list nodes their own storage Date: Tue, 1 Dec 2026 13:41:44 +0100 Message-ID: <20261201124252.1163254-19-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de (10.32.0.171) From: Jianbo Liu 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 Reviewed-by: Carolina Jubran Signed-off-by: Steffen Klassert --- 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 5fbb73474e32..cd37aa69c9ac 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 eb984ed11888..9c101be250ee 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.53.0