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>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 27 Sep 2007 09:33:12 +0200
From:	Mariusz Kozlowski <m.kozlowski@...land.pl>
To:	jkosina@...e.cz
Cc:	linux-input@...ey.karlin.mff.cuni.cz, linux-kernel@...r.kernel.org
Subject: [PATCH] hid: hidraw_connect memleak fix

It looks like hidraw_connect() is leaking memory in case of failure.
Also it should return -ENOMEM when kzalloc fails.

Signed-off-by: Mariusz Kozlowski <m.kozlowski@...land.pl>

 drivers/hid/hidraw.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

--- linux-2.6.23-rc8-mm1-a/drivers/hid/hidraw.c	2007-09-26 12:07:37.000000000 +0200
+++ linux-2.6.23-rc8-mm1-b/drivers/hid/hidraw.c	2007-09-26 14:36:08.000000000 +0200
@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(hidraw_report_event);

 int hidraw_connect(struct hid_device *hid)
 {
-	int minor, result = -EINVAL;
+	int minor, result;
 	struct hidraw *dev;

 	/* TODO currently we accept any HID device. This should later
@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hi
 	 * non-input applications
 	 */

-	if (!(dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL)))
-		return -1;
+	dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	result = -EINVAL;

 	spin_lock(&minors_lock);

@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hi

 	spin_unlock(&minors_lock);

-	if (result)
+	if (result) {
+		kfree(dev);
 		goto out;
+	}

 	dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
 				"%s%d", "hidraw", minor);
@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hi
 		hidraw_table[minor] = NULL;
 		spin_unlock(&minors_lock);
 		result = PTR_ERR(dev->dev);
+		kfree(dev);
 		goto out;
 	}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ