linux-stable/fs/ext4
Maximilian Heyne 75cc31c2e7 ext4: fix corruption during on-line resize
[ Upstream commit a6b3bfe176 ]

We observed a corruption during on-line resize of a file system that is
larger than 16 TiB with 4k block size. With having more then 2^32 blocks
resize_inode is turned off by default by mke2fs. The issue can be
reproduced on a smaller file system for convenience by explicitly
turning off resize_inode. An on-line resize across an 8 GiB boundary (the
size of a meta block group in this setup) then leads to a corruption:

  dev=/dev/<some_dev> # should be >= 16 GiB
  mkdir -p /corruption
  /sbin/mke2fs -t ext4 -b 4096 -O ^resize_inode $dev $((2 * 2**21 - 2**15))
  mount -t ext4 $dev /corruption

  dd if=/dev/zero bs=4096 of=/corruption/test count=$((2*2**21 - 4*2**15))
  sha1sum /corruption/test
  # 79d2658b39dcfd77274e435b0934028adafaab11  /corruption/test

  /sbin/resize2fs $dev $((2*2**21))
  # drop page cache to force reload the block from disk
  echo 1 > /proc/sys/vm/drop_caches

  sha1sum /corruption/test
  # 3c2abc63cbf1a94c9e6977e0fbd72cd832c4d5c3  /corruption/test

2^21 = 2^15*2^6 equals 8 GiB whereof 2^15 is the number of blocks per
block group and 2^6 are the number of block groups that make a meta
block group.

The last checksum might be different depending on how the file is laid
out across the physical blocks. The actual corruption occurs at physical
block 63*2^15 = 2064384 which would be the location of the backup of the
meta block group's block descriptor. During the on-line resize the file
system will be converted to meta_bg starting at s_first_meta_bg which is
2 in the example - meaning all block groups after 16 GiB. However, in
ext4_flex_group_add we might add block groups that are not part of the
first meta block group yet. In the reproducer we achieved this by
substracting the size of a whole block group from the point where the
meta block group would start. This must be considered when updating the
backup block group descriptors to follow the non-meta_bg layout. The fix
is to add a test whether the group to add is already part of the meta
block group or not.

Fixes: 01f795f9e0 ("ext4: add online resizing support for meta_bg and 64-bit file systems")
Cc:  <stable@vger.kernel.org>
Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
Tested-by: Srivathsa Dara <srivathsa.d.dara@oracle.com>
Reviewed-by: Srivathsa Dara <srivathsa.d.dara@oracle.com>
Link: https://lore.kernel.org/r/20240215155009.94493-1-mheyne@amazon.de
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-13 12:50:06 +02:00
..
Kconfig
Makefile
acl.c
acl.h ext4: apply umask if ACL support is disabled 2023-11-28 16:46:36 +00:00
balloc.c ext4: fix WARNING in mb_find_extent 2023-05-17 11:13:27 +02:00
bitmap.c
block_validity.c ext4: eliminate bogus error in ext4_data_block_valid_rcu() 2021-07-11 12:49:30 +02:00
dir.c ext4: fix potential infinite loop in ext4_dx_readdir() 2021-10-06 15:31:25 +02:00
ext4.h ext4: change s_last_trim_minblks type to unsigned long 2023-10-10 21:44:57 +02:00
ext4_extents.h ext4: fix EXT_MAX_EXTENT/INDEX to check for zeroed eh_max 2020-06-22 09:05:21 +02:00
ext4_jbd2.c
ext4_jbd2.h
extents.c ext4: move 'ix' sanity check to corrent position 2023-11-20 10:29:19 +01:00
extents_status.c Revert "ext4: generalize extents status tree search functions" 2023-01-24 07:11:51 +01:00
extents_status.h Revert "ext4: generalize extents status tree search functions" 2023-01-24 07:11:51 +01:00
file.c ext4: avoid crash when inline data creation follows DIO write 2022-10-26 13:19:22 +02:00
fsmap.c ext4: rename journal_dev to s_journal_dev inside ext4_sb_info 2023-08-11 11:45:28 +02:00
fsmap.h
fsync.c ext4: fix race between ext4_sync_parent() and rename() 2020-06-22 09:05:22 +02:00
hash.c
ialloc.c ext4: make directory inode spreading reflect flexbg size 2022-09-28 11:02:58 +02:00
indirect.c ext4: only update i_reserved_data_blocks on successful block allocation 2023-08-11 11:45:20 +02:00
inline.c ext4: bail out of ext4_xattr_ibody_get() fails for any reason 2023-05-17 11:13:27 +02:00
inode.c ext4: only update i_reserved_data_blocks on successful block allocation 2023-08-11 11:45:20 +02:00
ioctl.c ext4: fix to check return value of freeze_bdev() in ext4_shutdown() 2023-08-11 11:45:30 +02:00
mballoc.c ext4: avoid allocating blocks from corrupted group in ext4_mb_find_by_goal() 2024-03-01 13:06:09 +01:00
mballoc.h
migrate.c ext4: fix warning in 'ext4_da_release_space' 2022-11-10 17:46:55 +01:00
mmp.c ext4: don't assume that mmp_nodename/bdevname have NUL 2020-02-19 19:51:55 +01:00
move_extent.c ext4: fix double-free of blocks due to wrong extents moved_len 2024-02-23 08:12:57 +01:00
namei.c ext4: fix rec_len verify error 2023-10-10 21:45:00 +02:00
page-io.c ext4: fix cgroup writeback accounting with fs-layer encryption 2023-03-22 13:27:08 +01:00
readpage.c
resize.c ext4: fix corruption during on-line resize 2024-04-13 12:50:06 +02:00
super.c ext4: Fix reusing stale buffer heads from last failed mounting 2023-08-11 11:45:28 +02:00
symlink.c ext4: report correct st_size for encrypted symlinks 2021-09-22 11:47:56 +02:00
sysfs.c ext4: Fix function prototype mismatch for ext4_feat_ktype 2023-02-25 11:51:51 +01:00
truncate.h
xattr.c ext4: correct inline offset when handling xattrs in inode body 2023-08-11 11:45:24 +02:00
xattr.h ext4: remove duplicate definition of ext4_xattr_ibody_inline_set() 2023-04-26 11:21:52 +02:00
xattr_security.c
xattr_trusted.c
xattr_user.c