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

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>, <stable@...>
Cc: <linux-kernel@...>, George G. Davis <gdavis@...>, Andrew Morton <akpm@...>, <linux-fsdevel@...>
Date: Sunday, October 28, 2007 - 1:31 pm

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

I think the real solution is to remove deadlock detection completely;
it's hard to imaagine applications really depend on it anyway.

For now, though, just bail out after a few iterations.

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 |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 0127a28..131aa88 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -696,17 +696,29 @@ 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.  We don't bother returning EDEADLK in that case;
+ * the deadlock has probably already happened anyway.
  */
+
+#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

-
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:
[PATCH] locks: fix possible infinite loop in posix deadlock ..., J. Bruce Fields, (Sun Oct 28, 1:31 pm)
[RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 1:43 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Tue Oct 30, 11:51 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 2:27 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 9:13 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 4:11 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Trond Myklebust, (Sun Oct 28, 5:50 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 6:41 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Trond Myklebust, (Sun Oct 28, 11:26 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 10:10 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 7:31 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 6:55 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Sun Oct 28, 10:29 pm)
Re: [RFC, PATCH] locks: remove posix deadlock detection, J. Bruce Fields, (Tue Oct 30, 11:35 am)
Re: [RFC, PATCH] locks: remove posix deadlock detection, Matthew Wilcox, (Sun Oct 28, 7:38 pm)