Skip to content

Commit

Permalink
fs/super.c: fix race between freeze_super() and thaw_super()
Browse files Browse the repository at this point in the history
commit 89f39af upstream.

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 <[email protected]>
Signed-off-by: Oleg Nesterov <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
oleg-nesterov authored and gregkh committed Oct 12, 2017
1 parent 9d3562b commit 7798893
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,8 @@ int freeze_super(struct super_block *sb)
}
}
/*
* This is just for debugging purposes so that fs can warn if it
* sees write activity when frozen is set to SB_FREEZE_COMPLETE.
* For debugging purposes so that fs can warn if it sees write activity
* when frozen is set to SB_FREEZE_COMPLETE, and for thaw_super().
*/
sb->s_writers.frozen = SB_FREEZE_COMPLETE;
up_write(&sb->s_umount);
Expand All @@ -1366,7 +1366,7 @@ int thaw_super(struct super_block *sb)
int error;

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);
return -EINVAL;
}
Expand Down

0 comments on commit 7798893

Please sign in to comment.