f2fs: fix freezing filesystem during resize

Using FREEZE_HOLDER_USERSPACE has two consequences:

(1) If userspace freezes the filesystem after mnt_drop_write_file() but
    before freeze_super() was called filesystem resizing will fail
    because the freeze isn't marked as nestable.

(2) If the kernel has successfully frozen the filesystem via
    FREEZE_HOLDER_USERSPACE userspace can simply undo it by using the
    FITHAW ioctl.

Fix both issues by using FREEZE_HOLDER_KERNEL. It will nest with
FREEZE_HOLDER_USERSPACE and cannot be undone by userspace.

And it is the correct thing to do because the kernel temporarily freezes
the filesystem.

Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-04-06 22:28:52 +02:00
parent 05b158d4fd
commit 1afe9e7da8
No known key found for this signature in database
GPG key ID: 91C61BC06578DCA2

View file

@ -2271,12 +2271,12 @@ out_drop_write:
if (err)
return err;
err = freeze_super(sbi->sb, FREEZE_HOLDER_USERSPACE, NULL);
err = freeze_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
if (err)
return err;
if (f2fs_readonly(sbi->sb)) {
err = thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE, NULL);
err = thaw_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
if (err)
return err;
return -EROFS;
@ -2333,6 +2333,6 @@ recover_out:
out_err:
f2fs_up_write(&sbi->cp_global_sem);
f2fs_up_write(&sbi->gc_lock);
thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE, NULL);
thaw_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
return err;
}