Skip to content

Commit 3039d8b

Browse files
LiBaokun96tytso
authored andcommitted
ext4: update s_journal_inum if it changes after journal replay
When mounting a crafted ext4 image, s_journal_inum may change after journal replay, which is obviously unreasonable because we have successfully loaded and replayed the journal through the old s_journal_inum. And the new s_journal_inum bypasses some of the checks in ext4_get_journal(), which may trigger a null pointer dereference problem. So if s_journal_inum changes after the journal replay, we ignore the change, and rewrite the current journal_inum to the superblock. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216541 Reported-by: Luís Henriques <[email protected]> Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 5cd7402 commit 3039d8b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/ext4/super.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,8 +5953,11 @@ static int ext4_load_journal(struct super_block *sb,
59535953
if (!really_read_only && journal_devnum &&
59545954
journal_devnum != le32_to_cpu(es->s_journal_dev)) {
59555955
es->s_journal_dev = cpu_to_le32(journal_devnum);
5956-
5957-
/* Make sure we flush the recovery flag to disk. */
5956+
ext4_commit_super(sb);
5957+
}
5958+
if (!really_read_only && journal_inum &&
5959+
journal_inum != le32_to_cpu(es->s_journal_inum)) {
5960+
es->s_journal_inum = cpu_to_le32(journal_inum);
59585961
ext4_commit_super(sb);
59595962
}
59605963

0 commit comments

Comments
 (0)