From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89964322A for ; Mon, 23 Mar 2026 08:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.96.220.36 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774254977; cv=none; b=nGCWv42ty5B2PR+YnAtMZ/3hmIknVHw8wdgGKA5RQSM7WpxCLwRfzKMyFkQ8Dc/mj8Vz2H1DZTbsh0CqeSuNtIiwzukvscd3OpGkXDd3g0w7VIwwPzdPy+mzQ1RNEQWbljLrfFquY7RzlNz5XOiwEAQxLArP9sbInEFrsIwA99s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774254977; c=relaxed/simple; bh=sDQshk6lxbTnRdh8pFq8Qt4s8hsHUgnu+u/Jg6JOxq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Utx3pJp38U024fvP/Vt5nXm/LYcdgEC5XoJyl+HeO+CcD9hpeiMIHPZQUA09YXjEvErnpMm3eYmVNN+ZNTJYK+yq0PKIS0FBMxcGn5ClU9H/duBo3bgfIhyreJBeH+ER72uachLR8ZmNDqgXw0vny/jOEFm4w9VTO5/YvjyizEA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.b=SbddMoC6; arc=none smtp.client-ip=62.96.220.36 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.b="SbddMoC6" Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id B3606207C1; Mon, 23 Mar 2026 09:36:14 +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 WtbYe3qaCn8W; Mon, 23 Mar 2026 09:36:14 +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 2846E205DD; Mon, 23 Mar 2026 09:36:14 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 2846E205DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1774254974; bh=rbWKtFSDsm9zKKJ8zorkRYsIVj0UsHqA/OM8skBEydQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=SbddMoC6IFpMbrNYUGwpE/zWN9qAlhiomiJj+YRdrvlLKqvyPkyiqsZMm8WPskwgP tBOLoYlNLAfuPZJQLFr0ydgOHG0IJXyreus0oVrh2FJRWaNC938cuOEEiDaTUDqzCJ zOdkFjnnn11RS8JA0lSdvdKn/MONMG/qweWwr2JFIplLs12m65iHutZ+7ARyL1Zkr8 Pj9BlOpn5ocqkz1qvwOUSGxCQeGrQVJ+UXzzX8ue0kaGy3kiSj9qx31r64xnRTaeH+ 2i3rtlr+S1u1hVw5Q4QRdxlFmQo3Q8x86JL5mQVvOKITB7sytpjMzc+ZSAnpqJ0ZpP hnbC8BUvBcsVw== Received: from secunet.com (10.182.7.193) 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.17; Mon, 23 Mar 2026 09:36:13 +0100 Received: (nullmailer pid 2741851 invoked by uid 1000); Mon, 23 Mar 2026 08:34:49 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 18/20] xfrm: prevent policy_hthresh.work from racing with netns teardown Date: Mon, 23 Mar 2026 09:33:59 +0100 Message-ID: <20260323083440.2741292-19-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323083440.2741292-1-steffen.klassert@secunet.com> References: <20260323083440.2741292-1-steffen.klassert@secunet.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-03.secunet.de (10.32.0.183) To EXCH-01.secunet.de (10.32.0.171) From: Minwoo Ra A XFRM_MSG_NEWSPDINFO request can queue the per-net work item policy_hthresh.work onto the system workqueue. The queued callback, xfrm_hash_rebuild(), retrieves the enclosing struct net via container_of(). If the net namespace is torn down before that work runs, the associated struct net may already have been freed, and xfrm_hash_rebuild() may then dereference stale memory. xfrm_policy_fini() already flushes policy_hash_work during teardown, but it does not synchronize policy_hthresh.work. Synchronize policy_hthresh.work in xfrm_policy_fini() as well, so the queued work cannot outlive the net namespace teardown and access a freed struct net. Fixes: 880a6fab8f6b ("xfrm: configure policy hash table thresholds by netlink") Signed-off-by: Minwoo Ra Signed-off-by: Steffen Klassert --- net/xfrm/xfrm_policy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 66ac93e65264..2140ee7b102d 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -4282,6 +4282,8 @@ static void xfrm_policy_fini(struct net *net) unsigned int sz; int dir; + disable_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.43.0