Skip to contentSkip to conversation

erofs-utils: lib: avoid malformed metabox metadata

PATCH New Gao Xiang 1 participant 1 message Nov 23, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: avoid malformed metabox metadata

- If metadata compression is off, images shouldn't have METABOX-marked NIDs;

- metabox_nid itself shouldn't be METABOX-marked.

Fixes 7928074b7643 ("erofs-utils: introduce metadata compression [metabox]")
---
 lib/data.c  | 3 +++
 lib/super.c | 2 ++
 2 files changed, 5 insertions(+)
lib/data.c +3 -0
index 1e5113406512..6fd1389cc09f 100644
@@ -30,6 +30,9 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
 		 *       cache to improve userspace metadata performance.
 		 */
 		if (!vf) {
+			if (!erofs_sb_has_metabox(sbi))
+				return ERR_PTR(-EFSCORRUPTED);
+
 			vi = (struct erofs_inode) { .sbi = sbi,
 						    .nid = sbi->metabox_nid };
 			err = erofs_read_inode_from_disk(&vi);
lib/super.c +2 -0
index d626c7cdc76f..5b4a2eb2470d 100644
@@ -133,6 +133,8 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 					     metabox_nid))
 			return -EFSCORRUPTED;
 		sbi->metabox_nid = le64_to_cpu(dsb->metabox_nid);
+		if (sbi->metabox_nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT))
+			return -EFSCORRUPTED;	/* self-loop detection */
 	}
 	sbi->inos = le64_to_cpu(dsb->inos);
 	sbi->checksum = le32_to_cpu(dsb->checksum);
Signature · 1 line
2.43.5