Skip to content

Commit f92a2fe

Browse files
toshikanigregkh
authored andcommitted
libnvdimm, pmem: fix a NULL pointer BUG in nd_pmem_notify
commit b2518c7 upstream. The following BUG was observed when nd_pmem_notify() was called for a BTT device. The use of a pmem_device pointer is not valid with BTT. BUG: unable to handle kernel NULL pointer dereference at 0000000000000030 IP: nd_pmem_notify+0x30/0xf0 [nd_pmem] Call Trace: nd_device_notify+0x40/0x50 child_notify+0x10/0x20 device_for_each_child+0x50/0x90 nd_region_notify+0x20/0x30 nd_device_notify+0x40/0x50 nvdimm_region_notify+0x27/0x30 acpi_nfit_scrub+0x341/0x590 [nfit] process_one_work+0x197/0x450 worker_thread+0x4e/0x4a0 kthread+0x109/0x140 Fix nd_pmem_notify() by setting nd_region and badblocks pointers properly for BTT. Cc: Vishal Verma <[email protected]> Fixes: 7199946 ("libnvdimm: async notification support") Signed-off-by: Toshi Kani <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 72393c0 commit f92a2fe

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

drivers/nvdimm/pmem.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,12 @@ static void nd_pmem_shutdown(struct device *dev)
388388

389389
static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
390390
{
391-
struct pmem_device *pmem = dev_get_drvdata(dev);
392-
struct nd_region *nd_region = to_region(pmem);
391+
struct nd_region *nd_region;
393392
resource_size_t offset = 0, end_trunc = 0;
394393
struct nd_namespace_common *ndns;
395394
struct nd_namespace_io *nsio;
396395
struct resource res;
396+
struct badblocks *bb;
397397

398398
if (event != NVDIMM_REVALIDATE_POISON)
399399
return;
@@ -402,20 +402,33 @@ static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
402402
struct nd_btt *nd_btt = to_nd_btt(dev);
403403

404404
ndns = nd_btt->ndns;
405-
} else if (is_nd_pfn(dev)) {
406-
struct nd_pfn *nd_pfn = to_nd_pfn(dev);
407-
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
405+
nd_region = to_nd_region(ndns->dev.parent);
406+
nsio = to_nd_namespace_io(&ndns->dev);
407+
bb = &nsio->bb;
408+
} else {
409+
struct pmem_device *pmem = dev_get_drvdata(dev);
408410

409-
ndns = nd_pfn->ndns;
410-
offset = pmem->data_offset + __le32_to_cpu(pfn_sb->start_pad);
411-
end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
412-
} else
413-
ndns = to_ndns(dev);
411+
nd_region = to_region(pmem);
412+
bb = &pmem->bb;
413+
414+
if (is_nd_pfn(dev)) {
415+
struct nd_pfn *nd_pfn = to_nd_pfn(dev);
416+
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
417+
418+
ndns = nd_pfn->ndns;
419+
offset = pmem->data_offset +
420+
__le32_to_cpu(pfn_sb->start_pad);
421+
end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
422+
} else {
423+
ndns = to_ndns(dev);
424+
}
425+
426+
nsio = to_nd_namespace_io(&ndns->dev);
427+
}
414428

415-
nsio = to_nd_namespace_io(&ndns->dev);
416429
res.start = nsio->res.start + offset;
417430
res.end = nsio->res.end - end_trunc;
418-
nvdimm_badblocks_populate(nd_region, &pmem->bb, &res);
431+
nvdimm_badblocks_populate(nd_region, bb, &res);
419432
}
420433

421434
MODULE_ALIAS("pmem");

0 commit comments

Comments
 (0)