Skip to content

Commit c99493c

Browse files
committed
erofs: fix offset truncation when shifting pgoff on 32-bit platforms
On 32-bit platforms, pgoff_t is 32 bits wide, so left-shifting large arbitrary pgoff_t values by PAGE_SHIFT performs 32-bit arithmetic and silently truncates the result for pages beyond the 4 GiB boundary. Cast the page index to loff_t before shifting to produce a correct 64-bit byte offset. Fixes: 3862929 ("erofs: introduce readmore decompression strategy") Fixes: 307210c ("erofs: verify metadata accesses for file-backed mounts") Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent d18a3b5 commit c99493c

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

fs/erofs/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
3939
* However, the data access range must be verified here in advance.
4040
*/
4141
if (buf->file) {
42-
fpos = index << PAGE_SHIFT;
42+
fpos = (loff_t)index << PAGE_SHIFT;
4343
err = rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE);
4444
if (err < 0)
4545
return ERR_PTR(err);

fs/erofs/zdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
18721872

18731873
if (cur < PAGE_SIZE)
18741874
break;
1875-
cur = (index << PAGE_SHIFT) - 1;
1875+
cur = ((loff_t)index << PAGE_SHIFT) - 1;
18761876
}
18771877
}
18781878

0 commit comments

Comments
 (0)