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 544B13905F4; Fri, 4 Sep 2026 05:45:11 +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=1788500712; cv=none; b=CvLhbHh/uy3bAWT9RKH8ZcY09pqZOITKtSl5H8CQD2iKVae1eWv4ptBKe/USeLP5evfm07BtH1hGRoZTqKj/GNyOMZw0keUWWyaOHK3WG75/dcW/TL9Gp6Aypka8ISZPmazz5uhygjhO2Cf1avuZ9ibMXlGFjFcg2hXX5PCTm50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500712; c=relaxed/simple; bh=2TynJs51HMAQkSl99rgmahy3CY8020QnMiBwoVPNiho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gLiBeIZvLW1+oQvCKm7aA5DZ1jl+xv0ws3hBne/cX1x4vJrrEYv1Khaj3nDozPJ1gLfruvjuqhI8au8hbBDs1wh6WwtSryW22XnaKJl6Lcr09E1p8xzazyEa/G391qt4hmMWgW4toazGBxn/YsmCCifW1hgqY7uDRgHrnqyoy/k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xZa6DCrP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xZa6DCrP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB34C1F00A3D; Fri, 4 Sep 2026 05:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788500711; bh=Hx2RLkjHdAeIfRCkkFfX9LLckeWF+MVecW9ngjrhYa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xZa6DCrPDQXw+nZa6osC8uN7klSuO2skgj3d5lZ04qncqpf86vLWI/kGGNaLLGO0F xFk/r6TodcPdk6yE592I9KnoBJ4xZV1hd6m+S0IWqdISRzeD409+ywV/x494BLbU9h 62Q6iG+lNUKivujm9O1y3da3OpMCTOt8xxLXpTI8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, NeilBrown , Jeff Layton , Chuck Lever Subject: [PATCH 6.18 152/552] NFSD: Prevent client use-after-free during NFSv4.0 revoked-state cleanup Date: Fri, 4 Sep 2026 06:55:09 +0200 Message-ID: <20260904045752.182709536@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuck Lever commit 7b4f8a1586c42d3afc3c0ac779af2db7ab1a5c55 upstream. nfs40_clean_admin_revoked() takes a stateid reference under clp->cl_lock, drops nn->client_lock, and calls nfsd4_drop_revoked_stid(), which dereferences the stateid's client through s->sc_client->cl_lock. The stateid reference does not pin the client, so a teardown racing the dropped lock can free the client while nfsd4_drop_revoked_stid() is still using it. This cleanup runs from the laundromat, so a periodic sweep can race force_expire_client() driven by a write to the clients//ctl file. Skip a client that is already expiring and otherwise pin it with cl_rpc_users under client_lock before dropping the lock, matching nfsd4_revoke_states(). Fixes: d688d8585e6b ("nfsd: allow admin-revoked NFSv4.0 state to be freed.") Cc: stable@vger.kernel.org Reviewed-by: NeilBrown Reviewed-by: Jeff Layton Link: https://patch.msgid.link/20260709-cel-v4-5-1d519d9be0cb@kernel.org Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs4state.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7016,16 +7016,22 @@ retry: if (atomic_read(&clp->cl_admin_revoked) == 0) continue; + if (is_client_expired(clp)) + continue; spin_lock(&clp->cl_lock); idr_for_each_entry_ul(&clp->cl_stateids, stid, tmp, id) if (stid->sc_status & SC_STATUS_ADMIN_REVOKED) { refcount_inc(&stid->sc_count); + atomic_inc(&clp->cl_rpc_users); spin_unlock(&nn->client_lock); /* this function drops ->cl_lock */ 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); goto retry; } spin_unlock(&clp->cl_lock);