]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
erofs: handle 48-bit blocks/uniaddr for extra devices
authorZhan Xusheng <zhanxusheng1024@gmail.com>
Fri, 3 Apr 2026 06:36:58 +0000 (14:36 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 7 Apr 2026 03:46:31 +0000 (11:46 +0800)
erofs_init_device() only reads blocks_lo and uniaddr_lo from the
on-disk device slot, ignoring blocks_hi and uniaddr_hi that were
introduced alongside the 48-bit block addressing feature.

For the primary device (dif0), erofs_read_superblock() already handles
this correctly by combining blocks_lo with blocks_hi when 48-bit
layout is enabled.  But the same logic was not applied to extra
devices.

With a 48-bit EROFS image using extra devices whose uniaddr or blocks
exceed 32-bit range, the truncated values cause erofs_map_dev() to
compute wrong physical addresses, leading to silent data corruption.

Fix this by reading blocks_hi and uniaddr_hi in erofs_init_device()
when 48-bit layout is enabled, consistent with the primary device
handling.  Also fix the erofs_deviceslot on-disk definition where
blocks_hi was incorrectly declared as __le32 instead of __le16.

Fixes: 61ba89b57905 ("erofs: add 48-bit block addressing on-disk support")
Suggested-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fs/erofs/erofs_fs.h
fs/erofs/super.c

index b80c6bb33a58c2f42dcac4347fd3df30b6515cb6..7871b16c1d3336f18fa9d75e97f3c6b830158948 100644 (file)
@@ -44,9 +44,9 @@ struct erofs_deviceslot {
        u8 tag[64];             /* digest(sha256), etc. */
        __le32 blocks_lo;       /* total blocks count of this device */
        __le32 uniaddr_lo;      /* unified starting block of this device */
-       __le32 blocks_hi;       /* total blocks count MSB */
+       __le16 blocks_hi;       /* total blocks count MSB */
        __le16 uniaddr_hi;      /* unified starting block MSB */
-       u8 reserved[50];
+       u8 reserved[52];
 };
 #define EROFS_DEVT_SLOT_SIZE   sizeof(struct erofs_deviceslot)
 
index 972a0c82198d7e55e55bfe3a9dc245d4ba5fb7e4..802add6652fda631ffef6814536274cae9b2fc4b 100644 (file)
@@ -129,6 +129,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
        struct erofs_fscache *fscache;
        struct erofs_deviceslot *dis;
        struct file *file;
+       bool _48bit;
 
        dis = erofs_read_metabuf(buf, sb, *pos, false);
        if (IS_ERR(dis))
@@ -175,8 +176,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
                dif->file = file;
        }
 
-       dif->blocks = le32_to_cpu(dis->blocks_lo);
-       dif->uniaddr = le32_to_cpu(dis->uniaddr_lo);
+       _48bit = erofs_sb_has_48bit(sbi);
+       dif->blocks = le32_to_cpu(dis->blocks_lo) |
+               (_48bit ? (u64)le16_to_cpu(dis->blocks_hi) << 32 : 0);
+       dif->uniaddr = le32_to_cpu(dis->uniaddr_lo) |
+               (_48bit ? (u64)le16_to_cpu(dis->uniaddr_hi) << 32 : 0);
        sbi->total_blocks += dif->blocks;
        *pos += EROFS_DEVT_SLOT_SIZE;
        return 0;