Commit 89f39af1 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Al Viro

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: default avatarNikolay Borisov <kernel@kyup.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 655042cc
...@@ -1379,8 +1379,8 @@ int freeze_super(struct super_block *sb) ...@@ -1379,8 +1379,8 @@ int freeze_super(struct super_block *sb)
} }
} }
/* /*
* This is just for debugging purposes so that fs can warn if it * For debugging purposes so that fs can warn if it sees write activity
* sees write activity when frozen is set to SB_FREEZE_COMPLETE. * when frozen is set to SB_FREEZE_COMPLETE, and for thaw_super().
*/ */
sb->s_writers.frozen = SB_FREEZE_COMPLETE; sb->s_writers.frozen = SB_FREEZE_COMPLETE;
up_write(&sb->s_umount); up_write(&sb->s_umount);
...@@ -1399,7 +1399,7 @@ int thaw_super(struct super_block *sb) ...@@ -1399,7 +1399,7 @@ int thaw_super(struct super_block *sb)
int error; int error;
down_write(&sb->s_umount); down_write(&sb->s_umount);
if (sb->s_writers.frozen == SB_UNFROZEN) { if (sb->s_writers.frozen != SB_FREEZE_COMPLETE) {
up_write(&sb->s_umount); up_write(&sb->s_umount);
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment