Skip to content

Commit 4e2524b

Browse files
LiBaokun96tytso
authored andcommitted
ext4: avoid use-after-free in ext4_ext_show_leaf()
In ext4_find_extent(), path may be freed by error or be reallocated, so using a previously saved *ppath may have been freed and thus may trigger use-after-free, as follows: ext4_split_extent path = *ppath; ext4_split_extent_at(ppath) path = ext4_find_extent(ppath) ext4_split_extent_at(ppath) // ext4_find_extent fails to free path // but zeroout succeeds ext4_ext_show_leaf(inode, path) eh = path[depth].p_hdr // path use-after-free !!! Similar to ext4_split_extent_at(), we use *ppath directly as an input to ext4_ext_show_leaf(). Fix a spelling error by the way. Same problem in ext4_ext_handle_unwritten_extents(). Since 'path' is only used in ext4_ext_show_leaf(), remove 'path' and use *ppath directly. This issue is triggered only when EXT_DEBUG is defined and therefore does not affect functionality. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Tested-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://patch.msgid.link/20240822023545.1994557-5-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent c26ab35 commit 4e2524b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/ext4/extents.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@ static int ext4_split_extent_at(handle_t *handle,
33273327
}
33283328

33293329
/*
3330-
* ext4_split_extents() splits an extent and mark extent which is covered
3330+
* ext4_split_extent() splits an extent and mark extent which is covered
33313331
* by @map as split_flags indicates
33323332
*
33333333
* It may result in splitting the extent into multiple extents (up to three)
@@ -3403,7 +3403,7 @@ static int ext4_split_extent(handle_t *handle,
34033403
goto out;
34043404
}
34053405

3406-
ext4_ext_show_leaf(inode, path);
3406+
ext4_ext_show_leaf(inode, *ppath);
34073407
out:
34083408
return err ? err : allocated;
34093409
}
@@ -3868,14 +3868,13 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
38683868
struct ext4_ext_path **ppath, int flags,
38693869
unsigned int allocated, ext4_fsblk_t newblock)
38703870
{
3871-
struct ext4_ext_path __maybe_unused *path = *ppath;
38723871
int ret = 0;
38733872
int err = 0;
38743873

38753874
ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocated %u\n",
38763875
(unsigned long long)map->m_lblk, map->m_len, flags,
38773876
allocated);
3878-
ext4_ext_show_leaf(inode, path);
3877+
ext4_ext_show_leaf(inode, *ppath);
38793878

38803879
/*
38813880
* When writing into unwritten space, we should not fail to
@@ -3972,7 +3971,7 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39723971
if (allocated > map->m_len)
39733972
allocated = map->m_len;
39743973
map->m_len = allocated;
3975-
ext4_ext_show_leaf(inode, path);
3974+
ext4_ext_show_leaf(inode, *ppath);
39763975
out2:
39773976
return err ? err : allocated;
39783977
}

0 commit comments

Comments
 (0)