Message ID | 1524445859-26970-4-git-send-email-amir73il@gmail.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | Fix ext4 freeze protection bypass | expand |
On Sun 22-04-18 18:10:59, Amir Goldstein wrote: > If fs is frozen after mount and before the first file open, the > update of s_last_mounted bypasses freeze protection and prints out > a WARNING splat: > > $ mount /vdf > $ fsfreeze -f /vdf > $ cat /vdf/foo > > [ 31.578555] WARNING: CPU: 1 PID: 1415 at > fs/ext4/ext4_jbd2.c:53 ext4_journal_check_start+0x48/0x82 > > [ 31.614016] Call Trace: > [ 31.614997] __ext4_journal_start_sb+0xe4/0x1a4 > [ 31.616771] ? ext4_file_open+0xb6/0x189 > [ 31.618094] ext4_file_open+0xb6/0x189 > > If fs is frozen, skip s_last_mounted update. > > [backport hint: to apply to stable tree, need to apply also patches > vfs: add the sb_start_intwrite_trylock() helper > ext4: factor out helper ext4_sample_last_mounted()] Looks good to me. Just one nit: > @@ -406,12 +406,14 @@ static int ext4_sample_last_mounted(struct super_block *sb, > path.mnt = mnt; > path.dentry = mnt->mnt_root; > cp = d_path(&path, buf, sizeof(buf)); > + err = 0; > if (IS_ERR(cp)) > - return 0; > + goto out_intwrite; > > handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); > + err = PTR_ERR(handle); > if (IS_ERR(handle)) > - return PTR_ERR(handle); > + goto out_intwrite; > BUFFER_TRACE(sbi->s_sbh, "get_write_access"); > err = ext4_journal_get_write_access(handle, sbi->s_sbh); > if (err) > @@ -421,6 +423,8 @@ static int ext4_sample_last_mounted(struct super_block *sb, > ext4_handle_dirty_super(handle, sb); > out: > ext4_journal_stop(handle); > +out_intwrite: > + sb_end_intwrite(sb); > return err; > } Usually 'out' is the outermost label. So I'd rename 'out' to 'out_journal' to avoid confusion in the future. With that fixed feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza
diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 065e95bb7186..f097a76ee54e 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -392,7 +392,7 @@ static int ext4_sample_last_mounted(struct super_block *sb, if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED)) return 0; - if (sb_rdonly(sb)) + if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb)) return 0; sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED; @@ -406,12 +406,14 @@ static int ext4_sample_last_mounted(struct super_block *sb, path.mnt = mnt; path.dentry = mnt->mnt_root; cp = d_path(&path, buf, sizeof(buf)); + err = 0; if (IS_ERR(cp)) - return 0; + goto out_intwrite; handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); + err = PTR_ERR(handle); if (IS_ERR(handle)) - return PTR_ERR(handle); + goto out_intwrite; BUFFER_TRACE(sbi->s_sbh, "get_write_access"); err = ext4_journal_get_write_access(handle, sbi->s_sbh); if (err) @@ -421,6 +423,8 @@ static int ext4_sample_last_mounted(struct super_block *sb, ext4_handle_dirty_super(handle, sb); out: ext4_journal_stop(handle); +out_intwrite: + sb_end_intwrite(sb); return err; }
If fs is frozen after mount and before the first file open, the update of s_last_mounted bypasses freeze protection and prints out a WARNING splat: $ mount /vdf $ fsfreeze -f /vdf $ cat /vdf/foo [ 31.578555] WARNING: CPU: 1 PID: 1415 at fs/ext4/ext4_jbd2.c:53 ext4_journal_check_start+0x48/0x82 [ 31.614016] Call Trace: [ 31.614997] __ext4_journal_start_sb+0xe4/0x1a4 [ 31.616771] ? ext4_file_open+0xb6/0x189 [ 31.618094] ext4_file_open+0xb6/0x189 If fs is frozen, skip s_last_mounted update. [backport hint: to apply to stable tree, need to apply also patches vfs: add the sb_start_intwrite_trylock() helper ext4: factor out helper ext4_sample_last_mounted()] Fixes: bc0b0d6d69ee ("ext4: update the s_last_mounted field in the superblock") Cc: <stable@vger.kernel.org> Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- fs/ext4/file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)