Skip to content

Commit 8a31569

Browse files
ext4: avoid resizing to a partial cluster size
jira VULN-69318 cve CVE-2022-50020 commit-author Kiselev, Oleg <[email protected]> commit 69cb8e9 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> (cherry picked from commit 69cb8e9) Signed-off-by: Pratham Patel <[email protected]>
1 parent d426f19 commit 8a31569

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
@@ -1943,6 +1943,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19431943
}
19441944
brelse(bh);
19451945

1946+
/*
1947+
* For bigalloc, trim the requested size to the nearest cluster
1948+
* boundary to avoid creating an unusable filesystem. We do this
1949+
* silently, instead of returning an error, to avoid breaking
1950+
* callers that blindly resize the filesystem to the full size of
1951+
* the underlying block device.
1952+
*/
1953+
if (ext4_has_feature_bigalloc(sb))
1954+
n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1);
1955+
19461956
retry:
19471957
o_blocks_count = ext4_blocks_count(es);
19481958

0 commit comments

Comments
 (0)