diff options
author | npiggin@suse.de <npiggin@suse.de> | 2010-06-24 13:02:14 +1000 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-06-29 10:38:22 -0700 |
commit | 57439f878afafefad8836ebf5c49da2a0a746105 (patch) | |
tree | ec11dd35704aa37d77a5fd8404fda57f297a3834 /include/linux/list.h | |
parent | 5904b3b81d25166e5e39b9727645bb47937618e3 (diff) | |
download | linux-57439f878afafefad8836ebf5c49da2a0a746105.tar.gz linux-57439f878afafefad8836ebf5c49da2a0a746105.tar.bz2 linux-57439f878afafefad8836ebf5c49da2a0a746105.zip |
fs: fix superblock iteration race
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>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Frank Mayhar <fmayhar@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/list.h')
-rw-r--r-- | include/linux/list.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/list.h b/include/linux/list.h index 8392884a2977..5d57a3a1fa1b 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -544,6 +544,21 @@ static inline void list_splice_tail_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** + * list_safe_reset_next - reset a stale list_for_each_entry_safe loop + * @pos: the loop cursor used in the list_for_each_entry_safe loop + * @n: temporary storage used in list_for_each_entry_safe + * @member: the name of the list_struct within the struct. + * + * list_safe_reset_next is not safe to use in general if the list may be + * modified concurrently (eg. the lock is dropped in the loop body). An + * exception to this is if the cursor element (pos) is pinned in the list, + * and list_safe_reset_next is called after re-taking the lock and before + * completing the current iteration of the loop body. + */ +#define list_safe_reset_next(pos, n, member) \ + n = list_entry(pos->member.next, typeof(*pos), member) + /* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is |