Skip to content

Commit 8191213

Browse files
Chunhai Guohsiangkao
authored andcommitted
erofs: avoid infinite loop in z_erofs_do_read_page() when reading beyond EOF
z_erofs_do_read_page() may loop infinitely due to the inappropriate truncation in the below statement. Since the offset is 64 bits and min_t() truncates the result to 32 bits. The solution is to replace unsigned int with a 64-bit type, such as erofs_off_t. cur = end - min_t(unsigned int, offset + end - map->m_la, end); - For example: - offset = 0x400160000 - end = 0x370 - map->m_la = 0x160370 - offset + end - map->m_la = 0x400000000 - offset + end - map->m_la = 0x00000000 (truncated as unsigned int) - Expected result: - cur = 0 - Actual result: - cur = 0x370 Signed-off-by: Chunhai Guo <[email protected]> Fixes: 3883a79 ("staging: erofs: introduce VLE decompression support") Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 936aa70 commit 8191213

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/erofs/zdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
10351035
*/
10361036
tight &= (fe->mode > Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE);
10371037

1038-
cur = end - min_t(unsigned int, offset + end - map->m_la, end);
1038+
cur = end - min_t(erofs_off_t, offset + end - map->m_la, end);
10391039
if (!(map->m_flags & EROFS_MAP_MAPPED)) {
10401040
zero_user_segment(page, cur, end);
10411041
goto next_part;

0 commit comments

Comments
 (0)