2022-02-01 20:42:01

by Ritesh Harjani

[permalink] [raw]
Subject: [RFC 6/6] ext4: Add extra check in ext4_mb_mark_bb() to prevent against possible corruption

This patch adds an extra checks in ext4_mb_mark_bb() function
to make sure we mark & report error if we were to mark/clear any
of the critical FS metadata specific bitmaps (&bail out) to prevent
from any accidental corruption.

Signed-off-by: Ritesh Harjani <[email protected]>
---
fs/ext4/mballoc.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 5f20e355d08c..c94888534caa 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3920,6 +3920,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
len -= overflow;
}

+ if (!ext4_group_block_valid(sb, group, block, len)) {
+ ext4_error(sb, "Marking blocks in system zone - "
+ "Block = %llu, len = %d", block, len);
+ bitmap_bh = NULL;
+ goto out_err;
+ }
+
clen = EXT4_NUM_B2C(sbi, len);

bitmap_bh = ext4_read_block_bitmap(sb, group);
--
2.31.1


2022-02-02 07:30:00

by Jan Kara

[permalink] [raw]
Subject: Re: [RFC 6/6] ext4: Add extra check in ext4_mb_mark_bb() to prevent against possible corruption

On Mon 31-01-22 20:46:55, Ritesh Harjani wrote:
> This patch adds an extra checks in ext4_mb_mark_bb() function
> to make sure we mark & report error if we were to mark/clear any
> of the critical FS metadata specific bitmaps (&bail out) to prevent
> from any accidental corruption.
>
> Signed-off-by: Ritesh Harjani <[email protected]>

Again please rather use ext4_inode_block_valid() here. All the callers of
ext4_mb_mark_bb() have the information available.

Honza

> ---
> fs/ext4/mballoc.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 5f20e355d08c..c94888534caa 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3920,6 +3920,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
> len -= overflow;
> }
>
> + if (!ext4_group_block_valid(sb, group, block, len)) {
> + ext4_error(sb, "Marking blocks in system zone - "
> + "Block = %llu, len = %d", block, len);
> + bitmap_bh = NULL;
> + goto out_err;
> + }
> +
> clen = EXT4_NUM_B2C(sbi, len);
>
> bitmap_bh = ext4_read_block_bitmap(sb, group);
> --
> 2.31.1
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2022-02-04 22:04:20

by Ritesh Harjani

[permalink] [raw]
Subject: Re: [RFC 6/6] ext4: Add extra check in ext4_mb_mark_bb() to prevent against possible corruption

On 22/02/01 12:47PM, Jan Kara wrote:
> On Mon 31-01-22 20:46:55, Ritesh Harjani wrote:
> > This patch adds an extra checks in ext4_mb_mark_bb() function
> > to make sure we mark & report error if we were to mark/clear any
> > of the critical FS metadata specific bitmaps (&bail out) to prevent
> > from any accidental corruption.
> >
> > Signed-off-by: Ritesh Harjani <[email protected]>
>
> Again please rather use ext4_inode_block_valid() here. All the callers of
> ext4_mb_mark_bb() have the information available.
>

Same reason here too, since we are already aware of the block group these blocks
belong too, does it make any sense to check against the system-zone in that
case?

-ritesh


> Honza
>
> > ---
> > fs/ext4/mballoc.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> > index 5f20e355d08c..c94888534caa 100644
> > --- a/fs/ext4/mballoc.c
> > +++ b/fs/ext4/mballoc.c
> > @@ -3920,6 +3920,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
> > len -= overflow;
> > }
> >
> > + if (!ext4_group_block_valid(sb, group, block, len)) {
> > + ext4_error(sb, "Marking blocks in system zone - "
> > + "Block = %llu, len = %d", block, len);
> > + bitmap_bh = NULL;
> > + goto out_err;
> > + }
> > +
> > clen = EXT4_NUM_B2C(sbi, len);
> >
> > bitmap_bh = ext4_read_block_bitmap(sb, group);
> > --
> > 2.31.1
> >
> --
> Jan Kara <[email protected]>
> SUSE Labs, CR