Skip to content
/ linux Public

Commit a226e5b

Browse files
weiny2gregkh
authored andcommitted
nvdimm/bus: Fix potential use after free in asynchronous initialization
commit a8aec14 upstream. Dingisoul with KASAN reports a use after free if device_add() fails in nd_async_device_register(). Commit b6eae0f ("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: b6eae0f ("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>
1 parent be5c359 commit a226e5b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/nvdimm/bus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,15 @@ EXPORT_SYMBOL_GPL(nd_synchronize);
486486
static void nd_async_device_register(void *d, async_cookie_t cookie)
487487
{
488488
struct device *dev = d;
489+
struct device *parent = dev->parent;
489490

490491
if (device_add(dev) != 0) {
491492
dev_err(dev, "%s: failed\n", __func__);
492493
put_device(dev);
493494
}
494495
put_device(dev);
495-
if (dev->parent)
496-
put_device(dev->parent);
496+
if (parent)
497+
put_device(parent);
497498
}
498499

499500
static void nd_async_device_unregister(void *d, async_cookie_t cookie)

0 commit comments

Comments
 (0)