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 CCE8C523781; Wed, 9 Sep 2026 13:47:30 +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=1788961652; cv=none; b=eMXxjayKBRspxxq5hnOkR0SI87B4PUPwFoRjkFfPxIAE3M5niWrPvPk8wPkdBleIh5ThtcU7YzgL7oOevc6+xH5rYt90fSC9uR7S7bNjk4e79F9w3I/grm7VHP3aP2iKRTGyXyEzWAoxmkBGFeLCP+om6M9BKUlZW5O4uZKUeN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788961652; c=relaxed/simple; bh=+2mlopiQglXT5G5VLlt+2E0as85wCp6oXMpodlIy4Xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYAmx6t7nkQnMXfqH3EUESSCrCLS7Kos6OFHArXtN1H758jtGz7AuXVwO3Cti9PiKM9IpfSPMLPghF8zHsy33OSQscfmSQFHoxrt1Hej42pJgmCJki2mqPCR0nXb8V8CHYQgWJ7d7rikex8obEbUnXNqz2htqnmNrE9tMzirv3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nAE8NVdj; 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="nAE8NVdj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 344C31F00A3A; Wed, 9 Sep 2026 13:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788961650; bh=rbcbT+nml0jDPdM8swMAW8Z6esq2bJmQAiuvYLxY53Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nAE8NVdjKdoRlwpQquNTAjo0UP/UCH/fhFvV5l++UwiHgYCxMbyxUDC3DVpSF+A+4 /PxAQM/40b+mwvCWUKKk/2LDFJ+KSazwi2tX66FW1RhNI++8LMIOo2mYCfnmMpICpa fO6y/elS4tuWtvLKpUKCOFY01gxenFTmTUbTlBT8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jeff Layton , Chuck Lever , Sasha Levin Subject: [PATCH 7.2 022/556] NFSD: Prevent client use-after-free during close_lru reaping Date: Wed, 9 Sep 2026 15:35:02 +0200 Message-ID: <20260909134231.274373265@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134230.441546314@linuxfoundation.org> References: <20260909134230.441546314@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuck Lever [ Upstream commit 2330b788d732f43668b965b3105b37ceb276dfea ] An nfs4_openowner left on nn->close_lru after its final CLOSE keeps its last closed stateid in oo_last_closed_stid, holding only a raw pointer to its nfs4_client. The laundromat reaps timed-out entries, drops nn->client_lock, and calls nfs4_put_stid(), which dereferences the client through cl_lock. Nothing pins the client across that window, so a concurrent force_expire_client() can free it and nfs4_put_stid() reads freed memory. __destroy_client() hits the same race, walking clp->cl_openowners without cl_lock. Pin the client with cl_rpc_users before dropping client_lock, and skip clients already expiring. __destroy_client() then cleans up its own close_lru entries through release_last_closed_stateid(), so teardown no longer races the laundromat. Fixes: 217526e7ecc9 ("nfsd: protect the close_lru list and oo_last_closed_stid with client_lock") Cc: stable@vger.kernel.org Reviewed-by: Jeff Layton Link: https://patch.msgid.link/20260709-cel-v4-8-1d519d9be0cb@kernel.org Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs4state.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7311,11 +7311,16 @@ nfs4_laundromat(struct nfsd_net *nn) if (!state_expired(<, oo->oo_time)) break; list_del_init(&oo->oo_close_lru); + clp = oo->oo_owner.so_client; + if (is_client_expired(clp)) + continue; stp = oo->oo_last_closed_stid; oo->oo_last_closed_stid = NULL; + atomic_inc(&clp->cl_rpc_users); spin_unlock(&nn->client_lock); nfs4_put_stid(&stp->st_stid); spin_lock(&nn->client_lock); + put_client_no_renew_locked(clp); } spin_unlock(&nn->client_lock);