]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
vfs: don't hold s_umount over close_bdev_exclusive() call
authorTejun Heo <tj@kernel.org>
Tue, 20 Jul 2010 22:18:07 +0000 (15:18 -0700)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 9 Aug 2010 20:48:59 +0000 (16:48 -0400)
Fix an obscure AB-BA deadlock in get_sb_bdev().

When a superblock is mounted more than once get_sb_bdev() calls
close_bdev_exclusive() to drop the extra bdev reference while holding
s_umount.  However, sb->s_umount nests inside bd_mutex during
__invalidate_device() and close_bdev_exclusive() acquires bd_mutex during
blkdev_put(); thus creating an AB-BA deadlock.

This condition doesn't trigger frequently.  For this condition to be
visible to lockdep, the filesystem must occupy the whole device (as
__invalidate_device() only grabs bd_mutex for the whole device), the FS
must be mounted more than once and partition rescan should be issued while
the FS is still mounted.

Fix it by dropping s_umount over close_bdev_exclusive().

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Ciprian Docan <docan@eden.rutgers.edu>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/super.c

index 938119ab8dcbc28f3f9853bc0808d6d70cd51d55..3479ca6f005ff7c87d22d52cd1381a89e06d0fbb 100644 (file)
@@ -773,7 +773,16 @@ int get_sb_bdev(struct file_system_type *fs_type,
                        goto error_bdev;
                }
 
+               /*
+                * s_umount nests inside bd_mutex during
+                * __invalidate_device().  close_bdev_exclusive()
+                * acquires bd_mutex and can't be called under
+                * s_umount.  Drop s_umount temporarily.  This is safe
+                * as we're holding an active reference.
+                */
+               up_write(&s->s_umount);
                close_bdev_exclusive(bdev, mode);
+               down_write(&s->s_umount);
        } else {
                char b[BDEVNAME_SIZE];