scsi: target: tcmu: Fix divide-by-zero in data_pages_per_blk store
Subsystems (3)
PATCH 1/1 scsi: target: tcmu: Fix divide-by-zero in data_pages_per_blk store
From: Shao Mingyin <[email protected]>
tcmu_set_data_pages_per_blk() only validates the upper bound of the value parsed from data_pages_per_blk=. Zero passes that check and is then used as the divisor when computing udev->max_blocks:
divide error: 0000 [#1] SMP
...
tcmu_set_data_pages_per_blk
tcmu_configure_device
Reject non-positive values, as the neighbouring max_data_area_mb and cmd_ring_size setters already do.
---
drivers/target/target_core_user.c +5 -0
@@ -2524,6 +2524,11 @@ static int tcmu_set_data_pages_per_blk(struct tcmu_dev *udev, substring_t *arg)return ret; } +if (val <=0 ) { +pr_err ("Invalid data_pages_per_blk %d.\n" , val); +return -EINVAL ; + } +if (val >TCMU_MBS_TO_PAGES (udev->data_area_mb)) { pr_err("Invalid data_pages_per_blk %d: greater than max_data_area_mb %d -> %zd pages).\n", val, udev->data_area_mb,
Quoted 24 lines · On 26/10/2026 12:52, [email protected] wrote:
From: Shao Mingyin <[email protected]>
tcmu_set_data_pages_per_blk()only validates the upper bound of the value parsed from data_pages_per_blk=. Zero passes that check and is then used as the divisor when computingudev->max_blocks:divide error: 0000 [#1] SMP ... tcmu_set_data_pages_per_blk tcmu_configure_deviceReject non-positive values, as the neighbouring
max_data_area_mbandcmd_ring_sizesetters already do.Fixes 08976cb548d6 ("scsi: target: tcmu: Make data_pages_per_blk changeable via configfs")Signed-off-by Shao Mingyin <[email protected]>---
drivers/target/target_core_user.c +0
-0@@ -2524,6 +2524,11 @@ static int tcmu_set_data_pages_per_blk(struct tcmu_dev *udev, substring_t *arg)return ret;
drivers/target/target_core_user.c static int tcmu_set_data_pages_per_blk(struct tcmu_dev *udev, substring_t *arg) · line 2534
Quoted 10 lines
drivers/target/target_core_user.c +5
-0} +if (val <=0 ) { +pr_err ("Invalid data_pages_per_blk %d.\n" , val); +return -EINVAL ; + } +if (val >TCMU_MBS_TO_PAGES (udev->data_area_mb)) { pr_err("Invalid data_pages_per_blk %d: greater than max_data_area_mb %d -> %zd pages).\n", val, udev->data_area_mb,
Thank you.
Regards,
Bodo Stroesser
Quoted 4 lines
tcmu_set_data_pages_per_blk()only validates the upper bound of the value parsed from data_pages_per_blk=. Zero passes that check and is then used as the divisor when computingudev->max_blocks:
Applied to 7.4/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen