Skip to content

Commit 4a2d046

Browse files
committed
erofs: fix interlaced plain identification for encoded extents
Only plain data whose start position and on-disk physical length are both aligned to the block size should be classified as interlaced plain extents. Otherwise, it must be treated as shifted plain extents. This issue was found by syzbot using a crafted compressed image containing plain extents with unaligned physical lengths, which can cause OOB read in z_erofs_transform_plain(). Reported-and-tested-by: syzbot+d988dc155e740d76a331@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/699d5714.050a0220.cdd3c.03e7.GAE@google.com Fixes: 1d191b4 ("erofs: implement encoded extent metadata") Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent bf4fde7 commit 4a2d046

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

fs/erofs/zmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static int z_erofs_map_blocks_ext(struct inode *inode,
513513
unsigned int recsz = z_erofs_extent_recsize(vi->z_advise);
514514
erofs_off_t pos = round_up(Z_EROFS_MAP_HEADER_END(erofs_iloc(inode) +
515515
vi->inode_isize + vi->xattr_isize), recsz);
516+
unsigned int bmask = sb->s_blocksize - 1;
516517
bool in_mbox = erofs_inode_in_metabox(inode);
517518
erofs_off_t lend = inode->i_size;
518519
erofs_off_t l, r, mid, pa, la, lstart;
@@ -596,17 +597,17 @@ static int z_erofs_map_blocks_ext(struct inode *inode,
596597
map->m_flags |= EROFS_MAP_MAPPED |
597598
EROFS_MAP_FULL_MAPPED | EROFS_MAP_ENCODED;
598599
fmt = map->m_plen >> Z_EROFS_EXTENT_PLEN_FMT_BIT;
600+
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
601+
map->m_flags |= EROFS_MAP_PARTIAL_REF;
602+
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
599603
if (fmt)
600604
map->m_algorithmformat = fmt - 1;
601-
else if (interlaced && !erofs_blkoff(sb, map->m_pa))
605+
else if (interlaced && !((map->m_pa | map->m_plen) & bmask))
602606
map->m_algorithmformat =
603607
Z_EROFS_COMPRESSION_INTERLACED;
604608
else
605609
map->m_algorithmformat =
606610
Z_EROFS_COMPRESSION_SHIFTED;
607-
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
608-
map->m_flags |= EROFS_MAP_PARTIAL_REF;
609-
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
610611
}
611612
}
612613
map->m_llen = lend - map->m_la;

0 commit comments

Comments
 (0)