mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
f2fs: backup raw_super in sbi
f2fs use fields of f2fs_super_block struct directly in a grabbed buffer. Once the buffer happen to be destroyed (e.g. through dd), it may bring in unpredictable effect on f2fs. This patch fixes to allocate additional buffer to store datas of super block rather than using grabbed block buffer directly. Signed-off-by: Yunlei He <heyunlei@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
c282a79134
commit
ba9a1899aa
1 changed files with 15 additions and 4 deletions
|
@ -561,6 +561,7 @@ static void f2fs_put_super(struct super_block *sb)
|
|||
|
||||
sb->s_fs_info = NULL;
|
||||
brelse(sbi->raw_super_buf);
|
||||
kfree(sbi->raw_super);
|
||||
kfree(sbi);
|
||||
}
|
||||
|
||||
|
@ -1132,6 +1133,9 @@ static int read_raw_super_block(struct super_block *sb,
|
|||
struct f2fs_super_block *super;
|
||||
int err = 0;
|
||||
|
||||
super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
|
||||
if (!super)
|
||||
return -ENOMEM;
|
||||
retry:
|
||||
buffer = sb_bread(sb, block);
|
||||
if (!buffer) {
|
||||
|
@ -1147,8 +1151,7 @@ retry:
|
|||
}
|
||||
}
|
||||
|
||||
super = (struct f2fs_super_block *)
|
||||
((char *)(buffer)->b_data + F2FS_SUPER_OFFSET);
|
||||
memcpy(super, buffer->b_data + F2FS_SUPER_OFFSET, sizeof(*super));
|
||||
|
||||
/* sanity checking of raw super */
|
||||
if (sanity_check_raw_super(sb, super)) {
|
||||
|
@ -1182,14 +1185,17 @@ retry:
|
|||
|
||||
out:
|
||||
/* No valid superblock */
|
||||
if (!*raw_super)
|
||||
if (!*raw_super) {
|
||||
kfree(super);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
||||
{
|
||||
struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi);
|
||||
struct buffer_head *sbh = sbi->raw_super_buf;
|
||||
struct buffer_head *bh;
|
||||
int err;
|
||||
|
@ -1200,7 +1206,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
|||
return -EIO;
|
||||
|
||||
lock_buffer(bh);
|
||||
memcpy(bh->b_data, sbh->b_data, sbh->b_size);
|
||||
memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
|
||||
WARN_ON(sbh->b_size != F2FS_BLKSIZE);
|
||||
set_buffer_uptodate(bh);
|
||||
set_buffer_dirty(bh);
|
||||
|
@ -1216,6 +1222,10 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
|||
|
||||
/* write current valid superblock */
|
||||
lock_buffer(sbh);
|
||||
if (memcmp(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super))) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO, "Write modified valid superblock");
|
||||
memcpy(sbh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
|
||||
}
|
||||
set_buffer_dirty(sbh);
|
||||
unlock_buffer(sbh);
|
||||
|
||||
|
@ -1490,6 +1500,7 @@ free_options:
|
|||
kfree(options);
|
||||
free_sb_buf:
|
||||
brelse(raw_super_buf);
|
||||
kfree(raw_super);
|
||||
free_sbi:
|
||||
kfree(sbi);
|
||||
|
||||
|
|
Loading…
Reference in a new issue