erofs: reset buf->off in erofs_init_metabuf()
PATCH 1/1 erofs: reset buf->off in erofs_init_metabuf()
From: Zhan Xusheng <[email protected]>
erofs_init_metabuf() sets buf->off only for the block device and keeps the old value when it switches to the metabox or the managed cache. erofs_bread() adds buf->off to every offset, so the result depends on how the buffer was last initialized.
getxattr and listxattr init the same buffer twice, for the inline and the shared xattrs, with in_metabox taken from different places. On a block device mount with fsoffset=, if the inode is outside the metabox and COMPAT_SHARED_EA_IN_METABOX is set, the shared xattrs are read at their metabox offset plus fsoffset. The same image mounted file-backed returns the right values.
Reset buf->off on every init.
---
Tested with a hand-edited image, as mkfs.erofs does not produce this layout.
--- fs/erofs/data.c | 1 + 1 file changed, 1 insertion(+)
fs/erofs/data.c +1 -0
@@ -60,6 +60,7 @@ int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb,struct erofs_sb_info *sbi =EROFS_SB (sb); buf->mc = false; + buf->off =0 ;if (in_metabox) {if (unlikely (!sbi->metabox_inode))return -EFSCORRUPTED ;
base-commit: 7c26dc33ea7bb677db294bfb4e58d4207477c9e3
Signature · 1 line
2.43.0
Quoted 14 lines · Zhan Xusheng
From: Zhan Xusheng <[email protected]>
erofs_init_metabuf()setsbuf->offonly for the block device and keeps the old value when it switches to the metabox or the managed cache.erofs_bread()addsbuf->offto every offset, so the result depends on how the buffer was last initialized.getxattr and listxattr init the same buffer twice, for the inline and the shared xattrs, with
in_metaboxtaken from different places. On a block device mount with fsoffset=, if the inode is outside the metabox andCOMPAT_SHARED_EA_IN_METABOXis set, the shared xattrs are read at their metabox offset plus fsoffset. The same image mounted file-backed returns the right values.
Quoted 4 lines
Reset
buf->offon every init.Fixes 414091322c63 ("erofs: implement metadata compression")Signed-off-by Zhan Xusheng <[email protected]>
Thanks,
Gao Xiang