lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20211018135428.3971329-1-wanghai38@huawei.com>
Date:   Mon, 18 Oct 2021 21:54:28 +0800
From:   Wang Hai <wanghai38@...wei.com>
To:     <maarten.lankhorst@...ux.intel.com>, <mripard@...nel.org>,
        <tzimmermann@...e.de>, <airlied@...ux.ie>, <daniel@...ll.ch>,
        <sam@...nborg.org>
CC:     <dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] drm: fix null-ptr-deref in drm_minor_alloc_release

I got a null-ptr-deref report:

BUG: kernel NULL pointer dereference, address: 0000000000000030
...
RIP: 0010:kobject_put+0x2a/0x180
...
Call Trace:
 put_device+0x25/0x30
 drm_minor_alloc_release.cold+0x45/0x7f [drm]
 drm_managed_release+0x158/0x2d0 [drm]
 drm_dev_init+0x3a7/0x4a0 [drm]
 __devm_drm_dev_alloc+0x55/0xd0 [drm]
 mi0283qt_probe+0x8a/0x2b5 [mi0283qt]
 spi_probe+0xeb/0x130
...
 entry_SYSCALL_64_after_hwframe+0x44/0xae

If drm_sysfs_minor_alloc() fails in drm_minor_alloc(), minor->kdev will
point to PTR_ERR(...) instead of NULL. This will result in null-ptr-deref
when put_device(minor->kdev) is called.

drm_dev_init()
	drm_minor_alloc()
		drm_sysfs_minor_alloc(); // fail, minor->kdev = PTR_ERR(...)
	drm_managed_release()
		drm_minor_alloc_release()
			put_device(minor->kdev); // access non-existent kdev

Define a temp variable and assign it to minor->kdev if the temp variable
is not PTR_ERR.

Fixes: f96306f9892b ("drm: manage drm_minor cleanup with drmm_")
Reported-by: Hulk Robot <hulkci@...wei.com>
Signed-off-by: Wang Hai <wanghai38@...wei.com>
---
 drivers/gpu/drm/drm_drv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index b3a1636d1b98..b302536edbce 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -112,6 +112,7 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
 {
 	struct drm_minor *minor;
 	unsigned long flags;
+	struct device *kdev;
 	int r;
 
 	minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL);
@@ -140,9 +141,11 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
 	if (r)
 		return r;
 
-	minor->kdev = drm_sysfs_minor_alloc(minor);
-	if (IS_ERR(minor->kdev))
-		return PTR_ERR(minor->kdev);
+	kdev = drm_sysfs_minor_alloc(minor);
+	if (IS_ERR(kdev))
+		return PTR_ERR(kdev);
+
+	minor->kdev = kdev;
 
 	*drm_minor_get_slot(dev, type) = minor;
 	return 0;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ