linux/fs/erofs
Binglei Wang 135d84c66f erofs: add missing buf->off in erofs_bread()
erofs_bread() locates the target folio with

 index = (buf->off + offset) >> PAGE_SHIFT;

but computes the in-folio offset without taking buf->off into account:

 return buf->base + (offset & ~PAGE_MASK);

If buf->off is not page-aligned, the returned pointer misses the in-page
component of buf->off, so callers end up fetching data from a wrong
offset.

buf->off is set to sbi->dif0.fsoff in erofs_init_metabuf(), and fsoff can
be specified via the "fsoffset=" mount option, which only requires
block-size alignment. Therefore, on an image with a sub-page block size
(e.g. 512 bytes), a non-page-aligned fsoff (e.g. 512) triggers the issue,
since 512 is a multiple of the block size but not of PAGE_SIZE.

It can be reproduced by mounting an image that is placed at a
non-page-aligned offset:

 mkfs.erofs -b512 -zlz4hc sub.erofs src/
 # prepend 512 bytes of padding to the image
 mount -t erofs -o loop,fsoffset=512 padded.erofs /mnt

which fails with

 erofs (device loop0): cannot find valid erofs superblock

because the on-disk superblock (at offset 1024 within the image, i.e.
1536 within the padded file) is read from a wrong in-folio offset. With
this fixed, the very same image mounts successfully and its file contents
match those read from the unpadded image.

Fix it by including buf->off in the in-folio offset calculation, so that
it is consistent with the folio index calculation.

Fixes: c36ec00d7f ("erofs: add 'fsoffset' mount option to specify filesystem offset")
Signed-off-by: Binglei Wang <l3b2w1@gmail.com>
Reviewed-by: Gao Xiang <xiang@kernel.org>
Signed-off-by: Gao Xiang <xiang@kernel.org>
2026-09-11 12:16:20 +08:00
..
compress.h erofs: enable error reporting for z_erofs_fixup_insize() 2025-11-30 23:49:32 +08:00
data.c erofs: add missing buf->off in erofs_bread() 2026-09-11 12:16:20 +08:00
decompressor_crypto.c erofs: make z_erofs_crypto[] static 2026-01-23 00:00:18 +08:00
decompressor_deflate.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
decompressor_lzma.c erofs: preserve LZMA decoders on resize failure 2026-09-02 10:32:01 +08:00
decompressor_zstd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
decompressor.c erofs: disable LZ4 rolling decompression for now 2026-09-03 22:49:35 +08:00
dir.c erofs: fix the out-of-bounds nameoff handling for trailing dirents 2026-04-21 16:56:04 +08:00
erofs_fs.h erofs: add sparse support to pcluster layout 2026-06-22 06:48:59 +08:00
fileio.c erofs: use dedicated meta inodes for file-backed mounts 2026-08-11 19:46:23 +08:00
inode.c erofs: handle 48-bit blocks_hi for compressed inodes 2026-06-22 18:50:36 +08:00
internal.h erofs: disable LZ4 rolling decompression for now 2026-09-03 22:49:35 +08:00
ishare.c erofs: support large folios in inode_share mode 2026-08-24 12:20:57 +08:00
Kconfig erofs: Fix EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS default logic 2026-08-24 12:20:11 +08:00
Makefile erofs: remove fscache backend entirely 2026-06-22 11:00:06 +08:00
namei.c erofs: get rid of erofs_kmap_type 2025-03-17 01:21:24 +08:00
super.c Changes since last update: 2026-08-20 12:24:48 -07:00
sysfs.c erofs: add sysfs feature entry for xattr prefixes 2026-09-02 10:03:30 +08:00
xattr.c erofs: delimit inode_share cache key components 2026-09-07 18:20:30 +08:00
xattr.h erofs: mark inodes without acls in erofs_read_inode() 2026-01-28 15:38:37 +08:00
zdata.c erofs: disable LZ4 rolling decompression for now 2026-09-03 22:49:35 +08:00
zmap.c Changes since last update: 2026-08-20 12:24:48 -07:00
zutil.c erofs: simplify z_erofs_gbuf_growsize() 2026-08-24 12:21:24 +08:00