mirror of https://github.com/vitalif/e2fsprogs
resize2fs: use blk64_t and location getters for free_gdp_blocks()
free_gdp_blocks needs to be taught to use 64-bit fields and the appropriate getters, otherwise it'll truncate high block numbers (when, say, resizing a >16T fs) and mark the low numbered group descriptor blocks as free. Yikes. Reported-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>debian-1.42.9
parent
816d2c9cf7
commit
0851517daa
|
@ -273,34 +273,36 @@ static void fix_uninit_block_bitmaps(ext2_filsys fs)
|
||||||
*/
|
*/
|
||||||
static void free_gdp_blocks(ext2_filsys fs,
|
static void free_gdp_blocks(ext2_filsys fs,
|
||||||
ext2fs_block_bitmap reserve_blocks,
|
ext2fs_block_bitmap reserve_blocks,
|
||||||
struct ext2_group_desc *gdp)
|
ext2_filsys old_fs,
|
||||||
|
dgrp_t group)
|
||||||
{
|
{
|
||||||
blk_t blk;
|
blk64_t blk;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (gdp->bg_block_bitmap &&
|
blk = ext2fs_block_bitmap_loc(old_fs, group);
|
||||||
(gdp->bg_block_bitmap < ext2fs_blocks_count(fs->super))) {
|
if (blk &&
|
||||||
ext2fs_block_alloc_stats(fs, gdp->bg_block_bitmap, -1);
|
(blk < ext2fs_blocks_count(fs->super))) {
|
||||||
ext2fs_mark_block_bitmap2(reserve_blocks,
|
ext2fs_block_alloc_stats2(fs, blk, -1);
|
||||||
gdp->bg_block_bitmap);
|
ext2fs_mark_block_bitmap2(reserve_blocks, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gdp->bg_inode_bitmap &&
|
blk = ext2fs_inode_bitmap_loc(old_fs, group);
|
||||||
(gdp->bg_inode_bitmap < ext2fs_blocks_count(fs->super))) {
|
if (blk &&
|
||||||
ext2fs_block_alloc_stats(fs, gdp->bg_inode_bitmap, -1);
|
(blk < ext2fs_blocks_count(fs->super))) {
|
||||||
ext2fs_mark_block_bitmap2(reserve_blocks,
|
ext2fs_block_alloc_stats2(fs, blk, -1);
|
||||||
gdp->bg_inode_bitmap);
|
ext2fs_mark_block_bitmap2(reserve_blocks, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gdp->bg_inode_table == 0 ||
|
blk = ext2fs_inode_table_loc(old_fs, group);
|
||||||
(gdp->bg_inode_table >= ext2fs_blocks_count(fs->super)))
|
if (blk == 0 ||
|
||||||
|
(blk >= ext2fs_blocks_count(fs->super)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (blk = gdp->bg_inode_table, j = 0;
|
for (j = 0;
|
||||||
j < fs->inode_blocks_per_group; j++, blk++) {
|
j < fs->inode_blocks_per_group; j++, blk++) {
|
||||||
if (blk >= ext2fs_blocks_count(fs->super))
|
if (blk >= ext2fs_blocks_count(fs->super))
|
||||||
break;
|
break;
|
||||||
ext2fs_block_alloc_stats(fs, blk, -1);
|
ext2fs_block_alloc_stats2(fs, blk, -1);
|
||||||
ext2fs_mark_block_bitmap2(reserve_blocks, blk);
|
ext2fs_mark_block_bitmap2(reserve_blocks, blk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -467,11 +469,8 @@ retry:
|
||||||
* and free any blocks associated with their metadata
|
* and free any blocks associated with their metadata
|
||||||
*/
|
*/
|
||||||
for (i = fs->group_desc_count;
|
for (i = fs->group_desc_count;
|
||||||
i < old_fs->group_desc_count; i++) {
|
i < old_fs->group_desc_count; i++)
|
||||||
free_gdp_blocks(fs, reserve_blocks,
|
free_gdp_blocks(fs, reserve_blocks, old_fs, i);
|
||||||
ext2fs_group_desc(old_fs,
|
|
||||||
old_fs->group_desc, i));
|
|
||||||
}
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue