login
Header Space

 
 

Re: nfs: infinite loop in fcntl(F_SETLKW)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Miklos Szeredi <miklos@...>
Cc: <trond.myklebust@...>, <eshel@...>, <neilb@...>, <akpm@...>, <linux-nfs@...>, <linux-kernel@...>, <linux-fsdevel@...>
Date: Saturday, April 12, 2008 - 8:08 pm

On Fri, Apr 11, 2008 at 09:12:23PM +0200, Miklos Szeredi wrote:

So, does this patch on its own fix the problem you saw?

Any extra eyes welcome....

--b.

commit e56100676b9ea3b2d5f3e937c3ce8a5149cffb84
Author: J. Bruce Fields <bfields@citi.umich.edu>
Date:   Sat Apr 12 18:12:15 2008 -0400

    locks: fix possible infinite loop in fcntl(F_SETLKW) over nfs
    
    Miklos Szeredi found the bug:
    
    	"Basically what happens is that on the server nlm_fopen() calls
    	nfsd_open() which returns -EACCES, to which nlm_fopen() returns
    	NLM_LCK_DENIED.
    
    	"On the client this will turn into a -EAGAIN (nlm_stat_to_errno()),
    	which in will cause fcntl_setlk() to retry forever."
    
    So, for example, opening a file on an nfs filesystem, changing
    permissions to forbid further access, then trying to lock the file,
    could result in an infinite loop.
    
    And Trond Myklebust identified the culprit, from Marc Eshel and I:
    
    	7723ec9777d9832849b76475b1a21a2872a40d20 "locks: factor out
    	generic/filesystem switch from setlock code"
    
    That commit claimed to just be reshuffling code, but actually introduced
    a behavioral change by calling the lock method repeatedly as long as it
    returned -EAGAIN.
    
    We assumed this would be safe, since we assumed a lock of type SETLKW
    would only return with either success or an error other than -EAGAIN.
    However, nfs does can in fact return -EAGAIN in this situation, and
    independently of whether that behavior is correct or not, we don't
    actually need this change, and it seems far safer not to depend on such
    assumptions about the filesystem's ->lock method.
    
    Therefore, revert the problematic part of the original commit.  This
    leaves vfs_lock_file() and its other callers unchanged, while returning
    fcntl_setlk and fcntl_setlk64 to their former behavior.
    
    Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
    Cc: Miklos Szeredi <mszeredi@suse.cz>
    Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
    Cc: Marc Eshel <eshel@almaden.ibm.com>

diff --git a/fs/locks.c b/fs/locks.c
index d83fab1..43c0af2 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1801,17 +1801,21 @@ again:
 	if (error)
 		goto out;
 
-	for (;;) {
-		error = vfs_lock_file(filp, cmd, file_lock, NULL);
-		if (error != -EAGAIN || cmd == F_SETLK)
-			break;
-		error = wait_event_interruptible(file_lock->fl_wait,
-				!file_lock->fl_next);
-		if (!error)
-			continue;
+	if (filp->f_op && filp->f_op->lock != NULL)
+		error = filp->f_op->lock(filp, cmd, file_lock);
+	else {
+		for (;;) {
+			error = posix_lock_file(filp, file_lock, NULL);
+			if (error != -EAGAIN || cmd == F_SETLK)
+				break;
+			error = wait_event_interruptible(file_lock->fl_wait,
+					!file_lock->fl_next);
+			if (!error)
+				continue;
 
-		locks_delete_block(file_lock);
-		break;
+			locks_delete_block(file_lock);
+			break;
+		}
 	}
 
 	/*
@@ -1925,17 +1929,21 @@ again:
 	if (error)
 		goto out;
 
-	for (;;) {
-		error = vfs_lock_file(filp, cmd, file_lock, NULL);
-		if (error != -EAGAIN || cmd == F_SETLK64)
-			break;
-		error = wait_event_interruptible(file_lock->fl_wait,
-				!file_lock->fl_next);
-		if (!error)
-			continue;
+	if (filp->f_op && filp->f_op->lock != NULL)
+		error = filp->f_op->lock(filp, cmd, file_lock);
+	else {
+		for (;;) {
+			error = posix_lock_file(filp, file_lock, NULL);
+			if (error != -EAGAIN || cmd == F_SETLK64)
+				break;
+			error = wait_event_interruptible(file_lock->fl_wait,
+					!file_lock->fl_next);
+			if (!error)
+				continue;
 
-		locks_delete_block(file_lock);
-		break;
+			locks_delete_block(file_lock);
+			break;
+		}
 	}
 
 	/*
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Thu Apr 10, 3:51 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Trond Myklebust, (Thu Apr 10, 5:02 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Trond Myklebust, (Thu Apr 10, 5:07 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Trond Myklebust, (Thu Apr 10, 5:20 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Thu Apr 10, 5:54 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Sun Apr 13, 4:28 am)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Mon Apr 14, 1:19 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Mon Apr 14, 5:15 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Tue Apr 15, 2:58 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Wed Apr 16, 12:28 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Thu Apr 17, 6:26 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Fri Apr 18, 8:47 am)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Fri Apr 11, 3:12 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Sat Apr 12, 8:08 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Sun Apr 13, 4:13 am)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Mon Apr 14, 1:07 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), J. Bruce Fields, (Fri Apr 11, 3:19 pm)
Re: nfs: infinite loop in fcntl(F_SETLKW), Miklos Szeredi, (Fri Apr 11, 3:22 pm)
speck-geostationary