NFSD: Fix delegation reference leak in nfsd4_revoke_states
Subsystems (2)
Chuck Lever
maintainerPATCH 1/1 NFSD: Fix delegation reference leak in nfsd4_revoke_states
From: Chuck Lever <[email protected]>
When revoking delegation state, nfsd4_revoke_states() takes an extra reference on the stid before calling unhash_delegation_locked(). If unhash_delegation_locked() returns false (the delegation was already unhashed by a concurrent path), dp is set to NULL and revoke_delegation() is skipped, but the extra reference is never released. Each occurrence permanently pins the stid in memory. The leaked reference also prevents nfs4_put_stid() from decrementing cl_admin_revoked, leaving the counter permanently inflated.
Drop the extra reference in the failure path.
--- fs/nfsd/nfs4state.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/nfsd/nfs4state.c +8 -1
@@ -1389,7 +1389,8 @@ static void destroy_delegation(struct nfs4_delegation *dp)* stateid or it's called from a laundromat thread (nfsd4_landromat()) that * determined that this specific state has expired and needs to be revoked * (both mark state with the appropriate stid sc_status mode). It is also -* assumed that a reference was taken on the @dp state. +* assumed that a reference was taken on the @dp state. This function +* consumes that reference. * * If this function finds that the @dp state is SC_STATUS_FREED it means * that a FREE_STATEID operation for this stateid has been processed and
@@ -1836,6 +1837,10 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)mutex_unlock (&stp->st_mutex);break ;case SC_TYPE_DELEG : +/* Extra reference guards against concurrent +* FREE_STATEID; revoke_delegation() consumes +* it, otherwise release it directly. +*/ refcount_inc (&stid->sc_count); dp =delegstateid (stid);spin_lock (&state_lock);
@@ -1845,6 +1850,8 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)spin_unlock (&state_lock);if (dp)revoke_delegation (dp); +else +nfs4_put_stid (stid);break ;case SC_TYPE_LAYOUT : ls =layoutstateid (stid);
Signature · 1 line
2.53.0
Quoted 45 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When revoking delegation state,
nfsd4_revoke_states()takes an extra reference on the stid before callingunhash_delegation_locked(). Ifunhash_delegation_locked()returns false (the delegation was already unhashed by a concurrent path), dp is set to NULL andrevoke_delegation()is skipped, but the extra reference is never released. Each occurrence permanently pins the stid in memory. The leaked reference also preventsnfs4_put_stid()from decrementingcl_admin_revoked, leaving the counter permanently inflated.Drop the extra reference in the failure path.
Fixes 8dd91e8d31fe ("nfsd: fix race between laundromat and free_stateid")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +6
-1@@ -1389,7 +1389,8 @@ static void destroy_delegation(struct nfs4_delegation *dp)* stateid or it's called from a laundromat thread (nfsd4_landromat()) that * determined that this specific state has expired and needs to be revoked * (both mark state with the appropriate stid sc_status mode). It is also -* assumed that a reference was taken on the @dp state. +* assumed that a reference was taken on the @dp state. This function +* consumes that reference. * * If this function finds that the @dp state is SC_STATUS_FREED it means * that a FREE_STATEID operation for this stateid has been processed and @@ -1836,6 +1837,10 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)mutex_unlock (&stp->st_mutex);break ;case SC_TYPE_DELEG : +/* Extra reference guards against concurrent +* FREE_STATEID; revoke_delegation() consumes +* it, otherwise release it directly. +*/ refcount_inc (&stid->sc_count); dp =delegstateid (stid);spin_lock (&state_lock);
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb) · line 1857
Quoted 8 lines
fs/nfsd/nfs4state.c +2
-0@@ -1845,6 +1850,8 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)spin_unlock (&state_lock);if (dp)revoke_delegation (dp); +else +nfs4_put_stid (stid);break ;case SC_TYPE_LAYOUT : ls =layoutstateid (stid);
Good catch!