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:	Fri,  2 Aug 2013 23:43:50 +0200
From:	Andreas Platschek <andi.platschek@...il.com>
To:	gregkh@...uxfoundation.org
Cc:	linux-kernel@...r.kernel.org,
	Andreas Platschek <andi.platschek@...il.com>
Subject: [PATCH] driver-core: only call kfree() if memory was allocated

There are several cases where we could bail out of show_uevent()
before kzalloc() is even called. In those cases we don't want to
call kfree().

In addition the error handling of kzalloc() is now using the
single point of exit as well.

Signed-off-by: Andreas Platschek <andi.platschek@...il.com>
---
 drivers/base/core.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8856d74..bf4effb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -372,8 +372,10 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
 			goto out;
 
 	env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
-	if (!env)
-		return -ENOMEM;
+	if (!env) {
+		count = -ENOMEM;
+		goto out;
+	}
 
 	/* let the kset specific function add its keys */
 	retval = kset->uevent_ops->uevent(kset, &dev->kobj, env);
@@ -383,8 +385,9 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
 	/* copy keys to file */
 	for (i = 0; i < env->envp_idx; i++)
 		count += sprintf(&buf[count], "%s\n", env->envp[i]);
-out:
+out_free:
 	kfree(env);
+out:
 	return count;
 }
 
-- 
1.7.10.4

--
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