Skip to content

Commit a149127

Browse files
pskrgagjankara
authored andcommitted
reiserfs: add check for invalid 1st journal block
syzbot reported divide error in reiserfs. The problem was in incorrect journal 1st block. Syzbot's reproducer manualy generated wrong superblock with incorrect 1st block. In journal_init() wasn't any checks about this particular case. For example, if 1st journal block is before superblock 1st block, it can cause zeroing important superblock members in do_journal_end(). Link: https://lore.kernel.org/r/[email protected] Reported-by: [email protected] Signed-off-by: Pavel Skripkin <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 5b9fedb commit a149127

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/reiserfs/journal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,20 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
27582758
goto free_and_return;
27592759
}
27602760

2761+
/*
2762+
* Sanity check to see if journal first block is correct.
2763+
* If journal first block is invalid it can cause
2764+
* zeroing important superblock members.
2765+
*/
2766+
if (!SB_ONDISK_JOURNAL_DEVICE(sb) &&
2767+
SB_ONDISK_JOURNAL_1st_BLOCK(sb) < SB_JOURNAL_1st_RESERVED_BLOCK(sb)) {
2768+
reiserfs_warning(sb, "journal-1393",
2769+
"journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d",
2770+
SB_JOURNAL_1st_RESERVED_BLOCK(sb),
2771+
SB_ONDISK_JOURNAL_1st_BLOCK(sb));
2772+
goto free_and_return;
2773+
}
2774+
27612775
if (journal_init_dev(sb, journal, j_dev_name) != 0) {
27622776
reiserfs_warning(sb, "sh-462",
27632777
"unable to initialize journal device");

0 commit comments

Comments
 (0)