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:   Wed,  2 Mar 2022 00:36:51 +0800
From:   cz18811105578@...il.com
To:     jpoimboe@...hat.com, peterz@...radead.org, mingo@...nel.org,
        bp@...e.de
Cc:     linux-kernel@...r.kernel.org, Zong Cao <cz18811105578@...il.com>
Subject: [PATCH] objtool: Fix memory leak in objtool_create_backup

From: Zong Cao <cz18811105578@...il.com>

The error handling branch did not properly free the memory before
return, which would cause memory leak.

Fixes: 8ad15c690084 ("objtool: Add --backup")
Signed-off-by: Zong Cao <cz18811105578@...il.com>
---
 tools/objtool/objtool.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index bdf699f6552b..1f4734c84382 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -62,19 +62,19 @@ static bool objtool_create_backup(const char *_objname)
 	d = open(name, O_CREAT|O_WRONLY|O_TRUNC, 0644);
 	if (d < 0) {
 		perror("failed to create backup file");
-		return false;
+		goto free_name;
 	}
 
 	s = open(_objname, O_RDONLY);
 	if (s < 0) {
 		perror("failed to open orig file");
-		return false;
+		goto close_d;
 	}
 
 	buf = malloc(4096);
 	if (!buf) {
 		perror("failed backup data malloc");
-		return false;
+		goto close_s;
 	}
 
 	while ((l = read(s, buf, 4096)) > 0) {
@@ -83,7 +83,7 @@ static bool objtool_create_backup(const char *_objname)
 			t = write(d, base, l);
 			if (t < 0) {
 				perror("failed backup write");
-				return false;
+				goto free_buf;
 			}
 			base += t;
 			l -= t;
@@ -92,7 +92,7 @@ static bool objtool_create_backup(const char *_objname)
 
 	if (l < 0) {
 		perror("failed backup read");
-		return false;
+		goto free_buf;
 	}
 
 	free(name);
@@ -101,6 +101,17 @@ static bool objtool_create_backup(const char *_objname)
 	close(s);
 
 	return true;
+
+free_buf:
+	free(buf);
+close_s:
+	close(s);
+close_d:
+	close(d);
+free_name:
+	free(name);
+	return false;
+
 }
 
 struct objtool_file *objtool_open_read(const char *_objname)
-- 
2.30.1 (Apple Git-130)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ