[PATCH v2] erofs-utils: lib: fix xattr crash in rebuild path when source has xattr

lishixian lishixian8 at huawei.com
Tue Mar 3 13:39:11 AEDT 2026


When rebuilding from source EROFS images, erofs_read_xattrs_from_disk()
is called for inodes that have xattr. At that point inode->sbi points to
the source image's sbi, which is opened read-only and never gets
erofs_xattr_init(), so sbi->xamgr is NULL. get_xattritem(sbi) then
dereferences xamgr and crashes with SIGSEGV.

Fix by using the build target's xamgr when initializing src's sbi.

Reported-by: Yixiao Chen <489679970 at qq.com>
Fixes: https://github.com/erofs/erofs-utils/issues/42
Signed-off-by: lishixian <lishixian8 at huawei.com>
Reviewed-by: Yifan Zhao <zhaoyifan28 at huawei.com>
---
 mkfs/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mkfs/main.c b/mkfs/main.c
index b84d1b4..58c18f9 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1735,7 +1735,9 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)
 	}
 
 	list_for_each_entry(src, &rebuild_src_list, list) {
+		src->xamgr = g_sbi.xamgr;
 		ret = erofs_rebuild_load_tree(root, src, datamode);
+		src->xamgr = NULL;
 		if (ret) {
 			erofs_err("failed to load %s", src->devname);
 			return ret;
-- 
2.47.3



More information about the Linux-erofs mailing list