nvme: Fix handling of large MDTS values
PATCH v2 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 v1: removed a dev_err() call.
drivers/nvme/host/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +4 -3
@@ -3123,10 +3123,11 @@ 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 + max_hw_sectors =UINT_MAX ; +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
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 17 lines · Bart Van Assche
Instead of triggering an integer overflow and undefined behavior if MDTS is large, set
max_hw_sectorstoUINT_MAX.Signed-off-by Bart Van Assche <[email protected]>---
Changes compared to v1: removed a
dev_err()call.drivers/nvme/host/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +0
-0@@ -3123,10 +3123,11 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 3130
Quoted 10 lines
drivers/nvme/host/core.c +4
-3atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; -if (id->mdts) - max_hw_sectors =1 << (id->mdts + page_shift -9 ); -else + max_hw_sectors =UINT_MAX ; +if (id->mdts &&check_shl_overflow (1U , id->mdts + page_shift -9 , + &max_hw_sectors)) { max_hw_sectors =UINT_MAX ; + }
The condition can be rearranged so that max_hw_sectors is set to UINT_MAX just once:
if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9,
&max_hw_sectors)) {
max_hw_sectors = UINT_MAX;
}drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 3133
Quoted 3 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
Quoted 21 lines · Keith Busch
Quoted 6 lines · Bart Van Assche
drivers/nvme/host/core.c +0
-0@@ -3123,10 +3123,11 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 3130
Quoted 10 lines
drivers/nvme/host/core.c +4
-3atomic_set (&ctrl->abort_limit, id->acl +1 ); ctrl->vwc = id->vwc; -if (id->mdts) - max_hw_sectors =1 << (id->mdts + page_shift -9 ); -else + max_hw_sectors =UINT_MAX ; +if (id->mdts &&check_shl_overflow (1U , id->mdts + page_shift -9 , + &max_hw_sectors)) { max_hw_sectors =UINT_MAX ; + }The condition can be rearranged so that
max_hw_sectorsis set toUINT_MAXjust once:
Quoted 4 lines
if (!id->mdts || check_shl_overflow(1U, id->mdts + page_shift - 9,
&max_hw_sectors)) {
max_hw_sectors = UINT_MAX;
}Hi Keith,
That's an interesting suggestion. I will integrate this change in my patch and repost it.
Thanks,
Bart.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme