Skip to content

Commit d5559ac

Browse files
zhanxusheng1024-osgregkh
authored andcommitted
erofs: handle 48-bit blocks/uniaddr for extra devices
[ Upstream commit 63c2f06 ] 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: 61ba89b ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 62c4456 commit d5559ac

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

fs/erofs/erofs_fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ struct erofs_deviceslot {
4444
u8 tag[64]; /* digest(sha256), etc. */
4545
__le32 blocks_lo; /* total blocks count of this device */
4646
__le32 uniaddr_lo; /* unified starting block of this device */
47-
__le32 blocks_hi; /* total blocks count MSB */
47+
__le16 blocks_hi; /* total blocks count MSB */
4848
__le16 uniaddr_hi; /* unified starting block MSB */
49-
u8 reserved[50];
49+
u8 reserved[52];
5050
};
5151
#define EROFS_DEVT_SLOT_SIZE sizeof(struct erofs_deviceslot)
5252

fs/erofs/super.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
140140
struct erofs_fscache *fscache;
141141
struct erofs_deviceslot *dis;
142142
struct file *file;
143+
bool _48bit;
143144

144145
dis = erofs_read_metabuf(buf, sb, *pos, false);
145146
if (IS_ERR(dis))
@@ -186,8 +187,11 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
186187
dif->file = file;
187188
}
188189

189-
dif->blocks = le32_to_cpu(dis->blocks_lo);
190-
dif->uniaddr = le32_to_cpu(dis->uniaddr_lo);
190+
_48bit = erofs_sb_has_48bit(sbi);
191+
dif->blocks = le32_to_cpu(dis->blocks_lo) |
192+
(_48bit ? (u64)le16_to_cpu(dis->blocks_hi) << 32 : 0);
193+
dif->uniaddr = le32_to_cpu(dis->uniaddr_lo) |
194+
(_48bit ? (u64)le16_to_cpu(dis->uniaddr_hi) << 32 : 0);
191195
sbi->total_blocks += dif->blocks;
192196
*pos += EROFS_DEVT_SLOT_SIZE;
193197
return 0;

0 commit comments

Comments
 (0)