diff mbox

ext4: fix oops when online resizing a filesystem with flex_bg

Message ID 1232743309-3929-1-git-send-email-cascardo@holoscopio.com
State Accepted, archived
Headers show

Commit Message

Thadeu Lima de Souza Cascardo Jan. 23, 2009, 8:41 p.m. UTC
http://kerneloops.org/raw.php?rawid=176715 and
http://bugzilla.kernel.org/show_bug.cgi?id=12433 report a bug when
resizing a mounted ext4 filesystem. I could easily reproduce it using
2.6.29-rc2, 2.6.28 and 2.6.27.

ext4_error was called just before the NULL derefence from
ext4_get_group_desc, indicating a block group beyond s_groups_count.
This function returned a NULL. The requested block group was beyond
s_groups_count because this is the last changed bit when resizing.

The caller, ext4_group_used_meta_blocks, did not check the returned
pointer. It needs the gdp anyway. Fortunately, its only caller,
ext4_init_block_bitmap, has a gdp and it was simply a matter of adding
this parameter to ext4_group_used_meta_blocks and use it.

Tested and the oops is gone.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
 fs/ext4/balloc.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)


Theodore Ts'o Jan. 27, 2009, 12:22 a.m. UTC | #1
I'm going to include this patch as well, but with a slightly different
changelog description, since I think making sure the group descriptor
is initialized addresses the root cause of the problem.  This still
saves a small amount of code space, so it's still a good patch, but it
shouldn't be strictly speaking necessary.

							- Ted

commit 030d677ef688dea36245bdeaab74826aece02ee8
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Mon Jan 26 19:20:18 2009 -0500

    ext4: remove call to ext4_group_desc() in ext4_group_used_meta_blocks()
    The static function ext4_group_used_meta_blocks() only has one caller,
    who already has access to the block group's group descriptor.  So it's
    better to have ext4_init_block_bitmap() pass the group descriptor to
    ext4_group_used_meta_blocks(), so it doesn't need to call
    ext4_group_desc().  Previously this function did not check if
    ext4_group_desc() returned NULL due to an error, potentially causing a
    kernel OOPS report.  This avoids the issue entirely.
    Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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
diff mbox


diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 9a50b80..d7dc22a 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -55,7 +55,7 @@  static int ext4_block_in_group(struct super_block *sb, ext4_fsblk_t block,
 static int ext4_group_used_meta_blocks(struct super_block *sb,
-				ext4_group_t block_group)
+		ext4_group_t block_group, struct ext4_group_desc *gdp)
 	ext4_fsblk_t tmp;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -63,10 +63,6 @@  static int ext4_group_used_meta_blocks(struct super_block *sb,
 	int used_blocks = sbi->s_itb_per_group + 2;
-		struct ext4_group_desc *gdp;
-		struct buffer_head *bh;
-		gdp = ext4_get_group_desc(sb, block_group, &bh);
 		if (!ext4_block_in_group(sb, ext4_block_bitmap(sb, gdp),
@@ -177,7 +173,7 @@  unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
 		mark_bitmap_end(group_blocks, sb->s_blocksize * 8, bh->b_data);
-	return free_blocks - ext4_group_used_meta_blocks(sb, block_group);
+	return free_blocks - ext4_group_used_meta_blocks(sb, block_group, gdp);