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 8C2EE257845 for ; Sat, 13 Jun 2026 22:16:46 +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=1781389007; cv=none; b=KOYRte2WNq39JWECIWBp+LUm9h2Ylqm5nG0Ky2tE+HV890qyBuJ6y/6rLZE83aMUxDNQvm7cnhs5I1cCGJ+gNweenkzzmAsMfA+JbbXK3jWOFXFl8l/42XQSbKiQn88T/quCTRuA1E0i6h1eCNGE+sB5SYA8m6z3frHDlZ4dz9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781389007; c=relaxed/simple; bh=dSZVqqZK+wzjQqLxHShwg64UsD5cGG3X5gZ2D/WdOKk=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=Vlv3VHkJB0QwfIeUMEO+vXAOj4anxKrBouO0WBUp17GE6Q5A7rgc+UpwI/oQinr/OL24sfbOTV9rPQpXmeAwnoOL+uGhc4GYhfbPClIQU/lkJROJ/3RKBEuvj+4OAN69et1hZZ+S4pyW+mNx/kkssB2AipdQUiwq7L1m49Il6M4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IB0J+5zH; 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="IB0J+5zH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DAF81F000E9; Sat, 13 Jun 2026 22:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781389006; bh=0+fLI91pa/Xv3FD1+RFHBdOmEDeulJXtr3rw3jCfjvU=; h=From:Subject:Date:To:Cc; b=IB0J+5zHNaROe2nUKJIMcgj5G+c4Mf5SU1bnfEL5f9mWC4BUb00ImbvHEeMErfFBC ynrFvU4K1UmjqopaTSBJ/gi8xXpwiwXIQLT0QA1+kBnT0AOA4lDE+goo+8K/ki0Flh TelUF6UFotmGqKIlsk/qy3nQJAiQ+13Nxxrad77DSCiZu/QfsmTw4uHpzOqlCKfPHm 8tQEZJEAfvFb0NnPUmcY56kPi6px0NYb32oXYjPWfxNvVzJdUGuTkBrw95WaAG2ntv DssFBAdUHUikTzRQ/22pSK7T7OXyuWuSHXCHE73yFC3Qk65s/CS35LnAxd62/gbF3D H4DgXHcESA1fg== From: Chuck Lever Subject: [PATCH 0/3] Fix NFSD post-shutdown use-after-free in the unlock_filesystem paths Date: Sat, 13 Jun 2026 18:16:31 -0400 Message-Id: <20260613-unlock-filesystem-uaf-v1-0-462b9bec8c84@kernel.org> 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 X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWMQQ6CMBBFr0Jm7USokQavYlwMZQqjWEinNRrC3 QVdvp//3gLKUVjhUiwQ+SUqU9igOhTgBgo9o3QbgylNXdbVCXMYJ/dALyPrRxM/MZPHpiF7ttY Rk4HNnSN7ef+619ufNbd3dmmP7Y+WlLGNFNywT47HY/DaYWJNEnpY1y/cTSv0nAAAAA== X-Change-ID: 20260613-unlock-filesystem-uaf-99a7577caea2 To: Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Musaab Khan , linux-nfs@vger.kernel.org, Chuck Lever X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2300; i=cel@kernel.org; h=from:subject:message-id; bh=dSZVqqZK+wzjQqLxHShwg64UsD5cGG3X5gZ2D/WdOKk=; b=owEBbQKS/ZANAwAKATNqszNvZn+XAcsmYgBqLdbEgMzxwztgqp05hGDEeVGbvbc+WoZJuSkBd 1PNosZjbmOJAjMEAAEKAB0WIQQosuWwEobfJDzyPv4zarMzb2Z/lwUCai3WxAAKCRAzarMzb2Z/ lxYTD/48T248W5RdNWjdPuXpFqghQotZXLmxo2RkedwM7LzIhzp+MV7U/r85V9JUyl2qOkrCHrN pstTkiHe1aXfM9DiSFh5bIyLk+BelJGQxJYAJvkoKyphvX284guJiJvMMU/DrqZfYQbQjhM4X18 E50MztWMGr+zaZztUnBMx8LpT03oDCtQ5801fyoRjpOVZetfOFRskB8rQKcA0WGh/XDvvAEyrC+ 14KdsBLWR23b81U67MtrtihH1NKoqziXRpcJmT5SZqPX/KJvdW3ZFv3s4J5gNejJqyX/8hoqx37 kt39nH+pYucxGNCEDLMkJb/qPKtDg41NnsxIYn4+QfRDCovxja+/6TmoEpDUIanN04uB+bQZ21m R6CuhmsyOSfMq32vN0b/yEsIqYwiTJaVuiOPhU5hob5506cLhZ07QYThcNY3A+DFzsdclS75L95 LxR2BlZ0ppAnQm/ZFxDeKIQdY47NndNsakzCzoicrTHzOBg17KGhniQP3TblqLN4wDfhLdUDJ+z olAzfvH0UvEJ2N3C5YdhSPsfjZHnoFXqJ3rgyrwmEwQ7vnZV6aFUk3Tv1bpo9Gnl89HmTdykkd3 Dhw0cnyNYth8mwNfBN6xuqzO9uPzsBQCmOPLkfeeo4hULEaB4XbsCosqXT26jlNIGP9iUudFsUy eyMHqeg0GY8rKcQ== X-Developer-Key: i=cel@kernel.org; a=openpgp; fpr=28B2E5B01286DF243CF23EFE336AB3336F667F97 Musaab Khan reported that a local administrator holding CAP_SYS_ADMIN can trigger a use-after-free in nfsd by writing a filesystem path to /proc/fs/nfsd/unlock_filesystem after the server has been stopped. write_unlock_fs() calls nfsd4_cancel_copy_by_sb() before it takes nfsd_mutex and before it confirms that nn->nfsd_serv is set. Once nfsd has shut down, nfs4_state_destroy_net() has freed nn->conf_id_hashtbl but left the pointer intact, so the cancel helper walks freed slab memory as an array of struct list_head and then dereferences a bogus nfs4_client when it takes clp->async_lock. KASAN reports a slab-use-after-free read in nfsd4_cancel_copy_by_sb(). nfsd4_revoke_states() walks the same state tables and for that reason already runs only under nfsd_mutex with nn->nfsd_serv confirmed present. The async COPY cancel was added ahead of that protected section, so it escaped the guard. The first two patches move the cancel inside the protected section on both the procfs unlock_filesystem path and the NFSD_CMD_UNLOCK_FILESYSTEM netlink path. Async copies exist only while the server runs, so gating the cancel on nn->nfsd_serv loses nothing. The netlink command that patch 2 corrects, 327c5168eff2 ("NFSD: Add NFSD_CMD_UNLOCK_FILESYSTEM netlink command"), has not yet reached mainline; it sits in nfsd-next, destined for v7.2. Patch 2 therefore applies to nfsd-next, not to a released kernel, and needs no stable backport. The last patch adds lockdep_assert_held(&nfsd_mutex) to the state-table walkers and documents the nfsd_mutex / nn->nfsd_serv precondition in a Context: kdoc section, so a future caller added to this path cannot silently reintroduce the same use-after-free. --- Chuck Lever (3): NFSD: Prevent post-shutdown use-after-free in unlock_filesystem NFSD: Prevent post-shutdown use-after-free in NFSD_CMD_UNLOCK_FILESYSTEM NFSD: Annotate caller preconditions for the state-table walkers fs/nfsd/nfs4proc.c | 6 ++++++ fs/nfsd/nfs4state.c | 16 +++++++++++++++- fs/nfsd/nfsctl.c | 14 ++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) --- base-commit: 56d6b74e37708005739ef00bb59db34bffac15a8 change-id: 20260613-unlock-filesystem-uaf-99a7577caea2 Best regards, -- Chuck Lever