nfsd: don't put blocked locks on LRU until after vfs_lock_file returns
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 nfsd: don't put blocked locks on LRU until after vfs_lock_file returns
Vasily reported a case where vfs_lock_file took a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when the vfs_lock_file returned, it ended up accessing freed memory.
Don't put entries onto the LRU until vfs_lock_file returns.
--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +4 -2
@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }
@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */
Signature · 1 line
2.33.1
Quoted 6 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.Don't put entries onto the LRU until
vfs_lock_filereturns.
Quoted 2 lines
Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Quoted 31 lines
--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +4
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */
Quoted 10 lines · Vasily Averin
Quoted 5 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.
Quoted 8 lines
Quoted 1 line
Don't put entries onto the LRU until
vfs_lock_filereturns.Fixes 7919d0a27f1e "nfsd: add a LRU list for blocked locks"Quoted 2 lines
Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>Tested-by Vasily Averin <[email protected]>
I assume Bruce is grabbing this for v5.16-rc.
Quoted 19 lines
Quoted 19 lines
---
fs/nfsd/nfs4state.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +0
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }
Quoted 13 lines
fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 6989
Quoted 12 lines
fs/nfsd/nfs4state.c +4
-0@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */
--
Chuck Lever
Quoted 4 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.
By the way, once we've called vfs_lock_file(), is there anything preventing nfsd4_cb_notify_lock_release() from freeing nbl before we get here?
Quoted 37 lines
Don't put entries onto the LRU until
vfs_lock_filereturns.Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +4
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */ Signature · 1 line
2.33.1
Jeff Layton
maintainerQuoted 10 lines · J. Bruce Fields
Quoted 4 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.By the way, once we've called
vfs_lock_file(), is there anything preventingnfsd4_cb_notify_lock_release()from freeing nbl before we get here?
No, I don't think there is. Good catch.
Hmm...the only way I can see to fix that would be to add a refcount to these things, in which case we probably don't need this patch since it would prevent the original issue as well...
Quoted 37 lines
Quoted 37 lines
Don't put entries onto the LRU until
vfs_lock_filereturns.Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +4
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */ Signature · 1 line
2.33.1
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 7 lines · Jeff Layton
Quoted 6 lines · J. Bruce Fields
Quoted 4 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.
Quoted 6 lines
Quoted 4 lines
By the way, once we've called
vfs_lock_file(), is there anything preventingnfsd4_cb_notify_lock_release()from freeing nbl before we get here?No, I don't think there is. Good catch.
It may be a rare race (an rpc's not normally going to reply in that time), but I wouldn't be surprised if there's some error condition where it's possible.
Quoted 3 lines
Hmm...the only way I can see to fix that would be to add a refcount to these things, in which case we probably don't need this patch since it would prevent the original issue as well...
Depending on how long that might take, I'd be OK with applying this as a stopgap.
--b.
Quoted 41 lines
Quoted 38 lines
Quoted 38 lines
Don't put entries onto the LRU until
vfs_lock_filereturns.Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +4
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */ Signature · 1 line
2.33.1Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerQuoted 19 lines · J. Bruce Fields
Quoted 7 lines · Jeff Layton
Quoted 6 lines · J. Bruce Fields
Quoted 4 lines · Jeff Layton
Vasily reported a case where
vfs_lock_filetook a very long time to return (longer than a lease period). The laundromat eventually ran and reaped the thing and when thevfs_lock_filereturned, it ended up accessing freed memory.Quoted 6 lines
Quoted 4 lines
By the way, once we've called
vfs_lock_file(), is there anything preventingnfsd4_cb_notify_lock_release()from freeing nbl before we get here?No, I don't think there is. Good catch.
It may be a rare race (an rpc's not normally going to reply in that time), but I wouldn't be surprised if there's some error condition where it's possible.
Quoted 8 lines
Quoted 3 lines
Hmm...the only way I can see to fix that would be to add a refcount to these things, in which case we probably don't need this patch since it would prevent the original issue as well...
Depending on how long that might take, I'd be OK with applying this as a stopgap.
I won't have the cycles to do that anytime soon, unfortunately, so you may want to.
Quoted 41 lines
Quoted 41 lines
Quoted 38 lines
Quoted 38 lines
Don't put entries onto the LRU until
vfs_lock_filereturns.Reported-by Vasily Averin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +4
-2@@ -6966,10 +6966,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, }if (fl_flags &FL_SLEEP ) { - nbl->nbl_time =ktime_get_boottime_seconds ();spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked); -list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru);spin_unlock (&nn->blocked_locks_lock); }@@ -6982,6 +6980,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : + nbl->nbl_time =ktime_get_boottime_seconds (); +spin_lock (&nn->blocked_locks_lock); +list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +spin_unlock (&nn->blocked_locks_lock); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */ Signature · 1 line
2.33.1Signature · 1 line
Jeff Layton <[email protected]>
Signature · 1 line
Jeff Layton <[email protected]>