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: <20210413204511.GA664936@LEGION>
Date:   Wed, 14 Apr 2021 01:45:11 +0500
From:   Muhammad Usama Anjum <musamaanjum@...il.com>
To:     Josh Poimboeuf <jpoimboe@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...nel.org>,
        Miroslav Benes <mbenes@...e.cz>, Borislav Petkov <bp@...e.de>,
        open list <linux-kernel@...r.kernel.org>
Cc:     musamaanjum@...il.com, kernel-janitors@...r.kernel.org,
        dan.carpenter@...cle.com, colin.king@...onical.com
Subject: [PATCH] objtool: prevent memory leak in error paths

Memory allocated by sym and sym->name isn't being freed if some error
occurs in elf_create_undef_symbol(). Free the sym and sym->name if error
is detected before returning NULL.

Addresses-Coverity: ("Prevent memory leak")
Fixes: 2f2f7e47f052 ("objtool: Add elf_create_undef_symbol()")
Signed-off-by: Muhammad Usama Anjum <musamaanjum@...il.com>
---
Only build has been tested.

tools/objtool/elf.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index d08f5f3670f8..17ee265a6c6b 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -733,7 +733,7 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
 
 	sym->sym.st_name = elf_add_string(elf, NULL, sym->name);
 	if (sym->sym.st_name == -1)
-		return NULL;
+		goto err;
 
 	sym->sym.st_info = GELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
 	// st_other 0
@@ -744,19 +744,19 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
 	symtab = find_section_by_name(elf, ".symtab");
 	if (!symtab) {
 		WARN("can't find .symtab");
-		return NULL;
+		goto err;
 	}
 
 	s = elf_getscn(elf->elf, symtab->idx);
 	if (!s) {
 		WARN_ELF("elf_getscn");
-		return NULL;
+		goto err;
 	}
 
 	data = elf_newdata(s);
 	if (!data) {
 		WARN_ELF("elf_newdata");
-		return NULL;
+		goto err;
 	}
 
 	data->d_buf = &sym->sym;
@@ -773,6 +773,10 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
 	elf_add_symbol(elf, sym);
 
 	return sym;
+err:
+	free(sym->name);
+	free(sym);
+	return NULL;
 }
 
 struct section *elf_create_section(struct elf *elf, const char *name,
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ