Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e84a26ce authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

ext4: Make the extent validity check more paranoid



Instead of just checking that the extent block number is greater or
equal than s_first_data_block, make sure it it is not pointing into
the block group descriptors, since that is clearly wrong.  This helps
prevent filesystem from getting very badly corrupted in case an extent
block is corrupted.

Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 38d726d1
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -326,10 +326,13 @@ ext4_ext_max_entries(struct inode *inode, int depth)

static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
{
	ext4_fsblk_t block = ext_pblock(ext);
	ext4_fsblk_t block = ext_pblock(ext), valid_block;
	int len = ext4_ext_get_actual_len(ext);
	struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
	if (unlikely(block < le32_to_cpu(es->s_first_data_block) ||

	valid_block = le32_to_cpu(es->s_first_data_block) +
		EXT4_SB(inode->i_sb)->s_gdb_count;
	if (unlikely(block <= valid_block ||
		     ((block + len) > ext4_blocks_count(es))))
		return 0;
	else
@@ -339,9 +342,12 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
static int ext4_valid_extent_idx(struct inode *inode,
				struct ext4_extent_idx *ext_idx)
{
	ext4_fsblk_t block = idx_pblock(ext_idx);
	ext4_fsblk_t block = idx_pblock(ext_idx), valid_block;
	struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
	if (unlikely(block < le32_to_cpu(es->s_first_data_block) ||

	valid_block = le32_to_cpu(es->s_first_data_block) +
		EXT4_SB(inode->i_sb)->s_gdb_count;
	if (unlikely(block <= valid_block ||
		     (block >= ext4_blocks_count(es))))
		return 0;
	else