mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
scsi: sd_zbc: Reject disks with too many zones
sd_zbc_read_zones() computes the number of zones with 64-bit arithmetic and
stores the result in the unsigned int nr_zones field of struct
zoned_disk_info, silently truncating counts that exceed 32 bits. The
truncated count is later used to size per-zone resources, while the device
may still report more zones than fit.
Moreover, sd_zbc_report_zones() counts the reported zones with a signed int
zone_idx, which overflows past INT_MAX. Reject devices reporting more than
INT_MAX zones at scan time; such a device is not realistic for any medium
that exists today, and accepting it produces inconsistent zone bookkeeping.
Fixes: 89d9475610 ("sd: Implement support for ZBC devices")
Signed-off-by: ZHOU Jiaxiang <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Martin K. Petersen (Oracle) <[email protected]>
This commit is contained in:
1 parent
7c431d61b6
commit
b6ec0f7974
1 file changed
+7
-1
@@ -589,7 +589,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
|
||||
int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
|
||||
u8 buf[SD_BUF_SIZE])
|
||||
{
|
||||
unsigned int nr_zones;
|
||||
u64 nr_zones;
|
||||
u32 zone_blocks = 0;
|
||||
int ret;
|
||||
|
||||
@@ -621,6 +621,12 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
|
||||
goto err;
|
||||
|
||||
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
|
||||
if (nr_zones > INT_MAX) {
|
||||
sd_printk(KERN_ERR, sdkp, "Too many zones (%llu)\n",
|
||||
nr_zones);
|
||||
ret = -EINVAL;
|
||||
goto err;
|
||||
}
|
||||
sdkp->early_zone_info.nr_zones = nr_zones;
|
||||
sdkp->early_zone_info.zone_blocks = zone_blocks;
|
||||
|
||||
|
||||
Reference in new issue
Block a user