aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@citi.umich.edu>2008-04-14 15:03:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-14 15:22:14 -0400
commit19e729a928172103e101ffd0829fd13e68c13f78 (patch)
tree5d3492a6dd2191abebe27a8d59e181398375e9c8 /fs
parenta985aabe4d7a720b109c2b63549f8641676a9c88 (diff)
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> Tested-by: Miklos Szeredi <mszeredi@suse.cz> Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Cc: Marc Eshel <eshel@almaden.ibm.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/locks.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/fs/locks.c b/fs/locks.c
index d83fab1b77b5..43c0af21a0c5 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1801,17 +1801,21 @@ again:
1801 if (error) 1801 if (error)
1802 goto out; 1802 goto out;
1803 1803
1804 for (;;) { 1804 if (filp->f_op && filp->f_op->lock != NULL)
1805 error = vfs_lock_file(filp, cmd, file_lock, NULL); 1805 error = filp->f_op->lock(filp, cmd, file_lock);
1806 if (error != -EAGAIN || cmd == F_SETLK) 1806 else {
1807 break; 1807 for (;;) {
1808 error = wait_event_interruptible(file_lock->fl_wait, 1808 error = posix_lock_file(filp, file_lock, NULL);
1809 !file_lock->fl_next); 1809 if (error != -EAGAIN || cmd == F_SETLK)
1810 if (!error) 1810 break;
1811 continue; 1811 error = wait_event_interruptible(file_lock->fl_wait,
1812 !file_lock->fl_next);
1813 if (!error)
1814 continue;
1812 1815
1813 locks_delete_block(file_lock); 1816 locks_delete_block(file_lock);
1814 break; 1817 break;
1818 }
1815 } 1819 }
1816 1820
1817 /* 1821 /*
@@ -1925,17 +1929,21 @@ again:
1925 if (error) 1929 if (error)
1926 goto out; 1930 goto out;
1927 1931
1928 for (;;) { 1932 if (filp->f_op && filp->f_op->lock != NULL)
1929 error = vfs_lock_file(filp, cmd, file_lock, NULL); 1933 error = filp->f_op->lock(filp, cmd, file_lock);
1930 if (error != -EAGAIN || cmd == F_SETLK64) 1934 else {
1931 break; 1935 for (;;) {
1932 error = wait_event_interruptible(file_lock->fl_wait, 1936 error = posix_lock_file(filp, file_lock, NULL);
1933 !file_lock->fl_next); 1937 if (error != -EAGAIN || cmd == F_SETLK64)
1934 if (!error) 1938 break;
1935 continue; 1939 error = wait_event_interruptible(file_lock->fl_wait,
1940 !file_lock->fl_next);
1941 if (!error)
1942 continue;
1936 1943
1937 locks_delete_block(file_lock); 1944 locks_delete_block(file_lock);
1938 break; 1945 break;
1946 }
1939 } 1947 }
1940 1948
1941 /* 1949 /*