From ffaab71302ca81ac4addbc63f5a81be37988595a Mon Sep 17 00:00:00 2001 From: sunshijie Date: Mon, 21 Aug 2023 21:02:05 +0800 Subject: [PATCH] UPSTREAM: 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 Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support") Reviewed-by: Gao Xiang Reviewed-by: Chao Yu Link: https://lore.kernel.org/r/20230710093410.44071-1-guochunhai@vivo.com Signed-off-by: Gao Xiang (cherry picked from commit 8191213a5835b0317c5e4d0d337ae1ae00c75253 https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev) Bug: 296824280 Change-Id: I152508ba4c0eb83aeae5d753e22b0ca8d3ada56d Signed-off-by: sunshijie Signed-off-by: sunshijie --- fs/erofs/zdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 01c1ab655277..a08299d80ca1 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -855,7 +855,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, */ tight &= (fe->mode > Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE); - cur = end - min_t(unsigned int, offset + end - map->m_la, end); + cur = end - min_t(erofs_off_t, offset + end - map->m_la, end); if (!(map->m_flags & EROFS_MAP_MAPPED)) { zero_user_segment(page, cur, end); goto next_part;