linux/drivers/nvdimm
Ira Weiny a36cf13850 nvdimm/bus: Fix potential use after free in asynchronous initialization
commit a8aec14230 upstream.

Dingisoul with KASAN reports a use after free if device_add() fails in
nd_async_device_register().

Commit b6eae0f61d ("libnvdimm: Hold reference on parent while
scheduling async init") correctly added a reference on the parent device
to be held until asynchronous initialization was complete.  However, if
device_add() results in an allocation failure the ref count of the
device drops to 0 prior to the parent pointer being accessed.  Thus
resulting in use after free.

The bug bot AI correctly identified the fix.  Save a reference to the
parent pointer to be used to drop the parent reference regardless of the
outcome of device_add().

Reported-by: Dingisoul <dingiso.kernel@gmail.com>
Closes: http://lore.kernel.org/8855544b-be9e-4153-aa55-0bc328b13733@gmail.com
Fixes: b6eae0f61d ("libnvdimm: Hold reference on parent while scheduling async init")
Cc: stable@vger.kernel.org
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://patch.msgid.link/20260306-fix-uaf-async-init-v1-1-a28fd7526723@intel.com
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-04-18 10:33:17 +02:00
..
badrange.c mm/memremap_pages: convert to 'struct range' 2020-10-13 18:38:28 -07:00
blk.c nvdimm-blk: convert to blk_alloc_disk/blk_cleanup_disk 2021-06-01 07:42:23 -06:00
btt.c nvdimm/btt: do not call del_gendisk() if not needed 2021-11-18 19:17:06 +01:00
btt.h nvdimm-btt: convert to blk_alloc_disk/blk_cleanup_disk 2021-06-01 07:42:23 -06:00
btt_devs.c libnvdimm: Move attribute groups to device type 2019-11-17 09:17:38 -08:00
bus.c nvdimm/bus: Fix potential use after free in asynchronous initialization 2026-04-18 10:33:17 +02: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-06-09 10:23:08 +02:00
dax_devs.c nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 19:51:41 +01:00
dimm.c libnvdimm: Make remove callback return void 2021-02-16 19:35:29 -08:00
dimm_devs.c libnvdimm: Export nvdimm shutdown helper, nvdimm_delete() 2021-06-15 16:47:22 -07:00
e820.c libnvdimm/e820: Retrieve and populate correct 'target_node' info 2020-02-18 10:28:05 -08:00
Kconfig lib: Uplevel the pmem "region" ida to a global allocator 2019-11-07 15:44:29 +01:00
label.c libnvdimm/labels: Fix divide error in nd_label_data_init() 2025-06-04 14:37:55 +02:00
label.h libnvdimm/labels: Add claim class helpers 2021-08-24 12:08:28 -07:00
Makefile libnvdimm: Enable unit test infrastructure compile checks 2019-09-07 04:28:05 -03:00
namespace_devs.c cxl for v5.15 2021-09-09 11:48:27 -07:00
nd-core.h PM, libnvdimm: Add runtime firmware activation support 2020-07-28 19:28:32 -06:00
nd.h nvdimm: rectify the illogical code within nd_dax_probe() 2024-12-14 19:51:41 +01:00
nd_virtio.c nvdimm: virtio_pmem: serialize flush requests 2026-03-04 07:19:44 -05:00
of_pmem.c libnvdimm/of_pmem: Use devm_kstrdup instead of kstrdup and check its return value 2023-11-20 11:08:22 +01:00
pfn.h libnvdimm/namespace: Enforce memremap_compat_align() 2020-03-17 12:23:21 -07:00
pfn_devs.c mm/memremap_pages: support multiple ranges per invocation 2020-10-13 18:38:28 -07:00
pmem.c nvdimm/pmem: cleanup the disk if pmem_release_disk() is yet assigned 2021-11-18 19:17:07 +01:00
pmem.h libnvdimm, pmem: Restore page attributes when clearing errors 2018-08-20 09:22:45 -07:00
region.c libnvdimm: Make remove callback return void 2021-02-16 19:35:29 -08:00
region_devs.c nd_btt: Make BTT lanes preemptible 2023-11-20 11:08:22 +01:00
security.c nvdimm: Allow overwrite in the presence of disabled dimms 2022-06-09 10:23:08 +02:00
virtio_pmem.c nvdimm: virtio_pmem: serialize flush requests 2026-03-04 07:19:44 -05:00
virtio_pmem.h nvdimm: virtio_pmem: serialize flush requests 2026-03-04 07:19:44 -05:00