Skip to content

Commit 0bc8061

Browse files
committed
erofs: handle NONHEAD !delta[1] lclusters gracefully
syzbot reported a WARNING in iomap_iter_done: iomap_fiemap+0x73b/0x9b0 fs/iomap/fiemap.c:80 ioctl_fiemap fs/ioctl.c:220 [inline] Generally, NONHEAD lclusters won't have delta[1]==0, except for crafted images and filesystems created by pre-1.0 mkfs versions. Previously, it would immediately bail out if delta[1]==0, which led to inadequate decompressed lengths (thus FIEMAP is impacted). Treat it as delta[1]=1 to work around these legacy mkfs versions. `lclusterbits > 14` is illegal for compact indexes, error out too. Reported-by: syzbot+6c0b301317aa0156f9eb@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/67373c0c.050a0220.2a2fcc.0079.GAE@google.com Tested-by: syzbot+6c0b301317aa0156f9eb@syzkaller.appspotmail.com Fixes: d95ae5e ("erofs: add support for the full decompressed length") Fixes: 001b8cc ("erofs: fix compact 4B support for 16k block size") Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20241115173651.3339514-1-hsiangkao@linux.alibaba.com
1 parent b49c021 commit 0bc8061

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

fs/erofs/zmap.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
219219
unsigned int amortizedshift;
220220
erofs_off_t pos;
221221

222-
if (lcn >= totalidx)
222+
if (lcn >= totalidx || vi->z_logical_clusterbits > 14)
223223
return -EINVAL;
224224

225225
m->lcn = lcn;
@@ -390,7 +390,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
390390
u64 lcn = m->lcn, headlcn = map->m_la >> lclusterbits;
391391
int err;
392392

393-
do {
393+
while (1) {
394394
/* handle the last EOF pcluster (no next HEAD lcluster) */
395395
if ((lcn << lclusterbits) >= inode->i_size) {
396396
map->m_llen = inode->i_size - map->m_la;
@@ -402,14 +402,16 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
402402
return err;
403403

404404
if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
405-
DBG_BUGON(!m->delta[1] &&
406-
m->clusterofs != 1 << lclusterbits);
405+
/* work around invalid d1 generated by pre-1.0 mkfs */
406+
if (unlikely(!m->delta[1])) {
407+
m->delta[1] = 1;
408+
DBG_BUGON(1);
409+
}
407410
} else if (m->type == Z_EROFS_LCLUSTER_TYPE_PLAIN ||
408411
m->type == Z_EROFS_LCLUSTER_TYPE_HEAD1 ||
409412
m->type == Z_EROFS_LCLUSTER_TYPE_HEAD2) {
410-
/* go on until the next HEAD lcluster */
411413
if (lcn != headlcn)
412-
break;
414+
break; /* ends at the next HEAD lcluster */
413415
m->delta[1] = 1;
414416
} else {
415417
erofs_err(inode->i_sb, "unknown type %u @ lcn %llu of nid %llu",
@@ -418,8 +420,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
418420
return -EOPNOTSUPP;
419421
}
420422
lcn += m->delta[1];
421-
} while (m->delta[1]);
422-
423+
}
423424
map->m_llen = (lcn << lclusterbits) + m->clusterofs - map->m_la;
424425
return 0;
425426
}

0 commit comments

Comments
 (0)