[PATCH, RESEND] locks: fix possible infinite loop in posix deadlock detection

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: J. Bruce Fields
Date: Tuesday, October 30, 2007 - 8:20 am

From: J. Bruce Fields <bfields@citi.umich.edu>

It's currently possible to send posix_locks_deadlock() into an infinite
loop (under the BKL).

For now, fix this just by bailing out after a few iterations.  We may
want to fix this in a way that better clarifies the semantics of
deadlock detection.  But that will take more time, and this minimal fix
is probably adequate for any realistic scenario, and is simple enough to
be appropriate for applying to stable kernels now.

Thanks to George Davis for reporting the problem.

Cc: "George G. Davis" <gdavis@mvista.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
 fs/locks.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

I didn't see objections to this quick fix (just to the followup that
attempts to rip out posix deadlock detection entirely), so I'm
resending with just comment modifications.

I haven't given up on a more comprehensive solution, but I think we
really need to apply some fix now.

--b.

diff --git a/fs/locks.c b/fs/locks.c
index 0127a28..8b8388e 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -696,17 +696,28 @@ EXPORT_SYMBOL(posix_test_lock);
  * Note: the above assumption may not be true when handling lock requests
  * from a broken NFS client. But broken NFS clients have a lot more to
  * worry about than proper deadlock detection anyway... --okir
+ *
+ * However, the failure of this assumption (also possible in the case of
+ * multiple tasks sharing the same open file table) also means there's no
+ * guarantee that the loop below will terminate.  As a hack, we give up
+ * after a few iterations.
  */
+
+#define MAX_DEADLK_ITERATIONS 10
+
 static int posix_locks_deadlock(struct file_lock *caller_fl,
 				struct file_lock *block_fl)
 {
 	struct file_lock *fl;
+	int i = 0;
 
 next_task:
 	if (posix_same_owner(caller_fl, block_fl))
 		return 1;
 	list_for_each_entry(fl, &blocked_list, fl_link) {
 		if (posix_same_owner(fl, block_fl)) {
+			if (i++ > MAX_DEADLK_ITERATIONS)
+				return 0;
 			fl = fl->fl_next;
 			block_fl = fl;
 			goto next_task;
-- 
1.5.3.4.208.gc990

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH] Fix hang in posix_locks_deadlock(), George G. Davis, (Wed Oct 17, 11:51 am)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), George G. Davis, (Wed Oct 17, 4:41 pm)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), George G. Davis, (Thu Oct 18, 11:57 am)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), J. Bruce Fields, (Fri Oct 26, 10:07 am)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), J. Bruce Fields, (Fri Oct 26, 3:47 pm)
[RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 10:43 am)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), J. Bruce Fields, (Sun Oct 28, 10:47 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 11:27 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 1:11 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Trond Myklebust, (Sun Oct 28, 2:50 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 3:41 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 3:55 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 4:31 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 4:38 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 6:13 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 7:10 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 7:29 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Trond Myklebust, (Sun Oct 28, 8:26 pm)
[PATCH, RESEND] locks: fix possible infinite loop in posix ..., J. Bruce Fields, (Tue Oct 30, 8:20 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Tue Oct 30, 8:35 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Tue Oct 30, 8:51 am)
Re: [RFC][PATCH] Fix hang in posix_locks_deadlock(), George G. Davis, (Fri Nov 2, 8:05 am)