From nobody Mon Apr 13 10:54:18 2026 Received: from mail115-79.sinamail.sina.com.cn (mail115-79.sinamail.sina.com.cn [218.30.115.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D3EC2165EA for ; Mon, 13 Apr 2026 01:33:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.79 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776044024; cv=none; b=qSTRF8u9ZPim8CmrgWm/5KsZnGltqqUjZEmhKdX0Ozz5GXFHP85Td/SmqRkBSJhYmUJzshJLrAs16Xuq+zEp+zzMWMyNr0FjArXdZjfXM7U3k68Su9jJTRdxZaJKIwmkvir4m7eGLaWrPep5lyJt2nBPQOb4YE8/OtNG8Nj0EiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776044024; c=relaxed/simple; bh=fg8f6Jjir04dYy1MUu5cm/qWNdaGJEtBqGRWLfrK//U=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=j6IEhU2zkN+RFeAjZDp290LdJ767hjp3lAXri8pdKlD2y7v0wa1/mlsdmcFqoIjwpwu+xrcrkFwGPZ477w2EOId+GfqP8spKVvYGgAbAdct1qNXTYJACmw0oj0qn0D0lOzQQvDdbIJVZ2tpz0WIA5jOVzZ/RRqOHsQYpU5oJPPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.cn; spf=pass smtp.mailfrom=sina.cn; dkim=pass (1024-bit key) header.d=sina.cn header.i=@sina.cn header.b=gPVQIzPA; arc=none smtp.client-ip=218.30.115.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=sina.cn header.i=@sina.cn header.b="gPVQIzPA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sina.cn; s=201208; t=1776044022; bh=5AiOv3OmSV1vAgdRKipxBvh8ToeMYXa8wksWt6WBwek=; h=From:Subject:Date:Message-Id; b=gPVQIzPA5JJzPt0XckjY1FnpSYokhAFbLc/zQXAqir3G9b4Nhhx0DXgkzWxIbQ6Nn zPa1M4de9wZNbgLO3BjCkW7i5W43cAe1q6U95xVEmuBzidCZSn6Lnua5qGnonQxGZU RjR9j+cVbJ33kAzRGkVNy8lHR1wfJHEcm/yVIO+U= X-SMAIL-HELO: NTT-kernel-dev Received: from unknown (HELO NTT-kernel-dev)([60.247.85.88]) by sina.cn (10.185.250.22) with ESMTP id 69DC47E900000EAA; Mon, 13 Apr 2026 09:33:31 +0800 (CST) X-Sender: jianqkang@sina.cn X-Auth-ID: jianqkang@sina.cn Authentication-Results: sina.cn; spf=none smtp.mailfrom=jianqkang@sina.cn; dkim=none header.i=none; dmarc=none action=none header.from=jianqkang@sina.cn X-SMAIL-MID: 2821247602310 X-SMAIL-UIID: EF915E9DFECA41D78B31B4BD59713C7D-20260413-093331-1 From: Jianqiang kang To: gregkh@linuxfoundation.org, stable@vger.kernel.org, ira.weiny@intel.com Cc: patches@lists.linux.dev, linux-kernel@vger.kernel.org, dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, alexander.h.duyck@linux.intel.com, linux-nvdimm@lists.01.org, dingiso.kernel@gmail.com Subject: [PATCH 5.10.y] nvdimm/bus: Fix potential use after free in asynchronous initialization Date: Mon, 13 Apr 2026 09:33:29 +0800 Message-Id: <20260413013329.837358-1-jianqkang@sina.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ira Weiny [ Upstream commit a8aec14230322ed8f1e8042b6d656c1631d41163 ] Dingisoul with KASAN reports a use after free if device_add() fails in nd_async_device_register(). Commit b6eae0f61db2 ("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 Closes: http://lore.kernel.org/8855544b-be9e-4153-aa55-0bc328b13733@gmail.c= om Fixes: b6eae0f61db2 ("libnvdimm: Hold reference on parent while scheduling = async init") Cc: stable@vger.kernel.org Reviewed-by: Dave Jiang Link: https://patch.msgid.link/20260306-fix-uaf-async-init-v1-1-a28fd752672= 3@intel.com Signed-off-by: Ira Weiny Signed-off-by: Jianqiang kang --- drivers/nvdimm/bus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 9ec59960f216..1aacc40ad09f 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c @@ -502,14 +502,15 @@ EXPORT_SYMBOL_GPL(nd_synchronize); static void nd_async_device_register(void *d, async_cookie_t cookie) { struct device *dev =3D d; + struct device *parent =3D dev->parent; =20 if (device_add(dev) !=3D 0) { dev_err(dev, "%s: failed\n", __func__); put_device(dev); } put_device(dev); - if (dev->parent) - put_device(dev->parent); + if (parent) + put_device(parent); } =20 static void nd_async_device_unregister(void *d, async_cookie_t cookie) --=20 2.34.1