Skip to contentSkip to conversation

erofs: fix interlaced ztailpacking pclusters

PATCH In review Gao Xiang 2 participants 2 messages Aug 14 – Aug 17 EROFS file system

lore
Share & tools
lore

Gao Xiang

author maintainer
#0 lore raw

PATCH 1/1 erofs: fix interlaced ztailpacking pclusters

On-disk sizes of interlaced pclusters should be block-aligned, and ztailpacking interlaced pclusters should be invalid at all.

Currently, mkfs.erofs won't generate any interlaced pcluster with ztailpacking enabled, so this doesn't affect any existing valid filesystems.

However, crafted images can contain invalid interlaced ztailpacking pclusters, resulting in an out-of-bounds read from a kmap'd page and copying irrelevant kernel memory into userspace-visible page cache.

Fixes fdffc091e6f9 ("erofs: support interlaced uncompressed data for compressed files")
---
 fs/erofs/decompressor.c | 1 +
 fs/erofs/zmap.c         | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
fs/erofs/decompressor.c +1 -0
index 3c54e95964c9..27caf4bebddc 100644
@@ -299,6 +299,7 @@ static const char *z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
 		return ERR_PTR(-EOPNOTSUPP);
 	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
 		cur = bs - (rq->pageofs_out & (bs - 1));
+		DBG_BUGON(rq->pageofs_in & (bs - 1));
 		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
 		cur = min(cur, rq->outputsize);
 		if (cur && rq->out[0]) {
fs/erofs/zmap.c +2 -1
index 5811556a7b71..331a231dfe13 100644
@@ -483,7 +483,8 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
 	}
 
 	if (m.headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN) {
-		if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER)
+		if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER &&
+		    !(map->m_flags & EROFS_MAP_META))
 			map->m_algorithmformat = Z_EROFS_COMPRESSION_INTERLACED;
 		else
 			map->m_algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Gao Xiang

On-disk sizes of interlaced pclusters should be block-aligned, and ztailpacking interlaced pclusters should be invalid at all.

Currently, mkfs.erofs won't generate any interlaced pcluster with ztailpacking enabled, so this doesn't affect any existing valid filesystems.

However, crafted images can contain invalid interlaced ztailpacking pclusters, resulting in an out-of-bounds read from a kmap'd page and copying irrelevant kernel memory into userspace-visible page cache.

Nitpick, if this can only happen in a fuzz case, we can add unlikely for !(map->m_flags & EROFS_MAP_META)?

Quoted 5 lines
Fixes fdffc091e6f9 ("erofs: support interlaced uncompressed data for compressed files")

Thanks,