- 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]")
Signed-off-by: Gao Xiang <[email protected]>
---
 lib/data.c  | 3 +++
 lib/super.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/lib/data.c b/lib/data.c
index 1e5113406512..6fd1389cc09f 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -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);
diff --git a/lib/super.c b/lib/super.c
index d626c7cdc76f..5b4a2eb2470d 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -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);
-- 
2.43.5


Reply via email to