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=1793213483; b=dGuMIm51RLL3jmKvBNch0nVmWA3s3Qz+r6hagRuJ9L/xGbTmeqHven+OPnBkf0Zu3DGY 638Vt7v+uVWnC6StMIYqykbkhNVjmcGgjmuXOWCS28+fYE+YUWRZMCPGlMglyihv0rA6I nI0WS+ZrV/w319jLeZstUrTAYoqNvDmgmBy0PV3AQUojHh6/q5M+FOM9SGOg04yuwpcY7 ku5bxXHPAmZ8z+1k+rmHxwOtl/wA0Xxkq3dIO361mEgfO0yYANC8Rzp+URuoxTwD62msC PTegVEOCMIWWvALT/P48Q8JO4w1AozCAeqM0WHtVAH3IaYIVlZ+rBzDtl0VFv5mtMRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793213483; 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=lWasm+OqxAzG/iv6x5zSkcSokui9n/c/CHRMqBxmjnI=; b=e5XpG1iR6lBsJIm1uaHySGcBtRDFnvA6lEuLsbzj3+aynaMlJWc8RwopP7Lb57R/aeZh tLSO2+vKnwoYHcpNnPetdwp+0x62/PXti23AJZeqjbOuORpjzNJx+pdVIDhzxDPpVIGde YbZGdcwtzkQjtwVNhsJ80m0WhtS8DtZjcGng+YV3fGd/ZBaajLiMvGBMID8zapaYX8Jb/ tZFzuotzgVoUAP9puWTLffnoDr9Bhu71d7VVwfQJzQHaCKFiUcPgudwMeT+Lns59AvlAX GPwCerWE/MIj/DyZo8/FBNLTjtw2FLhl4q835cMPn2/zV8pvfj+Wxq1lkADU0XZ3h5A== 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=i1A5gPvG; 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 9F4B5606A31C; Wed, 28 Oct 2026 18:51:18 +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=i1A5gPvG Received: by smtp.kernel.org (Postfix) with ESMTPSA id F00EC1F01828; Wed, 28 Oct 2026 18:51:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793213478; bh=lWasm+OqxAzG/iv6x5zSkcSokui9n/c/CHRMqBxmjnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i1A5gPvG6CUXXOY4cjEGn5PmdW2nBD+lSz980+AAadWBjJarpb1pwaqOcW+y5URoB 2B/QeHAqjGBNuqAgIRC4SYG4Q2mTeOhc447RiRgHhNZdL0ALV3879TSfKTc/on2QuX zbsYzI/prqx/zcFRlYuFLG5szQBZUl1Rg0u8wjak= 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 6.1 0519/1887] xfrm: prevent policy_hthresh.work from racing with netns teardown Date: Wed, 28 Oct 2026 17:43:35 +0100 Message-ID: <20261028170511.134536639@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@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 6.1-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 6.1, 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 2a47f5b5776e8..76b7b94132c00 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1381,7 +1381,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); @@ -4094,6 +4097,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); @@ -4119,6 +4123,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 v6.6. 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