Commit 3fafd915 authored by sunshijie's avatar sunshijie Committed by Matthias Männich
Browse files

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: default avatarChunhai Guo <guochunhai@vivo.com>
Fixes: 3883a79a ("staging: erofs: introduce VLE decompression support")
Reviewed-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Link: https://lore.kernel.org/r/20230710093410.44071-1-guochunhai@vivo.com


Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
(cherry picked from commit 8191213a
    https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git

 dev)
Bug: 296824280
Bug: 298150234
Change-Id: I152508ba4c0eb83aeae5d753e22b0ca8d3ada56d
Signed-off-by: default avatarsunshijie <sunshijie@xiaomi.corp-partner.google.com>
Signed-off-by: default avatarsunshijie <sunshijie@xiaomi.com>
(cherry picked from commit ffaab713)
parent 8fdad5df
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment