nvme: Fix handling of large MDTS values
PATCH v3 1/1 nvme: Fix handling of large MDTS values
Instead of triggering an integer overflow and undefined behavior if MDTS is large, set max_hw_sectors to UINT_MAX.
---
Changes compared to v2: reduced the two max_hw_sectors = UINT_MAX statements into a single assignment. Changes compared to v1: removed a dev_err() call.
drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +3 -3
@@ -3123,10 +3123,10 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; -if (id->mdts) - max_hw_sectors =1 << (id->mdts + page_shift -9 ); -else +if (!id->mdts ||check_shl_overflow (1U , id->mdts + page_shift -9 , + &max_hw_sectors)) { max_hw_sectors =UINT_MAX ; + } ctrl->max_hw_sectors =min_not_zero (ctrl->max_hw_sectors, max_hw_sectors);
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 2 lines · Bart Van Assche
Instead of triggering an integer overflow and undefined behavior if MDTS is large, set
max_hw_sectorstoUINT_MAX.
Looks good,
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 20 lines · Bart Van Assche
Instead of triggering an integer overflow and undefined behavior if MDTS is large, set
max_hw_sectorstoUINT_MAX.Cc Christoph Hellwig <[email protected]>Cc Sagi Grimberg <[email protected]>Cc Keith Busch <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
Changes compared to v2: reduced the two
max_hw_sectors=UINT_MAXstatements into a single assignment. Changes compared to v1: removed adev_err()call.drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 3129
Quoted 10 lines
drivers/nvme/host/core.c +3
-3@@ -3123,10 +3123,10 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; -if (id->mdts) - max_hw_sectors =1 << (id->mdts + page_shift -9 ); -else +if (!id->mdts ||check_shl_overflow (1U , id->mdts + page_shift -9 , + &max_hw_sectors)) { max_hw_sectors =UINT_MAX ; + }
Nit: this could be rewritten as:
if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9, &max_hw_sectors)) max_hw_sectors = UINT_MAX;
More readable and no unneeded brackets. No ?
Quoted 9 lines
drivers/nvme/host/core.c +0
-0ctrl->max_hw_sectors =min_not_zero (ctrl->max_hw_sectors, max_hw_sectors);_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Signature · 7 lines
Damien Le Moal Western Digital Research _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 34 lines · Damien Le Moal
Quoted 20 lines · Bart Van Assche
Instead of triggering an integer overflow and undefined behavior if MDTS is large, set
max_hw_sectorstoUINT_MAX.Cc Christoph Hellwig <[email protected]>Cc Sagi Grimberg <[email protected]>Cc Keith Busch <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
Changes compared to v2: reduced the two
max_hw_sectors=UINT_MAXstatements into a single assignment. Changes compared to v1: removed adev_err()call.drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +0
-0drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 3129
Quoted 10 lines
drivers/nvme/host/core.c +3
-3@@ -3123,10 +3123,10 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; -if (id->mdts) - max_hw_sectors =1 << (id->mdts + page_shift -9 ); -else +if (!id->mdts ||check_shl_overflow (1U , id->mdts + page_shift -9 , + &max_hw_sectors)) { max_hw_sectors =UINT_MAX ; + }Nit: this could be rewritten as:
Quoted 5 lines
if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9, &max_hw_sectors)) max_hw_sectors = UINT_MAX;More readable and no unneeded brackets. No ?
I'll just fix this up when applying the patch.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks,
applied to nvme-5.13.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme