lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1364777043-20610-2-git-send-email-tytso@mit.edu>
Date:	Sun, 31 Mar 2013 20:44:00 -0400
From:	Theodore Ts'o <tytso@....edu>
To:	Ext4 Developers List <linux-ext4@...r.kernel.org>
Cc:	john.jolly@...il.com, Theodore Ts'o <tytso@....edu>
Subject: [PATCH 1/4] resize2fs: fix off-line resize of file systems with flex_bg && !resize_inode

When doing an off-line resize2fs of an initially very small file
system, it's possible to run out of reserved gdt blocks (which are
reserved via the resize inode).  Once we run out, we need to move the
allocation bitmaps and inode table out of the way to grow the gdt
blocks.  Unfortunately, when moving these metadata blocks, it was
possible that a block that had been just been newly allocated for a
new block group could also get allocated for a metadata block for an
existing block group that was being moved.

To prevent this, after we grow the gdt blocks and allocate the
metadata blocks for the new block groups, make sure all of these
blocks are marked as reserved.

Signed-off-by: "Theodore Ts'o" <tytso@....edu>
Reported-by: John Jolly <john.jolly@...il.com>
---
 resize/resize2fs.c | 58 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index c9458ea..7c4f86a 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -51,6 +51,8 @@ static errcode_t move_itables(ext2_resize_t rfs);
 static errcode_t fix_resize_inode(ext2_filsys fs);
 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs);
 static errcode_t fix_sb_journal_backup(ext2_filsys fs);
+static errcode_t mark_table_blocks(ext2_filsys fs,
+				   ext2fs_block_bitmap bmap);
 
 /*
  * Some helper CPP macros
@@ -306,9 +308,6 @@ static void free_gdp_blocks(ext2_filsys fs,
 /*
  * This routine is shared by the online and offline resize routines.
  * All of the information which is adjusted in memory is done here.
- *
- * The reserve_blocks parameter is only needed when shrinking the
- * filesystem.
  */
 errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
 			 ext2fs_block_bitmap reserve_blocks, blk64_t new_size)
@@ -407,12 +406,21 @@ retry:
 	real_end = (((blk64_t) EXT2_BLOCKS_PER_GROUP(fs->super) *
 		     fs->group_desc_count)) - 1 +
 		fs->super->s_first_data_block;
-	retval = ext2fs_resize_block_bitmap2(ext2fs_blocks_count(fs->super)-1,
-					    real_end, fs->block_map);
-
+	retval = ext2fs_resize_block_bitmap2(new_size - 1,
+					     real_end, fs->block_map);
 	if (retval) goto errout;
 
 	/*
+	 * If we are growing the file system, also grow the size of
+	 * the reserve_blocks bitmap
+	 */
+	if (reserve_blocks && new_size > ext2fs_blocks_count(old_fs->super)) {
+		retval = ext2fs_resize_block_bitmap2(new_size - 1,
+						     real_end, reserve_blocks);
+		if (retval) goto errout;
+	}
+
+	/*
 	 * Reallocate the group descriptors as necessary.
 	 */
 	if (old_fs->desc_blocks != fs->desc_blocks) {
@@ -512,6 +520,15 @@ retry:
 	else
 		old_desc_blocks = fs->desc_blocks +
 			fs->super->s_reserved_gdt_blocks;
+
+	/*
+	 * If we changed the number of block_group descriptor blocks,
+	 * we need to make sure they are all marked as reserved in the
+	 * file systems's block allocation map.
+	 */
+	for (i = 0; i < old_fs->group_desc_count; i++)
+		ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
+
 	for (i = old_fs->group_desc_count;
 	     i < fs->group_desc_count; i++) {
 		memset(ext2fs_group_desc(fs, fs->group_desc, i), 0,
@@ -578,6 +595,17 @@ retry:
 	}
 	retval = 0;
 
+	/*
+	 * Mark all of the metadata blocks as reserved so they won't
+	 * get allocated by the call to ext2fs_allocate_group_table()
+	 * in blocks_to_move(), where we allocate new blocks to
+	 * replace those allocation bitmap and inode table blocks
+	 * which have to get relocated to make space for an increased
+	 * number of the block group descriptors.
+	 */
+	if (reserve_blocks)
+		mark_table_blocks(fs, reserve_blocks);
+
 errout:
 	return (retval);
 }
@@ -716,6 +744,7 @@ static errcode_t mark_table_blocks(ext2_filsys fs,
 				   ext2fs_block_bitmap bmap)
 {
 	dgrp_t			i;
+	blk64_t			blk;
 
 	for (i = 0; i < fs->group_desc_count; i++) {
 		ext2fs_reserve_super_and_bgd(fs, i, bmap);
@@ -723,21 +752,24 @@ static errcode_t mark_table_blocks(ext2_filsys fs,
 		/*
 		 * Mark the blocks used for the inode table
 		 */
-		ext2fs_mark_block_bitmap_range2(bmap,
-					  ext2fs_inode_table_loc(fs, i),
-					  fs->inode_blocks_per_group);
+		blk = ext2fs_inode_table_loc(fs, i);
+		if (blk)
+			ext2fs_mark_block_bitmap_range2(bmap, blk,
+						fs->inode_blocks_per_group);
 
 		/*
 		 * Mark block used for the block bitmap
 		 */
-		ext2fs_mark_block_bitmap2(bmap,
-					 ext2fs_block_bitmap_loc(fs, i));
+		blk = ext2fs_block_bitmap_loc(fs, i);
+		if (blk)
+			ext2fs_mark_block_bitmap2(bmap, blk);
 
 		/*
 		 * Mark block used for the inode bitmap
 		 */
-		ext2fs_mark_block_bitmap2(bmap,
-					 ext2fs_inode_bitmap_loc(fs, i));
+		blk = ext2fs_inode_bitmap_loc(fs, i);
+		if (blk)
+			ext2fs_mark_block_bitmap2(bmap, blk);
 	}
 	return 0;
 }
-- 
1.7.12.rc0.22.gcdd159b

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ