From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793211667; b=SWAQG9DMuyopI4/nRaDhGj8+LqRw+qij8BViY1rzZxdkUnz3RkA2nzAIEckDyXtZAYg6 3avSffIeYKQygjDRADU7qBUG2a3KTsEyfk3lkw1xhaPr0TitVwCOqzcl9is0D2ZSxnBGt KN2ttbVdQVY5qgzL5oFkB1kqS6PELu3tKKxmawGWgFJmvTSq1kgR2knqFt1S6tV+Tl+ly nNVV6Py4VZzOxQS/WbuDeUQi8IHOFTGaJ/L90v7g7K6l+IvDcObDPmFkTWnqpt06qhfrM gEWNONswsZnqQrc/Dn1DiN9hWyenZnqluaB1bTjb7FGMbwW/wiy+DmRKgKN5hdxMvGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793211667; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=51fIKbsQ/EL4X2bWwtLBBJUtlxahvBTnFUpFhayVwDk=; b=fWsKjWv53dRRCaxwI6v+U89JWR8aDE4NNaMJsxEnam6mXu07wHd1NJGVI1E62pYH08fP J0o4HAbbHFvUxSPRyNWkXVLCVfkCoMLw7gRi1GDvvcNwx5iH09R5MTIElRjKNnNFH7aqF dKB5Z6uU3eWjvwxB/gvPvvJ4xsOaT73HpqAckkjQQIaHDYwt5U9BeC2Lwej5Fxi54jmSB b0BpAGk0PsTjDUhHfjPDVJf5rebpCm3nMMCfU6Mk7xfaUSylcx3KASzIHFmXl3Rkfs+o6 Z6w7aU4E84vTFXTMuWvW8e9WX2FbyRpq1SfEEGSHitS8DBHG9VNJGFDhPSX0+Xe/ZSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mxYsRDcI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB636606A31A; Wed, 28 Oct 2026 18:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mxYsRDcI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 077611F01825; Wed, 28 Oct 2026 18:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793211666; bh=51fIKbsQ/EL4X2bWwtLBBJUtlxahvBTnFUpFhayVwDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mxYsRDcIfv3OpY5Xk6d1fiWo6CvUPryOpkhozBAlrKTF/sRRrhudyRqNxD5ootkQq Jl2migr29UI28gdR+oFZ4gyG3j6WCd4cxFJgrNrJiqgLfPqe6bYGa/tIne4jS/u6d7 ppyLMOp26yqGsidrLX1CxPcjDshZM3udEt0m1Bi0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tahera Fahimi , Allen Pais , Sasha Levin Subject: [PATCH 5.15 456/571] xfrm: prevent policy_hthresh.work from racing with netns teardown Date: Wed, 28 Oct 2026 18:00:03 +0100 Message-ID: <20261028170018.845769513@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170008.009143722@linuxfoundation.org> References: <20261028170008.009143722@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tahera Fahimi An XFRM_MSG_NEWSPDINFO request can queue the per-net work item policy_hthresh.work onto the system workqueue. xfrm_hash_rebuild() retrieves the enclosing struct net from the work item, so the callback can dereference freed memory if it runs after net namespace teardown. Mainline commit 29fe3a61bcdc ("xfrm: prevent policy_hthresh.work from racing with netns teardown") fixes this issue using disable_work_sync(). That API is not available in Linux 5.15, so the mainline change cannot be directly backported. Provide the same guarantee with an XFRM-local work_disabled flag. Protect the flag and schedule_work() with the existing policy_hthresh seqlock so teardown can atomically stop new queueing attempts. Then use cancel_work_sync() to synchronize work that was queued before the flag was set. This ensures policy_hthresh.work cannot outlive its struct net. Fixes: 880a6fab8f6b ("xfrm: configure policy hash table thresholds by netlink") Assisted-by: GitHub-Copilot:GPT-5.6 Sol Signed-off-by: Tahera Fahimi Reviewed-by: Allen Pais Signed-off-by: Sasha Levin --- include/net/netns/xfrm.h | 1 + net/xfrm/xfrm_policy.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h index 7922ec72eaa68..eb9edddd73092 100644 --- a/include/net/netns/xfrm.h +++ b/include/net/netns/xfrm.h @@ -23,6 +23,7 @@ struct xfrm_policy_hash { struct xfrm_policy_hthresh { struct work_struct work; seqlock_t lock; + bool work_disabled; u8 lbits4; u8 rbits4; u8 lbits6; diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 536b945e1eeb6..15d50b5a22ef1 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1378,7 +1378,10 @@ static void xfrm_hash_rebuild(struct work_struct *work) void xfrm_policy_hash_rebuild(struct net *net) { - schedule_work(&net->xfrm.policy_hthresh.work); + write_seqlock(&net->xfrm.policy_hthresh.lock); + if (!net->xfrm.policy_hthresh.work_disabled) + schedule_work(&net->xfrm.policy_hthresh.work); + write_sequnlock(&net->xfrm.policy_hthresh.lock); } EXPORT_SYMBOL(xfrm_policy_hash_rebuild); @@ -4088,6 +4091,7 @@ static int __net_init xfrm_policy_init(struct net *net) net->xfrm.policy_hthresh.rbits6 = 128; seqlock_init(&net->xfrm.policy_hthresh.lock); + net->xfrm.policy_hthresh.work_disabled = false; INIT_LIST_HEAD(&net->xfrm.policy_all); INIT_LIST_HEAD(&net->xfrm.inexact_bins); @@ -4113,6 +4117,19 @@ static void xfrm_policy_fini(struct net *net) unsigned int sz; int dir; + /* Prevent new policy hash rebuilds before draining the work item. + * + * The upstream fix uses disable_work_sync(), which is unavailable + * in v5.15. Protecting work_disabled and schedule_work() with the + * same seqlock closes the check-to-queue race, while the subsequent + * cancel_work_sync() drains work that was queued or running before + * teardown disabled it. + */ + write_seqlock(&net->xfrm.policy_hthresh.lock); + net->xfrm.policy_hthresh.work_disabled = true; + write_sequnlock(&net->xfrm.policy_hthresh.lock); + cancel_work_sync(&net->xfrm.policy_hthresh.work); + flush_work(&net->xfrm.policy_hash_work); #ifdef CONFIG_XFRM_SUB_POLICY xfrm_policy_flush(net, XFRM_POLICY_TYPE_SUB, false); -- 2.53.0