Skip to content

Commit f59b701

Browse files
AlisonSchofieldweiny2
authored andcommitted
tools/testing/nvdimm: Use per-DIMM device handle
KASAN reports a global-out-of-bounds access when running these nfit tests: clear.sh, pmem-errors.sh, pfn-meta-errors.sh, btt-errors.sh, daxdev-errors.sh, and inject-error.sh. [] BUG: KASAN: global-out-of-bounds in nfit_test_ctl+0x769f/0x7840 [nfit_test] [] Read of size 4 at addr ffffffffc03ea01c by task ndctl/1215 [] The buggy address belongs to the variable: [] handle+0x1c/0x1df4 [nfit_test] nfit_test_search_spa() uses handle[nvdimm->id] to retrieve a device handle and triggers a KASAN error when it reads past the end of the handle array. It should not be indexing the handle array at all. The correct device handle is stored in per-DIMM test data. Each DIMM has a struct nfit_mem that embeds a struct acpi_nfit_memdev that describes the NFIT device handle. Use that device handle here. Fixes: 10246dc ("acpi nfit: nfit_test supports translate SPA") Cc: stable@vger.kernel.org Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com>> --- Link: https://patch.msgid.link/20251031234227.1303113-1-alison.schofield@intel.com Signed-off-by: Ira Weiny <ira.weiny@intel.com>
1 parent 43bc0aa commit f59b701

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • tools/testing/nvdimm/test

tools/testing/nvdimm/test/nfit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ static int nfit_test_search_spa(struct nvdimm_bus *bus,
670670
.addr = spa->spa,
671671
.region = NULL,
672672
};
673+
struct nfit_mem *nfit_mem;
673674
u64 dpa;
674675

675676
ret = device_for_each_child(&bus->dev, &ctx,
@@ -687,8 +688,12 @@ static int nfit_test_search_spa(struct nvdimm_bus *bus,
687688
*/
688689
nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1];
689690
nvdimm = nd_mapping->nvdimm;
691+
nfit_mem = nvdimm_provider_data(nvdimm);
692+
if (!nfit_mem)
693+
return -EINVAL;
690694

691-
spa->devices[0].nfit_device_handle = handle[nvdimm->id];
695+
spa->devices[0].nfit_device_handle =
696+
__to_nfit_memdev(nfit_mem)->device_handle;
692697
spa->num_nvdimms = 1;
693698
spa->devices[0].dpa = dpa;
694699

0 commit comments

Comments
 (0)