All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] fs: fix superblock iteration race
@ 2010-06-11 14:50 Nick Piggin
  2010-06-11 16:06 ` Linus Torvalds
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Piggin @ 2010-06-11 14:50 UTC (permalink / raw)
  To: Al Viro, Linus Torvalds, linux-fsdevel

Not sure if this is really the _cleanest_ way to fix it. But open coding
the list walking is a bit annoying too. And I couldn't see any real way to
make the list macro safe. Better ideas?

Thanks,
Nick

--
list_for_each_entry_safe is not suitable to protect against concurrent
modification of the list. 6754af6 introduced a race in sb walking.

list_for_each_entry can use the trick of pinning the current entry in
the list before we drop and retake the lock because it subsequently
follows cur->next. However list_for_each_entry_safe saves n=cur->next
for following before entering the loop body, so when the lock is
dropped, n may be deleted.

Signed-off-by: Nick Piggin <npiggin@suse.de>
---
 fs/dcache.c |    2 ++
 fs/super.c  |    6 ++++++
 2 files changed, 8 insertions(+)

Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c	2010-06-12 00:00:10.000000000 +1000
+++ linux-2.6/fs/dcache.c	2010-06-12 00:38:21.000000000 +1000
@@ -590,6 +590,8 @@ static void prune_dcache(int count)
 			up_read(&sb->s_umount);
 		}
 		spin_lock(&sb_lock);
+		/* old n may have been deleted */
+		n = list_entry(sb->s_list.next, struct super_block, s_list);
 		count -= pruned;
 		__put_super(sb);
 		/* more work left to do? */
Index: linux-2.6/fs/super.c
===================================================================
--- linux-2.6.orig/fs/super.c	2010-06-11 23:55:40.000000000 +1000
+++ linux-2.6/fs/super.c	2010-06-12 00:38:40.000000000 +1000
@@ -374,6 +374,8 @@ void sync_supers(void)
 			up_read(&sb->s_umount);
 
 			spin_lock(&sb_lock);
+			/* old n may have been deleted */
+			n = list_entry(sb->s_list.next, struct super_block, s_list);
 			__put_super(sb);
 		}
 	}
@@ -405,6 +407,8 @@ void iterate_supers(void (*f)(struct sup
 		up_read(&sb->s_umount);
 
 		spin_lock(&sb_lock);
+		/* old n may have been deleted */
+		n = list_entry(sb->s_list.next, struct super_block, s_list);
 		__put_super(sb);
 	}
 	spin_unlock(&sb_lock);
@@ -585,6 +589,8 @@ static void do_emergency_remount(struct
 		}
 		up_write(&sb->s_umount);
 		spin_lock(&sb_lock);
+		/* old n may have been deleted */
+		n = list_entry(sb->s_list.next, struct super_block, s_list);
 		__put_super(sb);
 	}
 	spin_unlock(&sb_lock);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-06-14 15:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-11 14:50 [patch] fs: fix superblock iteration race Nick Piggin
2010-06-11 16:06 ` Linus Torvalds
2010-06-12  3:37   ` Nick Piggin
2010-06-12  3:57   ` Nick Piggin
2010-06-12  4:15     ` Linus Torvalds
2010-06-12  4:38       ` Nick Piggin
2010-06-12  4:46         ` Linus Torvalds
2010-06-14 15:07           ` Nick Piggin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.