Skip to content

Commit 50fda57

Browse files
committed
ext4: avoid resizing to a partial cluster size
jira VULN-135014 cve CVE-2022-50020 commit-author Kiselev, Oleg <okiselev@amazon.com> commit 69cb8e9 upstream-diff This kernel doesn't have the ext4_feature_has_bigalloc helper, so this commit uses the EXT4_HAS_RO_COMPAT_FEATURE macro which does the same thing This patch avoids an attempt to resize the filesystem to an unaligned cluster boundary. An online resize to a size that is not integral to cluster size results in the last iteration attempting to grow the fs by a negative amount, which trips a BUG_ON and leaves the fs with a corrupted in-memory superblock. Signed-off-by: Oleg Kiselev <okiselev@amazon.com> Link: https://lore.kernel.org/r/0E92A0AB-4F16-4F1A-94B7-702CC6504FDE@amazon.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> (cherry picked from commit 69cb8e9) Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent d4221b3 commit 50fda57

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/ext4/resize.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19001900
}
19011901
brelse(bh);
19021902

1903+
/*
1904+
* For bigalloc, trim the requested size to the nearest cluster
1905+
* boundary to avoid creating an unusable filesystem. We do this
1906+
* silently, instead of returning an error, to avoid breaking
1907+
* callers that blindly resize the filesystem to the full size of
1908+
* the underlying block device.
1909+
*/
1910+
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC))
1911+
n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1);
1912+
19031913
retry:
19041914
o_blocks_count = ext4_blocks_count(es);
19051915

0 commit comments

Comments
 (0)