reiserfs: add check for invalid 1st journal block
PATCH 1/1 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().
--- fs/reiserfs/journal.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/reiserfs/journal.c +13 -0
@@ -2758,6 +2758,19 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; } +/* +* Sanity check to see is journal first block correct. +* If journal first block is invalid it can cause +* zeroing important superblock members. +*/ +if (SB_ONDISK_JOURNAL_1st_BLOCK (sb) <SB_JOURNAL_1st_RESERVED_BLOCK (sb)) { +reiserfs_warning (sb,"journal-1393" , +"journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d" , +SB_JOURNAL_1st_RESERVED_BLOCK (sb), +SB_ONDISK_JOURNAL_1st_BLOCK (sb)); + goto free_and_return; + } +if (journal_init_dev (sb, journal, j_dev_name) !=0 ) {reiserfs_warning (sb,"sh-462" ,"unable to initialize journal device" );
Signature · 1 line
2.31.1
Quoted 7 lines · Pavel Skripkin
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.
Quoted 6 lines
For example, if 1st journal block is before superblock 1st block, it can cause zeroing important superblock members in
do_journal_end().Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>
Thanks for the patch. One comment below:
Quoted 5 lines
fs/reiserfs/journal.c +0
-0
fs/reiserfs/journal.c int journal_init(struct super_block *sb, const char *j_dev_name, · line 2766
Quoted 9 lines
fs/reiserfs/journal.c +6
-0@@ -2758,6 +2758,19 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; } +/* +* Sanity check to see is journal first block correct. +* If journal first block is invalid it can cause +* zeroing important superblock members. +*/ +if (SB_ONDISK_JOURNAL_1st_BLOCK (sb) <SB_JOURNAL_1st_RESERVED_BLOCK (sb)) {
I guess this check is valid only if !SB_ONDISK_JOURNAL_DEVICE(sb), isn't it? Otherwise you are comparing block numbers from two different devices...
Honza
Quoted 13 lines
fs/reiserfs/journal.c +7
-0+reiserfs_warning (sb,"journal-1393" , +"journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d" , +SB_JOURNAL_1st_RESERVED_BLOCK (sb), +SB_ONDISK_JOURNAL_1st_BLOCK (sb)); + goto free_and_return; + } +if (journal_init_dev (sb, journal, j_dev_name) !=0 ) {reiserfs_warning (sb,"sh-462" ,"unable to initialize journal device" );Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 26 lines · On Mon, 17 May 2021 12:15:23 +0200 Jan Kara <[email protected]> wrote:
Quoted 7 lines · Pavel Skripkin
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.Quoted 7 lines
For example, if 1st journal block is before superblock 1st block, it can cause zeroing important superblock members in
do_journal_end().Reported-and-tested-by:
[email protected]Signed-off-by Pavel Skripkin <[email protected]>Thanks for the patch. One comment below:
Quoted 8 lines
fs/reiserfs/journal.c +0
-0@@ -2758,6 +2758,19 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; }
Quoted 12 lines
fs/reiserfs/journal.c int journal_init(struct super_block *sb, const char *j_dev_name,
Quoted 7 lines
fs/reiserfs/journal.c +6
-0+/* +* Sanity check to see is journal first block correct. +* If journal first block is invalid it can cause +* zeroing important superblock members. +*/ +if (SB_ONDISK_JOURNAL_1st_BLOCK (sb) <SB_JOURNAL_1st_RESERVED_BLOCK (sb)) {I guess this check is valid only if !SB_ONDISK_JOURNAL_DEVICE(sb), isn't it? Otherwise you are comparing block numbers from two different devices...
Hi!
Indeed. Thanks for pointing it out! I'll send v2 soon
Quoted 16 lines
Honza
Quoted 11 lines
fs/reiserfs/journal.c +7
-0+reiserfs_warning (sb,"journal-1393" , + "journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d", + SB_JOURNAL_1st_RESERVED_BLOCK(sb), +SB_ONDISK_JOURNAL_1st_BLOCK (sb)); + goto free_and_return; + } +if (journal_init_dev (sb, journal, j_dev_name) !=0 ) {fs/reiserfs/journal.c +0
-0reiserfs_warning(sb, "sh-462", "unable to initialize journalQuoted 3 lines
device"); --
2.31.1
With regards,
Pavel Skripkin
PATCH v2 1/1 reiserfs: add check for invalid 1st journal block
In reply to Jan Karasyzbot 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().
---
Changes in v2:
Added necessary !SB_ONDISK_JOURNAL_DEVICE(sb) in "if"
--- fs/reiserfs/journal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/reiserfs/journal.c +14 -0
@@ -2758,6 +2758,20 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; } +/* +* Sanity check to see if journal first block is correct. +* If journal first block is invalid it can cause +* zeroing important superblock members. +*/ +if (!SB_ONDISK_JOURNAL_DEVICE (sb) && +SB_ONDISK_JOURNAL_1st_BLOCK (sb) <SB_JOURNAL_1st_RESERVED_BLOCK (sb)) { +reiserfs_warning (sb,"journal-1393" , +"journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d" , +SB_JOURNAL_1st_RESERVED_BLOCK (sb), +SB_ONDISK_JOURNAL_1st_BLOCK (sb)); + goto free_and_return; + } +if (journal_init_dev (sb, journal, j_dev_name) !=0 ) {reiserfs_warning (sb,"sh-462" ,"unable to initialize journal device" );
Signature · 1 line
2.31.1
Quoted 7 lines · Pavel Skripkin
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.
Quoted 6 lines
For example, if 1st journal block is before superblock 1st block, it can cause zeroing important superblock members in
do_journal_end().Reported-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>
Thanks! I've added the patch to my tree.
Honza
Quoted 37 lines
---
Changes in v2:
Added necessary !SB_ONDISK_JOURNAL_DEVICE(sb) in "if"--- fs/reiserfs/journal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)fs/reiserfs/journal.c +14
-0@@ -2758,6 +2758,20 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; } +/* +* Sanity check to see if journal first block is correct. +* If journal first block is invalid it can cause +* zeroing important superblock members. +*/ +if (!SB_ONDISK_JOURNAL_DEVICE (sb) && +SB_ONDISK_JOURNAL_1st_BLOCK (sb) <SB_JOURNAL_1st_RESERVED_BLOCK (sb)) { +reiserfs_warning (sb,"journal-1393" , +"journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d" , +SB_JOURNAL_1st_RESERVED_BLOCK (sb), +SB_ONDISK_JOURNAL_1st_BLOCK (sb)); + goto free_and_return; + } +if (journal_init_dev (sb, journal, j_dev_name) !=0 ) {reiserfs_warning (sb,"sh-462" ,"unable to initialize journal device" );Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 12 lines · On Mon, 17 May 2021 15:08:18 +0200 Jan Kara <[email protected]> wrote:
Quoted 11 lines · Pavel Skripkin
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().
Quoted 7 lines
Quoted 2 lines
Reported-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>Thanks! I've added the patch to my tree.
Honza
Hi, Jan!
Is this patched got lost somehow? I did't find it in your tree here
https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/.
Sorry to bother you, maybe Im missing something :)
With regards,
Pavel Skripkin
Quoted 23 lines · Pavel Skripkin
Quoted 12 lines · On Mon, 17 May 2021 15:08:18 +0200 Jan Kara <[email protected]> wrote:
Quoted 11 lines · Pavel Skripkin
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().Quoted 7 lines
Quoted 2 lines
Reported-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>Thanks! I've added the patch to my tree.
Honza
Quoted 6 lines
Hi, Jan!
Is this patched got lost somehow? I did't find it in your tree here
https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/.Sorry to bother you, maybe Im missing something :)
It's sitting in my for_next branch as commit a149127be52f. I'll push it to Linus in the coming merge window.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR