Skip to content

Commit dea93e9

Browse files
OjaswinMgregkh
authored andcommitted
ext4: fix reserved gdt blocks handling in fsmap
commit 3ffbdd1 upstream. In some cases like small FSes with no meta_bg and where the resize doesn't need extra gdt blocks as it can fit in the current one, s_reserved_gdt_blocks is set as 0, which causes fsmap to emit a 0 length entry, which is incorrect. $ mkfs.ext4 -b 65536 -O bigalloc /dev/sda 5G $ mount /dev/sda /mnt/scratch $ xfs_io -c "fsmap -d" /mnt/scartch 0: 253:48 [0..127]: static fs metadata 128 1: 253:48 [128..255]: special 102:1 128 2: 253:48 [256..255]: special 102:2 0 <---- 0 len entry 3: 253:48 [256..383]: special 102:3 128 Fix this by adding a check for this case. Cc: stable@kernel.org Fixes: 0c9ec4b ("ext4: support GETFSMAP ioctls") Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Link: https://patch.msgid.link/08781b796453a5770112aa96ad14c864fbf31935.1754377641.git.ojaswin@linux.ibm.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6323522 commit dea93e9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/ext4/fsmap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ static unsigned int ext4_getfsmap_find_sb(struct super_block *sb,
393393
/* Reserved GDT blocks */
394394
if (!ext4_has_feature_meta_bg(sb) || metagroup < first_meta_bg) {
395395
len = le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks);
396+
397+
/*
398+
* mkfs.ext4 can set s_reserved_gdt_blocks as 0 in some cases,
399+
* check for that.
400+
*/
401+
if (!len)
402+
return 0;
403+
396404
error = ext4_getfsmap_fill(meta_list, fsb, len,
397405
EXT4_FMR_OWN_RESV_GDT);
398406
if (error)

0 commit comments

Comments
 (0)