f2fs: fix potential corruption in area before F2FS_SUPER_OFFSET
authorSheng Yong <shengyong1@huawei.com>
Mon, 29 Jan 2018 11:13:15 +0000 (19:13 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 8 Apr 2018 11:07:40 +0000 (04:07 -0700)
sb_getblk does not guarantee the buffer head is uptodate. If bh is not
uptodate, the data (may be used as boot code) in area before
F2FS_SUPER_OFFSET may get corrupted when super block is committed.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/super.c

index 0f8945bc4b4b9a93690da7e3e5f261d0d01168ac..80847f9411b21d0a3843ba026f24181f90c221bd 100644 (file)
@@ -1894,7 +1894,6 @@ static int __f2fs_commit_super(struct buffer_head *bh,
        lock_buffer(bh);
        if (super)
                memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
-       set_buffer_uptodate(bh);
        set_buffer_dirty(bh);
        unlock_buffer(bh);
 
@@ -2334,7 +2333,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
        }
 
        /* write back-up superblock first */
-       bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1);
+       bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
        if (!bh)
                return -EIO;
        err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
@@ -2345,7 +2344,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
                return err;
 
        /* write current valid superblock */
-       bh = sb_getblk(sbi->sb, sbi->valid_super_block);
+       bh = sb_bread(sbi->sb, sbi->valid_super_block);
        if (!bh)
                return -EIO;
        err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));