Skip to content

Commit a18ed35

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: always check ext4_ext_find_extent result
Where are some places where logic guaranties us that extent we are searching exits, but this may not be true due to on-disk data corruption. If such corruption happens we must prevent possible null pointer dereferences. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 8dc79ec commit a18ed35

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,11 @@ static int ext4_split_extent(handle_t *handle,
33133313
return PTR_ERR(path);
33143314
depth = ext_depth(inode);
33153315
ex = path[depth].p_ext;
3316+
if (!ex) {
3317+
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
3318+
(unsigned long) map->m_lblk);
3319+
return -EIO;
3320+
}
33163321
uninitialized = ext4_ext_is_uninitialized(ex);
33173322
split_flag1 = 0;
33183323

@@ -3694,6 +3699,12 @@ static int ext4_convert_initialized_extents(handle_t *handle,
36943699
}
36953700
depth = ext_depth(inode);
36963701
ex = path[depth].p_ext;
3702+
if (!ex) {
3703+
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
3704+
(unsigned long) map->m_lblk);
3705+
err = -EIO;
3706+
goto out;
3707+
}
36973708
}
36983709

36993710
err = ext4_ext_get_access(handle, inode, path + depth);
@@ -5340,6 +5351,12 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
53405351
return PTR_ERR(path);
53415352
depth = path->p_depth;
53425353
extent = path[depth].p_ext;
5354+
if (!extent) {
5355+
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
5356+
(unsigned long) start);
5357+
return -EIO;
5358+
}
5359+
53435360
current_block = le32_to_cpu(extent->ee_block);
53445361
if (start > current_block) {
53455362
/* Hole, move to the next extent */

0 commit comments

Comments
 (0)