nvme: Fix u32 overflow in the number of namespace list calculation
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 nvme: Fix u32 overflow in the number of namespace list calculation
The Number of Namespaces (nn) field in the identify controller data structure is defined as u32 and the maximum allowed value in NVMe specification is 0xFFFFFFFEUL. This change fixes the possible overflow of the DIV_ROUND_UP() operation used in nvme_scan_ns_list() by casting the nn to u64.
---
Changes in v2:
- use DIV_ROUND_UP_ULL for 32-bit system
drivers/nvme/host/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +0 -0
@@ -3373,7 +3373,8 @@ static int nvme_scan_ns_list(struct nvme_ctrl
*ctrl, unsigned nn)
{
struct nvme_ns *ns;
__le32 *ns_list;
- unsigned i, j, nsid, prev = 0, num_lists = DIV_ROUND_UP(nn, 1024);
+ unsigned i, j, nsid, prev = 0;
+ unsigned num_lists = DIV_ROUND_UP_ULL((u64)nn, 1024);
int ret = 0;
ns_list = kzalloc(NVME_IDENTIFY_DATA_SIZE, GFP_KERNEL);--
2.7.4
Christoph Hellwig
maintainerPATCH v2 1/1 nvme: Fix u32 overflow in the number of namespace list calculation
Quoted 6 lines · Jaesoo Lee
The Number of Namespaces (nn) field in the identify controller data structure is defined as u32 and the maximum allowed value in NVMe specification is
0xFFFFFFFEUL. This change fixes the possible overflow of theDIV_ROUND_UP()operation used innvme_scan_ns_list()by casting the nn to u64.Signed-off-by Jaesoo Lee <jalee at purestorage.com>
Looks good,
PATCH v2 1/1 nvme: Fix u32 overflow in the number of namespace list calculation
In reply to Jaesoo LeeApplied to 5.2-rc-next with a slight conflict resolution.
Please verify that the patch is fine by you:
http://git.infradead.org/nvme.git/commitdiff/e6c9417f9eeec4587bce5a861cfcda0f02b39464?hp=c8b0ec95a45dfda1360a58458456ded45a42a83e
PATCH v2 1/1 nvme: Fix u32 overflow in the number of namespace list calculation
The patch looks good to me.
Thanks.
Quoted 5 lines · Sagi Grimberg
Applied to 5.2-rc-next with a slight conflict resolution.
Please verify that the patch is fine by you:
http://git.infradead.org/nvme.git/commitdiff/e6c9417f9eeec4587bce5a861cfcda0f02b39464?hp=c8b0ec95a45dfda1360a58458456ded45a42a83e