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: <20220120111356.8052-1-linmq006@gmail.com>
Date:   Thu, 20 Jan 2022 11:13:54 +0000
From:   Miaoqian Lin <linmq006@...il.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Miaoqian Lin <linmq006@...il.com>, linux-kernel@...r.kernel.org
Subject: [PATCH] edd: Fix memory leak in edd_init

edd_init calls edd_device_register(), which calls kobject_init_and_add()
and propagates the error code to the caller.
And kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix the error handling by adding kobject_put().
And callback function edd_release() in kobject_put()
calls kfree(dev). So remove the redundant kfree(dev);

Signed-off-by: Miaoqian Lin <linmq006@...il.com>
---
 drivers/firmware/edd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 69353dd0ea22..1135e66f92bc 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -748,8 +748,8 @@ edd_init(void)
 		}
 
 		rc = edd_device_register(edev, i);
-		if (rc) {
-			kfree(edev);
+		if (rc < 0) {
+			kobject_put(&edev->kobj);
 			goto out;
 		}
 		edd_devices[i] = edev;
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ