[Devel] [PATCH rh7 2/2] ms/nfsd: don't put blocked locks on LRU until after vfs_lock_file returns

Vasily Averin vvs at virtuozzo.com
Wed Nov 24 10:43:51 MSK 2021


From: Jeff Layton <jlayton at kernel.org>

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.

Cc: stable at vger.kernel.org
Fixes: 7919d0a27f1e "nfsd: add a LRU list for blocked locks"
Reported-by: Vasily Averin <vvs at virtuozzo.com>
Signed-off-by: Jeff Layton <jlayton at kernel.org>
Tested-by: Vasily Averin <vvs at virtuozzo.com>

(VvS: should be added to upstream soon)
https://lore.kernel.org/all/20211123122223.69236-1-jlayton@kernel.org
https://jira.sw.ru/browse/PSBM-102407
https://jira.sw.ru/browse/PSBM-121875
https://jira.sw.ru/browse/PSBM-121984
https://jira.sw.ru/browse/PSBM-129208
https://jira.sw.ru/browse/PSBM-129647
https://jira.sw.ru/browse/PSBM-133020
https://jira.sw.ru/browse/PSBM-133265
https://jira.sw.ru/browse/PSBM-133274
https://jira.sw.ru/browse/PSBM-134762
https://jira.sw.ru/browse/PSBM-134877
https://jira.sw.ru/browse/PSBM-134905
https://jira.sw.ru/browse/PSBM-135845
Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 fs/nfsd/nfs4state.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 4a57b40de542..ff64be32bd00 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -5991,10 +5991,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	}
 
 	if (fl_flags & FL_SLEEP) {
-		nbl->nbl_time = get_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);
 	}
 
@@ -6005,6 +6003,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		status = 0;
 		break;
 	case FILE_LOCK_DEFERRED:
+		nbl->nbl_time = get_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 */
-- 
2.25.1



More information about the Devel mailing list