Skip to contentSkip to conversation

erofs: reset buf->off in erofs_init_metabuf()

PATCH In review Zhan Xusheng 2 participants 2 messages Nov 11 EROFS file system

lore
Share & tools
lore
#0 lore raw

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.

Fixes 414091322c63 ("erofs: implement metadata compression")

---
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
index 968303afd620..da4f3e7bd443 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Zhan Xusheng

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.

Quoted 4 lines

Reset buf->off on every init.

Fixes 414091322c63 ("erofs: implement metadata compression")

Thanks,
Gao Xiang