linux-yocto/drivers/nvdimm
Robert Richter 1d1e1efad1 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>
2025-05-29 11:02:09 +02:00
..
badrange.c libnvdimm: remove kernel-doc warnings: 2023-10-18 09:48:05 -07:00
btt_devs.c nvdimm: Remove usage of the deprecated ida_simple_xx() API 2024-01-03 12:21:36 -08:00
btt.c 6.11 updates for libnvdimm 2024-07-20 11:26:02 -07:00
btt.h
bus.c driver core: have match() callback in struct bus_type take a const * 2024-07-03 15:16:54 +02:00
claim.c
core.c nvdimm: add missing MODULE_DESCRIPTION() macros 2024-06-17 18:41:48 -05:00
dax_devs.c nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 20:04:02 +01:00
dimm_devs.c nvdimm/dimm_devs: fix kernel-doc for function params 2024-01-03 12:21:36 -08:00
dimm.c
e820.c Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
Kconfig libnvdimm: Fix ACPI_NFIT in BLK_DEV_PMEM help 2024-02-12 14:32:25 -07:00
label.c libnvdimm/labels: Fix divide error in nd_label_data_init() 2025-05-29 11:02:09 +02:00
label.h
Makefile
namespace_devs.c nvdimm: Remove dead code for ENODEV checking in scan_labels() 2024-08-21 16:06:43 -05:00
nd_perf.c
nd_virtio.c virtio_pmem: Check device status before requesting flush 2024-09-10 02:51:47 -04:00
nd-core.h
nd.h nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 20:04:02 +01:00
of_pmem.c nvdimm: Use of_property_present() and of_property_read_bool() 2024-08-21 16:06:43 -05:00
pfn_devs.c nvdimm: Remove usage of the deprecated ida_simple_xx() API 2024-01-03 12:21:36 -08:00
pfn.h
pmem.c nvdimm/pmem: Set dax flag for all 'PFN_MAP' cases 2024-08-09 14:29:58 -05:00
pmem.h
region_devs.c libnvdimm: Annotate struct nd_region with __counted_by 2023-09-27 10:33:47 -07:00
region.c
security.c
virtio_pmem.c nvdimm: virtio_pmem: drop owner assignment 2024-05-22 08:31:18 -04:00
virtio_pmem.h