aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2016-09-26 12:07:48 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2016-10-14 20:00:34 -0400
commit89f39af129382a40d7cd1f6914617282cfeee28e (patch)
tree01c7ce34eda659481fba92293365b3a07c725d16
parent655042cc1406fcec20aa7ffd7d790ada18ac5211 (diff)
fs/super.c: fix race between freeze_super() and thaw_super()
Change thaw_super() to check frozen != SB_FREEZE_COMPLETE rather than frozen == SB_UNFROZEN, otherwise it can race with freeze_super() which drops sb->s_umount after SB_FREEZE_WRITE to preserve the lock ordering. In this case thaw_super() will wrongly call s_op->unfreeze_fs() before it was actually frozen, and call sb_freeze_unlock() which leads to the unbalanced percpu_up_write(). Unfortunately lockdep can't detect this, so this triggers misc BUG_ON()'s in kernel/rcu/sync.c. Reported-and-tested-by: Nikolay Borisov <kernel@kyup.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/super.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/super.c b/fs/super.c
index c2ff475c1711..47d11e0462d0 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1379,8 +1379,8 @@ int freeze_super(struct super_block *sb)
1379 } 1379 }
1380 } 1380 }
1381 /* 1381 /*
1382 * This is just for debugging purposes so that fs can warn if it 1382 * For debugging purposes so that fs can warn if it sees write activity
1383 * sees write activity when frozen is set to SB_FREEZE_COMPLETE. 1383 * when frozen is set to SB_FREEZE_COMPLETE, and for thaw_super().
1384 */ 1384 */
1385 sb->s_writers.frozen = SB_FREEZE_COMPLETE; 1385 sb->s_writers.frozen = SB_FREEZE_COMPLETE;
1386 up_write(&sb->s_umount); 1386 up_write(&sb->s_umount);
@@ -1399,7 +1399,7 @@ int thaw_super(struct super_block *sb)
1399 int error; 1399 int error;
1400 1400
1401 down_write(&sb->s_umount); 1401 down_write(&sb->s_umount);
1402 if (sb->s_writers.frozen == SB_UNFROZEN) { 1402 if (sb->s_writers.frozen != SB_FREEZE_COMPLETE) {
1403 up_write(&sb->s_umount); 1403 up_write(&sb->s_umount);
1404 return -EINVAL; 1404 return -EINVAL;
1405 } 1405 }