linux-stable/fs/ext4
Maximilian Heyne b461910af8 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-03 15:11:20 +02:00
..
.kunitconfig
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile
acl.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
acl.h ext4: apply umask if ACL support is disabled 2023-10-05 22:32:15 -04:00
balloc.c ext4: add some kunit stub for mballoc kunit test 2023-10-05 22:32:16 -04:00
bitmap.c ext4: remove useless conditional branch code 2023-04-19 23:39:08 -04:00
block_validity.c ext4: add correct group descriptors and reserved GDT blocks to system zone 2023-08-27 11:27:12 -04:00
crypto.c fscrypt: support crypto data unit size less than filesystem block size 2023-09-25 22:34:33 -07:00
dir.c
ext4.h quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
ext4_extents.h
ext4_jbd2.c Many ext4 and jbd2 cleanups and bug fixes for v6.6-rc1. 2023-08-31 15:18:15 -07:00
ext4_jbd2.h
extents.c ext4: correct the hole length returned by ext4_map_blocks() 2024-03-01 13:41:39 +01:00
extents_status.c Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
extents_status.h ext4: make ext4_es_insert_extent() return void 2023-06-26 19:35:12 -04:00
fast_commit.c ext4: make state in ext4_mb_mark_bb to be bool 2023-10-05 22:32:15 -04:00
fast_commit.h
file.c ext4: fix warning in ext4_dio_write_end_io() 2023-11-30 23:29:34 -05:00
fsmap.c ext4: Convert to bdev_open_by_dev() 2023-10-28 13:29:20 +02:00
fsmap.h
fsync.c ext4: drop EXT4_MF_FS_ABORTED flag 2023-07-29 18:37:53 -04:00
hash.c ext4: remove redundant checks of s_encoding 2023-08-27 11:27:13 -04:00
ialloc.c ext4: convert to new timestamp accessors 2023-10-18 13:26:21 +02:00
indirect.c ext4: only update i_reserved_data_blocks on successful block allocation 2023-06-26 19:34:56 -04:00
inline.c ext4: convert to new timestamp accessors 2023-10-18 13:26:21 +02:00
inode-test.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
inode.c Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
ioctl.c ext4: convert to new timestamp accessors 2023-10-18 13:26:21 +02:00
mballoc-test.c ext4: run mballoc test with different layouts setting 2023-10-05 22:32:16 -04:00
mballoc.c ext4: correct best extent lstart adjustment logic 2024-04-03 15:11:11 +02:00
mballoc.h ext4: add two helper functions extent_logical_end() and pa_logical_end() 2023-07-29 00:02:30 -04:00
migrate.c ext4: avoid deadlock in fs reclaim with page writeback 2023-05-13 18:05:04 -04:00
mmp.c ext4: replace read-only check for shutdown check in mmp code 2023-07-29 18:37:53 -04:00
move_extent.c ext4: fix double-free of blocks due to wrong extents moved_len 2024-02-23 09:51:40 +01:00
namei.c Cleanup ext4's multi-block allocator, including adding some unit 2023-11-02 07:45:14 -10:00
orphan.c
page-io.c ext4: make ext4_forced_shutdown() take struct super_block 2023-07-29 18:37:24 -04:00
readpage.c ext4: use folio_end_read() 2023-10-18 14:34:16 -07:00
resize.c ext4: fix corruption during on-line resize 2024-04-03 15:11:20 +02:00
super.c quota: Properly annotate i_dquot arrays with __rcu 2024-03-26 18:18:32 -04:00
symlink.c
sysfs.c ext4: Give symbolic names to mballoc criterias 2023-06-26 19:34:56 -04:00
truncate.h
verity.c - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07:00
xattr.c vfs-6.7.ctime 2023-10-30 09:47:13 -10:00
xattr.h ext4: move ext4_xattr_handlers to .rodata 2023-10-09 16:24:16 +02:00
xattr_hurd.c
xattr_security.c
xattr_trusted.c
xattr_user.c