Patchwork [4/5] ext4: don't crash when validating block bitmap

login
register
mail settings
Submitter Darrick J. Wong
Date May 1, 2014, 11:17 p.m.
Message ID <20140501231747.892.95073.stgit@birch.djwong.org>
Download mbox | patch
Permalink /patch/344868/
State Rejected
Headers show

Comments

Darrick J. Wong - May 1, 2014, 11:17 p.m.
If EXT4FS_DEBUG is defined, ext4_validate_block_bitmap is called via
ext4_count_free_clusters before sb->s_group_info is set up.  When this
happens, the kernel crashes because group info hasn't been loaded.
Forego marking the group corrupt for now; not setting BH_Verified
means we'll revisit the bitmap if something went wrong.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/ext4/balloc.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o - May 12, 2014, 2:24 p.m.
On Thu, May 01, 2014 at 04:17:47PM -0700, Darrick J. Wong wrote:
> If EXT4FS_DEBUG is defined, ext4_validate_block_bitmap is called via
> ext4_count_free_clusters before sb->s_group_info is set up.  When this
> happens, the kernel crashes because group info hasn't been loaded.
> Forego marking the group corrupt for now; not setting BH_Verified
> means we'll revisit the bitmap if something went wrong.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

This shouldn't be necessary that we have this in the ext4 tree, right?

commit 007649375f6af242d5b1df2c15996949714303ba
Author: Azat Khuzhin <a3at.mail@gmail.com>
Date:   Mon Apr 7 10:54:20 2014 -0400

    ext4: initialize multi-block allocator before checking block descriptors
    
    With EXT4FS_DEBUG ext4_count_free_clusters() will call
    ext4_read_block_bitmap() without s_group_info initialized, so we need to
    initialize multi-block allocator before.
    
    ...

						- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darrick J. Wong - May 13, 2014, 10:33 p.m.
On Mon, May 12, 2014 at 10:24:57AM -0400, Theodore Ts'o wrote:
> On Thu, May 01, 2014 at 04:17:47PM -0700, Darrick J. Wong wrote:
> > If EXT4FS_DEBUG is defined, ext4_validate_block_bitmap is called via
> > ext4_count_free_clusters before sb->s_group_info is set up.  When this
> > happens, the kernel crashes because group info hasn't been loaded.
> > Forego marking the group corrupt for now; not setting BH_Verified
> > means we'll revisit the bitmap if something went wrong.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> This shouldn't be necessary that we have this in the ext4 tree, right?

Err... right, you can drop this patch of mine.

--D

> 
> commit 007649375f6af242d5b1df2c15996949714303ba
> Author: Azat Khuzhin <a3at.mail@gmail.com>
> Date:   Mon Apr 7 10:54:20 2014 -0400
> 
>     ext4: initialize multi-block allocator before checking block descriptors
>     
>     With EXT4FS_DEBUG ext4_count_free_clusters() will call
>     ext4_read_block_bitmap() without s_group_info initialized, so we need to
>     initialize multi-block allocator before.
>     
>     ...
> 
> 						- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 59c3ba8..8f7bed0 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -357,7 +357,10 @@  void ext4_validate_block_bitmap(struct super_block *sb,
 			       struct buffer_head *bh)
 {
 	ext4_fsblk_t	blk;
-	struct ext4_group_info *grp = ext4_get_group_info(sb, block_group);
+	struct ext4_group_info *grp = NULL;
+
+	if (EXT4_SB(sb)->s_group_info)
+		grp = ext4_get_group_info(sb, block_group);
 
 	if (buffer_verified(bh))
 		return;
@@ -368,14 +371,18 @@  void ext4_validate_block_bitmap(struct super_block *sb,
 		ext4_unlock_group(sb, block_group);
 		ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
 			   block_group, blk);
-		set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
+		if (grp)
+			set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT,
+				&grp->bb_state);
 		return;
 	}
 	if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
 			desc, bh))) {
 		ext4_unlock_group(sb, block_group);
 		ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
-		set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
+		if (grp)
+			set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT,
+				&grp->bb_state);
 		return;
 	}
 	set_buffer_verified(bh);