From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 62A8D4195BE for ; Thu, 9 Jul 2026 17:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618844; cv=none; b=p5KoDRBYS1VXmjmK+a/AhFZCxwTXBoN5cfN3Yc8/mJN5DoBrY/gfSfWvMd0BZ/OS60eDEeL/dT7BZQfs79wux+eGM4d6UQG832K9Gdc+ESi/n6JlNBtkQNQo6KSgPYY/UtiuWkv8uVQ8ONL4XQM1dN0rUPYWacnZWKMbE41jgCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618844; c=relaxed/simple; bh=OHNPpDUoxlvLmA9oMH2uu2wD8kPh8i83NI9I0DaLpU4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iAxPO2/SDoiiOyFWyKWRA5fdcBYNWktJ+x0UaZQVV6nSttLZp1SpeZh82EDuZfrBrBF7LsX3mUk5mCss5xOSQIjDsVYCCHY65zJvyUh1XqG/P558GKLuXBq+DYaq/0OyRTTNEgs8NmzX0D0qnUnS30mKna0A+J9j+Gsd/jcGZ1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=maHsEa59; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="maHsEa59" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2F6D1F00A3D; Thu, 9 Jul 2026 17:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618843; bh=jXKIF1/8Z0bAqwPLu4AeFYwhGaz8CukTAjbXK6rzrJw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=maHsEa59WeD9tDcDzYyV3bUtrWrFtxi8E1f6wrePMY9khV96McukUQhjno8MbF1lo inK9DKNzLTODL0lRYa8rM83CQ88Kfe4dei3fhXqxMSmts8u3TVbXUQA9y/degLpUaM RVESmnC381yqqBlcn1Pp/yxXEtY2o6Ea/xkr61zUkoXGIgZ/Wk4f9Pf8aHxv6QsT+u meFND2YhQIuRaFF7FJ26vNMAPjCYZypa76wsAT37sxnKAdDUlg1+gndykagf0M3D8k iLbllUjrMD/T6zrfJ2sdhQbJfWABJ4fWIUdzJOoXxbhvNnI0uRV+WouWMo40q8R6GY u2j7PJXWyheog== From: Chuck Lever Date: Thu, 09 Jul 2026 13:40:29 -0400 Subject: [PATCH v4 6/9] NFSD: Consolidate the revocation-path client unpin Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260709-cel-v4-6-1d519d9be0cb@kernel.org> References: <20260709-cel-v4-0-1d519d9be0cb@kernel.org> In-Reply-To: <20260709-cel-v4-0-1d519d9be0cb@kernel.org> To: Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-nfs@vger.kernel.org, Chuck Lever X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4876; i=cel@kernel.org; h=from:subject:message-id; bh=OHNPpDUoxlvLmA9oMH2uu2wD8kPh8i83NI9I0DaLpU4=; b=owEBbQKS/ZANAwAKATNqszNvZn+XAcsmYgBqT90VIGyWvCC4R2oRSi4fkqYwT4dbjcLS0dDVC 4dNzC7GP6mJAjMEAAEKAB0WIQQosuWwEobfJDzyPv4zarMzb2Z/lwUCak/dFQAKCRAzarMzb2Z/ l9/UD/9TtYsgZDNDL+c0hRH5g/dAEXGgJQFJroSNOyuNhW1JrbtYUzap5TSntCOFZVyZ8Ik5kNB hfwWjCFUkJjx+k5UrAWF024aKg9uwULn6qFpDbQwSqAbeisAdLXDdUlnJh6Q5WaY5tkQYGouxA8 gJ6Ya5rshtxiwSbVXHSmrtEShv2j04IpNpJcTfat3Vv6VME0OLCiYxhYuVK28K/DsDx6X4SrrJI PkXkP/3OEZG/3ALQcTEVs2oElTsI22bMbVx9hF/mEbazZNwsLsuUSE6jnFz1Md3cTqkk5oTbnQT nnr+0JKfZ2y1eMDmQsDzeWLwbDxBSZeQcU6Rx06Bleym7VkEppzvcTXXL4Wyn01ifhjTjtV108E VMTEBCONH0D7RsGsRejX/JBcXP6HN/dPRdEhaqWaJLEAJ2OgLAedTLGSi2VaJ5/8JwHKa5cZCoP wnujsCzCFd7B++26SYFTM2qhd3EEi+fslsYoXxbmLJcmu8JHBKdIviKmZ7n7zXeyCB0+nqtdK9S /FzRWEwCSjsZUQ12xpDU33r1TFQ7RNLeDBE9+aZehEK00U8JKk5cSBzg5BJHtrZAGe2QWOZYI5G wYi8TVcuZDPpFBW6y6cFiTGbNf5KaO989Ay6+urr97OtBnytdoZOKFjHzx25A81dt3hYR0hOsRj OoNA1XROLUg5u+w== X-Developer-Key: i=cel@kernel.org; a=openpgp; fpr=28B2E5B01286DF243CF23EFE336AB3336F667F97 The client use-after-free fixes in the state-revocation paths left four open-coded copies of one idiom: drop a cl_rpc_users pin without renewing the client's lease, waking force_expire_client() when the last pin drops on a client it is tearing down. The accompanying "do not renew" rationale was documented at only one of the four sites. put_client_renew_locked() and put_client_renew() already carry the same pin-drop logic, but they renew a non-expired client's lease and so would resurrect the client whose state is being revoked. Factor the common pin-drop into __put_client_locked(), parameterized by whether to renew. The renew helpers pass true; the new put_client_no_renew_locked() and put_client_no_renew() pass false and carry the revocation paths, which must not revive the client they are tearing down. No change in behavior. Reviewed-by: NeilBrown Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 69 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 445a0f40d5ff..142ba7d80539 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -206,18 +206,28 @@ renew_client_locked(struct nfs4_client *clp) clp->cl_state = NFSD4_ACTIVE; } +/* + * Finish a cl_rpc_users unpin with the client_lock held. A + * revocation walk clears @renew so the client whose state it is + * revoking is not revived; every other caller renews the lease of + * a still-active client. + */ +static void __put_client_locked(struct nfs4_client *clp, bool renew) +{ + if (is_client_expired(clp)) + wake_up_all(&expiry_wq); + else if (renew) + renew_client_locked(clp); +} + static void put_client_renew_locked(struct nfs4_client *clp) { struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); lockdep_assert_held(&nn->client_lock); - if (!atomic_dec_and_test(&clp->cl_rpc_users)) - return; - if (!is_client_expired(clp)) - renew_client_locked(clp); - else - wake_up_all(&expiry_wq); + if (atomic_dec_and_test(&clp->cl_rpc_users)) + __put_client_locked(clp, true); } static void put_client_renew(struct nfs4_client *clp) @@ -226,10 +236,27 @@ static void put_client_renew(struct nfs4_client *clp) if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) return; - if (!is_client_expired(clp)) - renew_client_locked(clp); - else - wake_up_all(&expiry_wq); + __put_client_locked(clp, true); + spin_unlock(&nn->client_lock); +} + +static void put_client_no_renew_locked(struct nfs4_client *clp) +{ + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + + lockdep_assert_held(&nn->client_lock); + + if (atomic_dec_and_test(&clp->cl_rpc_users)) + __put_client_locked(clp, false); +} + +static void put_client_no_renew(struct nfs4_client *clp) +{ + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + + if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) + return; + __put_client_locked(clp, false); spin_unlock(&nn->client_lock); } @@ -1990,9 +2017,7 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb) */ nn->nfs40_last_revoke = ktime_get_boottime_seconds(); - if (atomic_dec_and_test(&clp->cl_rpc_users) && - is_client_expired(clp)) - wake_up_all(&expiry_wq); + put_client_no_renew_locked(clp); goto retry; } } @@ -2070,9 +2095,7 @@ void nfsd4_revoke_export_states(struct nfsd_net *nn, const struct path *path) if (clp->cl_minorversion == 0) nn->nfs40_last_revoke = ktime_get_boottime_seconds(); - if (atomic_dec_and_test(&clp->cl_rpc_users) && - is_client_expired(clp)) - wake_up_all(&expiry_wq); + put_client_no_renew_locked(clp); goto retry; } } @@ -7465,9 +7488,7 @@ static void nfs40_clean_admin_revoked(struct nfsd_net *nn, nfsd4_drop_revoked_stid(stid); nfs4_put_stid(stid); spin_lock(&nn->client_lock); - if (atomic_dec_and_test(&clp->cl_rpc_users) && - is_client_expired(clp)) - wake_up_all(&expiry_wq); + put_client_no_renew_locked(clp); goto retry; } spin_unlock(&clp->cl_lock); @@ -7540,15 +7561,7 @@ nfs4_laundromat(struct nfsd_net *nn) clp = dp->dl_stid.sc_client; list_del_init(&dp->dl_recall_lru); revoke_delegation(dp); - /* - * Unpin without renewing: put_client_renew() would - * renew the reaped client's lease. - */ - if (atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) { - if (is_client_expired(clp)) - wake_up_all(&expiry_wq); - spin_unlock(&nn->client_lock); - } + put_client_no_renew(clp); } spin_lock(&nn->client_lock); -- 2.54.0