Skip to content

Commit

Permalink
nvme: fix handling of large MDTS values
Browse files Browse the repository at this point in the history
Instead of triggering an integer overflow and undefined behavior if MDTS is
large, set max_hw_sectors to UINT_MAX.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Keith Busch <kbusch@kernel.org>
[hch: rebased to account for the new nvme_mps_to_sectors helper]
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Bart Van Assche authored and Christoph Hellwig committed Apr 6, 2021
1 parent 5befc7c commit 8609c63
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3049,9 +3049,11 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,

static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units)
{
u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12;
u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val;

return 1 << (units + page_shift - 9);
if (check_shl_overflow(1U, units + page_shift - 9, &val))
return UINT_MAX;
return val;
}

static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
Expand Down

0 comments on commit 8609c63

Please sign in to comment.