All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] reiserfs: add check for invalid 1st journal block
@ 2021-05-14 21:23 Pavel Skripkin
  2021-05-17 10:15 ` Jan Kara
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2021-05-14 21:23 UTC (permalink / raw)
  To: jack, tiantao6, rdunlap
  Cc: reiserfs-devel, linux-kernel, Pavel Skripkin,
	syzbot+0ba9909df31c6a36974d

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().

Reported-and-tested-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 fs/reiserfs/journal.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 9edc8e2b154e..d58f24a08385 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -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");
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] reiserfs: add check for invalid 1st journal block
  2021-05-14 21:23 [PATCH] reiserfs: add check for invalid 1st journal block Pavel Skripkin
@ 2021-05-17 10:15 ` Jan Kara
  2021-05-17 11:37   ` Pavel Skripkin
  2021-05-17 12:15   ` [PATCH v2] " Pavel Skripkin
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Kara @ 2021-05-17 10:15 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: jack, tiantao6, rdunlap, reiserfs-devel, linux-kernel,
	syzbot+0ba9909df31c6a36974d

On Sat 15-05-21 00:23:35, Pavel Skripkin wrote:
> 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().
> 
> Reported-and-tested-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>

Thanks for the patch. One comment below:

> diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
> index 9edc8e2b154e..d58f24a08385 100644
> --- a/fs/reiserfs/journal.c
> +++ b/fs/reiserfs/journal.c
> @@ -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

> +		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");
> -- 
> 2.31.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] reiserfs: add check for invalid 1st journal block
  2021-05-17 10:15 ` Jan Kara
@ 2021-05-17 11:37   ` Pavel Skripkin
  2021-05-17 12:15   ` [PATCH v2] " Pavel Skripkin
  1 sibling, 0 replies; 7+ messages in thread
From: Pavel Skripkin @ 2021-05-17 11:37 UTC (permalink / raw)
  To: Jan Kara
  Cc: tiantao6, rdunlap, reiserfs-devel, linux-kernel,
	syzbot+0ba9909df31c6a36974d

On Mon, 17 May 2021 12:15:23 +0200
Jan Kara <jack@suse.cz> wrote:
> On Sat 15-05-21 00:23:35, Pavel Skripkin wrote:
> > 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().
> > 
> > Reported-and-tested-by:
> > syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
> > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> 
> Thanks for the patch. One comment below:
> 
> > diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
> > index 9edc8e2b154e..d58f24a08385 100644
> > --- a/fs/reiserfs/journal.c
> > +++ b/fs/reiserfs/journal.c
> > @@ -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...
> 

Hi!

Indeed. Thanks for pointing it out! I'll send v2 soon

> 									Honza
> 
> > +		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"); -- 
> > 2.31.1
> > 




With regards,
Pavel Skripkin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] reiserfs: add check for invalid 1st journal block
  2021-05-17 10:15 ` Jan Kara
  2021-05-17 11:37   ` Pavel Skripkin
@ 2021-05-17 12:15   ` Pavel Skripkin
  2021-05-17 13:08     ` Jan Kara
  1 sibling, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2021-05-17 12:15 UTC (permalink / raw)
  To: jack, tiantao6, rdunlap
  Cc: reiserfs-devel, linux-kernel, Pavel Skripkin,
	syzbot+0ba9909df31c6a36974d

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().

Reported-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---

Changes in v2:
  Added necessary !SB_ONDISK_JOURNAL_DEVICE(sb) in "if"

---
 fs/reiserfs/journal.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 9edc8e2b154e..0834b101c316 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -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");
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] reiserfs: add check for invalid 1st journal block
  2021-05-17 12:15   ` [PATCH v2] " Pavel Skripkin
@ 2021-05-17 13:08     ` Jan Kara
  2021-06-08 10:44       ` Pavel Skripkin
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kara @ 2021-05-17 13:08 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: jack, tiantao6, rdunlap, reiserfs-devel, linux-kernel,
	syzbot+0ba9909df31c6a36974d

On Mon 17-05-21 15:15:45, Pavel Skripkin wrote:
> 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().
> 
> Reported-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>

Thanks! I've added the patch to my tree.

								Honza

> ---
> 
> Changes in v2:
>   Added necessary !SB_ONDISK_JOURNAL_DEVICE(sb) in "if"
> 
> ---
>  fs/reiserfs/journal.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
> index 9edc8e2b154e..0834b101c316 100644
> --- a/fs/reiserfs/journal.c
> +++ b/fs/reiserfs/journal.c
> @@ -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");
> -- 
> 2.31.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] reiserfs: add check for invalid 1st journal block
  2021-05-17 13:08     ` Jan Kara
@ 2021-06-08 10:44       ` Pavel Skripkin
  2021-06-08 11:56         ` Jan Kara
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2021-06-08 10:44 UTC (permalink / raw)
  To: Jan Kara
  Cc: tiantao6, rdunlap, reiserfs-devel, linux-kernel,
	syzbot+0ba9909df31c6a36974d

On Mon, 17 May 2021 15:08:18 +0200
Jan Kara <jack@suse.cz> wrote:

> On Mon 17-05-21 15:15:45, Pavel Skripkin wrote:
> > 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().
> > 
> > Reported-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
> > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] reiserfs: add check for invalid 1st journal block
  2021-06-08 10:44       ` Pavel Skripkin
@ 2021-06-08 11:56         ` Jan Kara
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2021-06-08 11:56 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: Jan Kara, tiantao6, rdunlap, reiserfs-devel, linux-kernel,
	syzbot+0ba9909df31c6a36974d

On Tue 08-06-21 13:44:43, Pavel Skripkin wrote:
> On Mon, 17 May 2021 15:08:18 +0200
> Jan Kara <jack@suse.cz> wrote:
> 
> > On Mon 17-05-21 15:15:45, Pavel Skripkin wrote:
> > > 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().
> > > 
> > > Reported-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com
> > > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> > 
> > 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 :)

It's sitting in my for_next branch as commit a149127be52f. I'll push it to
Linus in the coming merge window.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-08 11:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 21:23 [PATCH] reiserfs: add check for invalid 1st journal block Pavel Skripkin
2021-05-17 10:15 ` Jan Kara
2021-05-17 11:37   ` Pavel Skripkin
2021-05-17 12:15   ` [PATCH v2] " Pavel Skripkin
2021-05-17 13:08     ` Jan Kara
2021-06-08 10:44       ` Pavel Skripkin
2021-06-08 11:56         ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.