From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796129134; b=xkmODYCkY5JQoRPhY/AY2JCZV4okTtTCVS5jWigtxZ3EKuODl22OVbIa7Jmdupkq+HNj SQOOdURJtlrc6tB1cnO56GJI7GKqqWzkI6Tc0I/i1v9bUnwnymj597avhuhAUKvUxAOnA 4cxAZxsGifm06rfDm8O6VaepUmd0rC7PN4LnXthMXCaoRGb9BkynTLDJRjrE8pLWlc1Ek N/E09W7o74WZUqnmml0D2u5kEys6uB8QCnOy/XKkhsi8TQSd0K4es483NWdFyahBUA9ps +GM9I6vWqp5dppIeqA+k04YpSHLpd0Tnf4xIuv1WGN5Vm3n6dcFNs+qr9c2o9SdX0lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129134; 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=VSio0lep0kL0eSw9izKOE9yaeGg+OMAPttGXZ9zi4oQ=; b=QtDdgh1uuF0jq2VU+rKx4KEviQoM5K2PLriQOtCmKExdc+ku9c9kMlm1u3HAOJQPzFQe 9Ttqfj83YuwaHxUGqv2lYcTmk47uYnpdb1amA31t2xezQbccNLF0ureH6YS54UbC2RfBz vFDSOtUm0yh49hCKptkrwRY10WN/KOCAc7NAUPgnQGnHSHg5fkv40w5yJxSSNKYmdB3fa OU3KruIS5u1Pt8vcKNQmJ66jSKJ1FFawq56V7qHkV3auSWAKjqswrzQChLkPbBL6V25Ut b+gEVQ1CEgjO2RYCe4ERF0c6EPnpB9EpAkITYBGC0p7KqKequCl+/KTxn/3kB0R0ifw== 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=BpgXtn+n; 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 23084606A6A6 for ; Tue, 1 Dec 2026 12:45:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23084606A6A6 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=BpgXtn+n Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id B779A205E5; Tue, 1 Dec 2026 13:45:23 +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 osHHHTBM5o0d; Tue, 1 Dec 2026 13:45:23 +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 1A8EF205E3; Tue, 1 Dec 2026 13:45:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 1A8EF205E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129123; bh=VSio0lep0kL0eSw9izKOE9yaeGg+OMAPttGXZ9zi4oQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=BpgXtn+nZsGKE5bIssFkk2lSL/NpKQdITs6z6xKDa4pWD0qtsJanMZ4KS2KliIXQy eUSSCG7CXduB2fMLMbtTJ+NRtZh+J4z/wktiNxomtyK0jZpp4ghq9NbSWa88cFk0Kt WpuNams/N/CyiJIURtnNAWK8hg5nfgxWk1jwQ7bU9wwwxdyiisxEZKegUlgtJm8q6n 3T+mcgy+Vy1xDk+QgdD/0WFVZhAWcf3quXA6YjjQjLCAS1AHc/hu0fdi2LOQrh3s6y 4dd9OSyKFbQuZDcXN55p87JO3kf//o3W/IseL/Mo1HNqLd0bnG2p4f8HC5/0G3jTrc wC1hjG+hS61Ew== 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:45:22 +0100 Received: (nullmailer pid 1165764 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 04/22] xfrm: serialize SA activation with state deletion Date: Tue, 1 Dec 2026 13:41:30 +0100 Message-ID: <20261201124252.1163254-5-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-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de (10.32.0.171) From: Kyle Zeng xfrm_add_sa() publishes a newly constructed state and arms its lifetime timer before marking it VALID. The final VOID-to-VALID test and store are not serialized with state deletion. If hard expiry deletes the state between the test and the store, the store resurrects the unlinked state. An input lookup which found the state before it was removed can then add it to the per-CPU cache after deletion has removed the cache entries. Once the remaining references are dropped, the cache points to freed memory. Take x->lock around the conditional transition, with bottom halves disabled as in xfrm_state_delete(). This preserves DEAD if expiry won the race. The same protection covers UPDSA when it installs a replacement for an ACQ state. Fixes: cc01572e2fb0 ("xfrm: Add SA to hardware at the end of xfrm_state_construct()") Signed-off-by: Kyle Zeng Signed-off-by: Steffen Klassert --- net/xfrm/xfrm_user.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index a5fbe38839c4..f802899d3d13 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -1088,8 +1088,10 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } + spin_lock_bh(&x->lock); if (x->km.state == XFRM_STATE_VOID) x->km.state = XFRM_STATE_VALID; + spin_unlock_bh(&x->lock); c.seq = nlh->nlmsg_seq; c.portid = nlh->nlmsg_pid; -- 2.53.0