🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14876

[PATCH v6 03/13] NFSv4: Clear idmap keyring cache when the last client unloads

#14876
From: Jarkko Sakkinen
Date: Thu, 12 Nov 2026 04:02
78 lines
11063 bytes
id_resolver_cache->thread_keyring caches id_resolver_legacy keys up until
nfs_idmap_quit() tears down the keyring.

Once keys pin to the kernel module of their key type, the cached keys
prevent module_exit() from ever happening.

Track the active idmap instances under a mutex and clear the idmap cache
keyring once the last client has been destroyed.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/nfs/nfs4idmap.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c
index bc397110d977..c88444cc6bf6 100644
--- a/fs/nfs/nfs4idmap.c
+++ b/fs/nfs/nfs4idmap.c
@@ -47,6 +47,8 @@
 #include <keys/request_key_auth-type.h>
 #include <linux/module.h>
 #include <linux/user_namespace.h>
+#include <linux/mutex.h>
+#include <linux/ratelimit.h>
 
 #include "internal.h"
 #include "netns.h"
@@ -58,6 +60,10 @@
 static const struct cred *id_resolver_cache;
 static struct key_type key_type_id_resolver_legacy;
 
+/* Serializes the idmap cache. */
+static DEFINE_MUTEX(nfs_idmap_cache_mutex);
+static unsigned int nfs_idmap_users;
+
 struct idmap_legacy_upcalldata {
 	struct rpc_pipe_msg pipe_msg;
 	struct idmap_msg idmap_msg;
@@ -469,7 +475,10 @@ nfs_idmap_new(struct nfs_client *clp)
 	if (error)
 		goto err_destroy_pipe;
 
+	mutex_lock(&nfs_idmap_cache_mutex);
+	nfs_idmap_users++;
 	clp->cl_idmap = idmap;
+	mutex_unlock(&nfs_idmap_cache_mutex);
 	return 0;
 err_destroy_pipe:
 	rpc_destroy_pipe_data(idmap->idmap_pipe);
@@ -483,6 +492,7 @@ void
 nfs_idmap_delete(struct nfs_client *clp)
 {
 	struct idmap *idmap = clp->cl_idmap;
+	int ret;
 
 	if (!idmap)
 		return;
@@ -493,6 +503,17 @@ nfs_idmap_delete(struct nfs_client *clp)
 	rpc_destroy_pipe_data(idmap->idmap_pipe);
 	put_user_ns(idmap->user_ns);
 	kfree(idmap);
+
+	mutex_lock(&nfs_idmap_cache_mutex);
+	if (--nfs_idmap_users == 0) {
+		ret = keyring_clear(id_resolver_cache->thread_keyring);
+		if (ret)
+			pr_warn_ratelimited("NFS: Failed to clear idmap cache: %d; cache pins remain\n",
+					    ret);
+		else
+			key_gc_flush();
+	}
+	mutex_unlock(&nfs_idmap_cache_mutex);
 }
 
 static int nfs_idmap_prepare_message(char *desc, struct idmap *idmap,
-- 
2.47.3
Technical Details
Message-ID: <20261112040242.247168-4-jarkko@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361489-linux-kernel-netdev=dewy.ru
References: <20261112040242.247168-1-jarkko@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361489-linux-kernel-netdev=dewy.ru
From: jarkko@kernel.org (Jarkko Sakkinen)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v6 03/13] NFSv4: Clear idmap keyring cache when the last client unloads
Date: Thu, 12 Nov 2026 06:02:32 +0200
Organization: Usenet Network
Message-ID: <20261112040242.247168-4-jarkko@kernel.org>
References: <20261112040242.247168-1-jarkko@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1004942"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HwE2p6PDECWp3cgoYNz2ZCp5STE= sha256:gjQDaEsaodeCM52qjcxxj2SEeDCBoFZhkp4MwepZyzM=
	sha1:JEmtm0GPMfdteShh4iOhq4gIGM8= sha256:Fsja0yaRZoWThrnyTfTwqR6LRI3oK4NF63+1JgzFv3o=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 555A11140F0; Thu, 12 Nov 2026 07:05:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.301
X-Spam-Status: No, score=-2.301 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001,
	DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 0ZQHod4XgIsn;
	Thu, 12 Nov 2026 07:05:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361489-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 283611140B3; Thu, 12 Nov 2026 07:05:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 27387A8125; Thu, 12 Nov 2026 04:03:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794456180;
	b=g1u6GgKR/8ycTv5pAF7vk+kOakj2LVxrLfrIbxxukwxo1LWxJ5S8awApCY89g2IvYDSD
	 bYo9ywyoSPwzn3SnvugLjCesv07u0Egr56CBq3nVrmkxz1FedDGL/9Ctun+pOJAGd9/Gk
	 SuxWnnkWMCNIOqUjqjHLbyyTDX/s1/4skJXX0XdgKa8E37lfnzN2Xnria5JNPm0z2wW2R
	 scgwCYjxntwTwwkUdWe50UPJ+EpgNMPfo6VggH5Ar/QAfvXHMN4ZYmG9iAbDwBu3ahipo
	 e/IIwpO+RnMTuu3syS2LDxPOP9JQB3KBMqqduvV0Lg195zVsSKhC5nUn+9TDquxgzcg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794456180;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=QVH4HUhUjAGbn//KdcTKvYYK0jkAf27rpg6dT7GZY+M=;
	b=mKDpo5pirjJ6GmtVsgv+1Jw6Rfu1k+GJDnVvCA9X/qH5kHxfIMr+fTX8G8gEgLVtHpjS
	 PZmFvW03PKCowjrp4xfkuZg6H6MF/KFAAoMydQ9MeBSJCUdOLp1ZxrKcqCAUvNffIhyUM
	 g97c7k5HO1JyOgpZ04DB8YOf1/v3aD7+1buLEf8I7KOvpFdblK8sK49BFh9vWqxcgVR4j
	 kgPoVH2rUvfRl4+uB7/wTg0RCDqdKY2UQ2UyDUZ63PviEGHe4bQeFAQkEfhnCjh00GqMK
	 1bfbvuu0IVaVJHtospQaOGOBUTwu5FcH4ytUiAowiOP+eD0iDn9vfN23vfmggHMeeTA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YOgWdqOz;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id C79B460A2618;
	Thu, 12 Nov 2026 04:03:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YOgWdqOz
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794456179;
	b=w8p0JwU5Y0GM8bB5jcRxSmD6awcXvcijxo+KEJrrz46RXU0TjKEmbm/+2dRIkCqzERvq
	 bAR/t9ta3AmuI2C3O33VwovxILLJ1eOSMapSf9OCz3EnosJdbYqLPyHBRgBF2n+JvZVya
	 awlo4KecNZcWm4NPCK69OKJWjBy1yMpiMFYuWwOo2r4LajLy2EYnGme5esjbo+iNbpRuJ
	 fE+WIYvSd/eIS6iBdbm9ZdEuhZMKIVmbhFF8w8i4qN1qRObQvCHAEggWDBXvk/3tlHCpw
	 fujoBfQD7f68Lb3A9cbLqTbezxyEFWXWbRMot8YiEgeG3V1CK9bKu2e8o8vWwvdKv/A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794456179;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=QVH4HUhUjAGbn//KdcTKvYYK0jkAf27rpg6dT7GZY+M=;
	b=vTug+1C5TzvxTdRUD5KzgDiu2xLLFMWCfZ82cUGUvOAHDDcjm3mm3No+VQZQcrMmGC5a
	 K9JYzzCl80DFxbsJlDf+zMsg3J6viysL8XjVyH5AI2sYn5em8WshrT9VCGsIVrHLFd4ZQ
	 6Zx71Hc4CttlD0349owHD2ND1lrCZ7a9q+QLYqu/9D4ghSi9jc7//q7jYMmc0+i9sxBfU
	 cRSxHK19kD/GQc0F8p3D7rXjqxwrL2BvltmfY89q73wMl83I/W8tbHWk8yc1M0Ot3wuvS
	 WT/lGa4wQufkcDQD8OE2u8TryjwOGX2476WPwJI1p1J/bI2IBwLEb7Yv9HhAx5B8eCw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YOgWdqOz;
	arc=none smtp.remote-ip=100.103.45.18
X-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 UTF8SMTPS id D9120606A324;
	Thu, 12 Nov 2026 04:02:59 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id D82151F00A0E;
	Thu, 12 Nov 2026 04:02:58 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794456179;
	bh=QVH4HUhUjAGbn//KdcTKvYYK0jkAf27rpg6dT7GZY+M=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=YOgWdqOzEplW2J6e6awGUnpR7YVFES/XdT0aihnIfNY9nJKFQ5okhEvwV5o0kYVkx
	 G7PtRmSiLOyv33tab6dH4i3Pww9DhQYS2PP9l5vs0uI8+IzTItQABou0Epx1uoKRZH
	 MaF3VoUJmds/AJ38zHsSLVwktAyXl6J9IZG8VAtlOe4oWuYbPMlk8UQfWh/BaXqjsU
	 HPvLqFKhVcGdMlzcaHTW9s1T0g6xjQbMjIpCyJztggyrne5RRpC2vkuwlKpMhoGEbp
	 IowmCrozt5HGHKTHdi8Ca/2DFywSp73RhKODsYlNf6330bt9r+BiNRIAT2SmsHO1Sc
	 9buefzOQiWUQw==
X-Cc: Jarkko Sakkinen <jarkko@kernel.org>,
	keyrings@vger.kernel.org,
	linux-afs@lists.infradead.org,
	linux-cifs@vger.kernel.org,
	linux-integrity@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-nfs@vger.kernel.org,
	linux-s390@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	netdev@vger.kernel.org,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Anna Schumaker <anna@kernel.org>,
	Bharath SM <bharathsm@microsoft.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Biggers <ebiggers@kernel.org>,
	Eric Dumazet <edumazet@kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Jakub Kicinski <kuba@kernel.org>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	James Morris <jmorris@namei.org>,
	Marc Dionne <marc.dionne@auristor.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Paul Moore <paul@paul-moore.com>,
	Paulo Alcantara <pc@manguebit.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Simon Horman <horms@kernel.org>,
	Sumit Garg <sumit.garg@kernel.org>,
	Sven Schnelle <svens@linux.ibm.com>,
	Tom Talpey <tom@talpey.com>,
	Trond Myklebust <trondmy@kernel.org>,
	Vasily Gorbik <gor@linux.ibm.com>
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261112040242.247168-1-jarkko@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list