From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796222522; b=NNQokCM49hg3d8gglKEdt+XZ6HPud2Fc8RFhObn0AiKKj7QJsCt1VDinoyYdxMq9YPY7 cqt9bK3ZUqUIYgdJfQuCjd37MgXWaKx17pdQBMRtc0CeVflQMstncVlc5Vm1wA/eOfw+I pnCVN7210QwFUs0JSBe/pvhIcWU07YmE1KZtBJRBuvE6QOTu/3rtz7pFPK+i4H0kgHBYP V4N7vlLZ1serVjX2qjmBPBYvEwP8e0QMw+69yNtwTtZsaY3UzKuD8o/adZUZLCXMNp4MM qO2yX956PS2OmiFPbDsiPjvK50JvzrALnMAM2QKHg2fMsh2EwbT1Vp6Xl4RLvoyr0eQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796222522; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=rrJb8cCE/RJF5hQdAc/2JaI1fe6PDkaXwQxoU+e0F9E=; b=EDyCNTmXP7OZGDLY+IDSslvfQ8NJoiGXLucZx1UL4soFE6prU//xq3AYzairUB5IlajO lrb//vR5XqSJ8nsl5SFgj7EdW2bsyNHz/yzfqZK+h3A9Kgw7f0zkvbeZ3uAXfXGJ6Vq/P 9lbZMRelISJBd4v+fE7JCd8X5RRsEOaH0T6p8e2kKaSJ/fWGqpXevCcCuq8MvYckXiTdW 02YhT2CJdGcoHMRpzMk4uM0BP+FH89g+X+Xjm1meek4h4Ex/0K9wbDr8gHUVIi72uKnX+ bsu9nsl/ZP5bnevOUPCHG+IyA0xpT/9XA2JdWQyG7zidzHtY6w0g6zG4QsVf5pCxLiQ== 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=TsXRCWHe; arc=none smtp.remote-ip=100.103.45.18 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 ESMTPS id 30F95606A31A for ; Wed, 2 Dec 2026 14:42:01 +0000 (UTC) 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=TsXRCWHe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99AAF1F000C1; Wed, 2 Dec 2026 14:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796222521; bh=rrJb8cCE/RJF5hQdAc/2JaI1fe6PDkaXwQxoU+e0F9E=; h=From:To:Cc:Subject:Date; b=TsXRCWHeV94liDYkKw3Fq6m+qzePfHLB1q5nXG1KnjCEr8kK9pqOmyNO1ljzHLLDt SQyYfSwf6cJSp8BEckVeP5y3ttdvF6CaQUdBR9RK2RiV7qbIsRryN25hNyd6Yrtcso 0A2tbIOhtE3tYeAgaLm0S8ErqvZgzsU129hnfHlDo2z/saIqkiG6KK1Z2Wp5tvJ7/a JpMB4SAtgTqdf3YBdRZr/47PEAuOuI0abCpj0/7yTdHSqPGL2m1Xd91YiwKhf9DFRQ bt2vE1Ac7w52MnzjmTedm1an6QFqIiGuJ6kfY9LQki4VahCxLwvme6kAXxzJWiamkR QZwk+i7/QP4ZQ== From: Chuck Lever To: NeilBrown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Subject: [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru Date: Wed, 2 Dec 2026 09:41:59 -0500 Message-ID: <20261202144159.108984-1-cel@kernel.org> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit An NFSv4.0 OPEN that evicts an unconfirmed openowner can race with a CLOSE on that owner. release_openowner() takes the owner off nn->close_lru only when oo_last_closed_stid is set. That field stays NULL until the CLOSE reaches move_to_close_lru(), which then adds the unhashed owner to the list. __destroy_client() finds close_lru entries only through cl_openowners, so it misses the stranded owner and frees the nfs4_client. The laundromat later reads the freed client through oo_owner.so_client, and can go on to take cl_lock in it: BUG: KASAN: slab-use-after-free in is_client_expired Read of size 8 by task kworker/u19:2/84 Workqueue: nfsd4 laundromat_main is_client_expired nfs4_laundromat laundromat_main Freed by task 84: kmem_cache_free free_client __destroy_client expire_client nfs4_process_client_reaplist nfs4_laundromat Any client permitted to OPEN on an NFSv4.0 export can provoke the use-after-free. NFSv4.1 and later create openowners confirmed. After the list add in move_to_close_lru(), test under cl_lock whether the owner is hashed, and if not, remove it with release_last_closed_stateid(). release_openowner() unhashes the owner under cl_lock before it reads oo_last_closed_stid under client_lock. move_to_close_lru() sets oo_last_closed_stid under client_lock before its test under cl_lock. At least one of the two therefore removes the owner, and release_last_closed_stateid() drops the stateid reference only once. Until that test, a fresh oo_time keeps the laundromat off the owner, and the CLOSE pins the client through cl_rpc_users. Testing inside the existing client_lock section would need a second path that skips the list add and puts the stateid by hand. Fixes: 3234975f477f ("nfsd: Remove nfs4_lock_state(): nfsd4_open and nfsd4_open_confirm") Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 6ddb35f5ae5a..c40b48125202 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6145,8 +6145,9 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net) { struct nfs4_ol_stateid *last; struct nfs4_openowner *oo = openowner(s->st_stateowner); - struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, - nfsd_net_id); + struct nfs4_client *clp = s->st_stid.sc_client; + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + bool unhashed; dprintk("NFSD: move_to_close_lru nfs4_openowner %p\n", oo); @@ -6178,6 +6179,17 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net) spin_unlock(&nn->client_lock); if (last) nfs4_put_stid(&last->st_stid); + + /* + * A release_openowner() that reads oo_last_closed_stid before the + * store above leaves @oo on close_lru unhashed. __destroy_client() + * reaches close_lru entries only through cl_openowners. + */ + spin_lock(&clp->cl_lock); + unhashed = nfs4_openowner_unhashed(oo); + spin_unlock(&clp->cl_lock); + if (unhashed) + release_last_closed_stateid(oo); } static noinline_for_stack struct nfs4_file * -- 2.56.0