* [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru
@ 2026-12-02 14:41 Chuck Lever
2026-12-02 14:53 ` Jeff Layton
0 siblings, 1 reply; 2+ messages in thread
From: Chuck Lever @ 2026-12-02 14:41 UTC (permalink / raw)
To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey; +Cc: linux-nfs
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 <cel@kernel.org>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru
2026-12-02 14:41 [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru Chuck Lever
@ 2026-12-02 14:53 ` Jeff Layton
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2026-12-02 14:53 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey; +Cc: linux-nfs
On Wed, 2026-12-02 at 09:41 -0500, Chuck Lever wrote:
> 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 <cel@kernel.org>
> ---
> 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 *
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 14:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 14:41 [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru Chuck Lever
2026-12-02 14:53 ` Jeff Layton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.