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]
Message-Id: <20200502211056.20975-1-wu000273@umn.edu>
Date:   Sat,  2 May 2020 16:10:56 -0500
From:   wu000273@....edu
To:     sre@...nel.org
Cc:     linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
        kjlu@....edu, wu000273@....edu
Subject: [PATCH] power: supply: fix memory leaks

From: Qiushi Wu <wu000273@....edu>

In function power_supply_add_hwmon_sysfs(), psyhw->props is
allocated by bitmap_zalloc(). But this pointer is not deallocated
in several error paths, which lead to memory leak bugs. To fix
this, we can call bitmap_free() to free this pointer.

Signed-off-by: Qiushi Wu <wu000273@....edu>
---
 drivers/power/supply/power_supply_hwmon.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
index 75cf861ba492..7453390ab7a4 100644
--- a/drivers/power/supply/power_supply_hwmon.c
+++ b/drivers/power/supply/power_supply_hwmon.c
@@ -307,7 +307,7 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 	ret = devm_add_action(dev, power_supply_hwmon_bitmap_free,
 			      psyhw->props);
 	if (ret)
-		goto error;
+		goto out_free;
 
 	for (i = 0; i < desc->num_properties; i++) {
 		const enum power_supply_property prop = desc->properties[i];
@@ -342,7 +342,7 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 		new_name = devm_kstrdup(dev, name, GFP_KERNEL);
 		if (!new_name) {
 			ret = -ENOMEM;
-			goto error;
+			goto out_free;
 		}
 		strreplace(new_name, '-', '_');
 		name = new_name;
@@ -353,10 +353,12 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 						NULL);
 	ret = PTR_ERR_OR_ZERO(hwmon);
 	if (ret)
-		goto error;
+		goto out_free;
 
 	devres_close_group(dev, power_supply_add_hwmon_sysfs);
 	return 0;
+out_free:
+	bitmap_free(psyhw->props);
 error:
 	devres_release_group(dev, NULL);
 	return ret;
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ