linux/drivers/nvdimm
Robert Richter db1aef51b8 libnvdimm/labels: Fix divide error in nd_label_data_init()
[ Upstream commit ef1d3455bb ]

If a faulty CXL memory device returns a broken zero LSA size in its
memory device information (Identify Memory Device (Opcode 4000h), CXL
spec. 3.1, 8.2.9.9.1.1), a divide error occurs in the libnvdimm
driver:

 Oops: divide error: 0000 [#1] PREEMPT SMP NOPTI
 RIP: 0010:nd_label_data_init+0x10e/0x800 [libnvdimm]

Code and flow:

1) CXL Command 4000h returns LSA size = 0
2) config_size is assigned to zero LSA size (CXL pmem driver):

drivers/cxl/pmem.c:             .config_size = mds->lsa_size,

3) max_xfer is set to zero (nvdimm driver):

drivers/nvdimm/label.c: max_xfer = min_t(size_t, ndd->nsarea.max_xfer, config_size);

4) A subsequent DIV_ROUND_UP() causes a division by zero:

drivers/nvdimm/label.c: /* Make our initial read size a multiple of max_xfer size */
drivers/nvdimm/label.c: read_size = min(DIV_ROUND_UP(read_size, max_xfer) * max_xfer,
drivers/nvdimm/label.c-                 config_size);

Fix this by checking the config size parameter by extending an
existing check.

Signed-off-by: Robert Richter <rrichter@amd.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Link: https://patch.msgid.link/20250320112223.608320-1-rrichter@amd.com
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-06-04 14:40:04 +02:00
..
badrange.c mm/memremap_pages: convert to 'struct range' 2020-10-13 18:38:28 -07:00
btt.c nvdimm-btt: Use the enum req_op type 2022-07-14 12:14:31 -06:00
btt.h nvdimm-btt: convert to blk_alloc_disk/blk_cleanup_disk 2021-06-01 07:42:23 -06:00
btt_devs.c nvdimm: Drop nd_device_lock() 2022-04-28 14:01:55 -07:00
bus.c cxl/pmem: Fix nvdimm registration races 2023-03-10 09:34:20 +01:00
claim.c libnvdimm: Cleanup include of badblocks.h 2020-12-15 21:47:45 -08:00
core.c nvdimm: Fix firmware activation deadlock scenarios 2022-04-28 14:01:56 -07:00
dax_devs.c nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 19:54:47 +01:00
dimm.c libnvdimm: Make remove callback return void 2021-02-16 19:35:29 -08:00
dimm_devs.c cxl/pmem: Fix nvdimm registration races 2023-03-10 09:34:20 +01:00
e820.c libnvdimm/e820: Retrieve and populate correct 'target_node' info 2020-02-18 10:28:05 -08:00
Kconfig nvdimm: Support sizeof(struct page) > MAX_STRUCT_PAGE_SIZE 2023-02-14 19:11:53 +01:00
label.c libnvdimm/labels: Fix divide error in nd_label_data_init() 2025-06-04 14:40:04 +02:00
label.h nvdimm/region: Delete nd_blk_region infrastructure 2022-03-11 15:53:13 -08:00
Makefile drivers/nvdimm: Fix build failure when CONFIG_PERF_EVENTS is not set 2022-03-23 12:17:36 -07:00
namespace_devs.c nvdimm: Fix devs leaks in scan_labels() 2024-10-17 15:21:04 +02:00
nd-core.h cxl/pmem: Fix nvdimm registration races 2023-03-10 09:34:20 +01:00
nd.h nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 19:54:47 +01:00
nd_perf.c nvdimm: Fix dereference after free in register_nvdimm_pmu() 2023-09-13 09:42:47 +02:00
nd_virtio.c virtio_pmem: Check device status before requesting flush 2024-10-17 15:22:16 +02:00
of_pmem.c libnvdimm/of_pmem: Use devm_kstrdup instead of kstrdup and check its return value 2023-11-20 11:52:05 +01:00
pfn.h libnvdimm/namespace: Enforce memremap_compat_align() 2020-03-17 12:23:21 -07:00
pfn_devs.c nvdimm: Support sizeof(struct page) > MAX_STRUCT_PAGE_SIZE 2023-02-14 19:11:53 +01:00
pmem.c Merge branch 'for-6.0/dax' into libnvdimm-fixes 2022-09-24 18:14:12 -07:00
pmem.h dax: introduce DAX_RECOVERY_WRITE dax access mode 2022-05-16 13:35:56 -07:00
region.c nvdimm: Drop nd_device_lock() 2022-04-28 14:01:55 -07:00
region_devs.c nd_btt: Make BTT lanes preemptible 2023-11-20 11:52:05 +01:00
security.c nvdimm: make __nvdimm_security_overwrite_query static 2022-09-20 10:23:52 -07:00
virtio_pmem.c virtio_pmem: set device ready in probe() 2022-08-11 04:06:37 -04:00
virtio_pmem.h virtio-pmem: Add virtio pmem driver 2019-07-05 15:19:10 -07:00