public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhang Yanfei <zhangyanfei.yes@gmail.com>
To: Simon Horman <horms@verge.net.au>
Cc: "kexec@lists.infradead.org" <kexec@lists.infradead.org>
Subject: [PATCH 13/13] kexec: x86_64: elf: fix possible memory leak in elf_x86_64_load
Date: Mon, 25 Mar 2013 23:18:19 +0800	[thread overview]
Message-ID: <51506ABB.2030808@gmail.com> (raw)
In-Reply-To: <51506758.4070902@gmail.com>

From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

In elf_x86_64_load, allocated memory may not be free'd if the code
exits abnormally, by calling die() or return. So the patch fixes
the possible memory leak.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/x86_64/kexec-elf-x86_64.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/kexec/arch/x86_64/kexec-elf-x86_64.c b/kexec/arch/x86_64/kexec-elf-x86_64.c
index 4a41780..7944be4 100644
--- a/kexec/arch/x86_64/kexec-elf-x86_64.c
+++ b/kexec/arch/x86_64/kexec-elf-x86_64.c
@@ -98,6 +98,8 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 #define ARG_STYLE_LINUX 1
 #define ARG_STYLE_NONE  2
 	int opt;
+	int result = 0;
+	char *error_msg = NULL;
 
 	/* See options.h and add any new options there too! */
 	static const struct option options[] = {
@@ -208,7 +210,8 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 		elf_rel_set_symbol(&info->rhdr, "entry64_regs", &regs, sizeof(regs));
 
 		if (ramdisk) {
-			die("Ramdisks not supported with generic elf arguments");
+			error_msg = "Ramdisks not supported with generic elf arguments";
+			goto out;
 		}
 	}
 	else if (arg_style == ARG_STYLE_LINUX) {
@@ -240,8 +243,10 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 		if (info->kexec_flags & KEXEC_ON_CRASH) {
 			rc = load_crashdump_segments(info, modified_cmdline,
 							max_addr, 0);
-			if (rc < 0)
-				return -1;
+			if (rc < 0) {
+				result = -1;
+				goto out;
+			}
 			/* Use new command line. */
 			free(command_line);
 			command_line = modified_cmdline;
@@ -267,10 +272,13 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 		elf_rel_set_symbol(&info->rhdr, "entry64_regs", &regs, sizeof(regs));
 	}
 	else {
-		die("Unknown argument style\n");
+		error_msg = "Unknown argument style\n";
 	}
 
+out:
 	free(command_line);
 	free(modified_cmdline);
-	return 0;
+	if (error_msg)
+		die(error_msg);
+	return result;
 }
-- 
1.7.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2013-03-25 15:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-25 15:03 [PATCH 01/13] kexec: fix possible memory leak in check_reuse_initrd Zhang Yanfei
2013-03-25 15:05 ` [PATCH 02/13] kexec: i386: bzImage: fix memory leak caused by get_command_line Zhang Yanfei
2013-03-27 12:36   ` Simon Horman
2013-03-25 15:07 ` [PATCH 03/13] kexec: i386: elf: fix possible memory leak in elf_x86_load Zhang Yanfei
2013-03-25 15:09   ` [PATCH 04/13] kexec: i386: elf: fix memory leak caused by get_command_line Zhang Yanfei
2013-03-27 12:37     ` Simon Horman
2013-03-27 12:36   ` [PATCH 03/13] kexec: i386: elf: fix possible memory leak in elf_x86_load Simon Horman
2013-03-25 15:10 ` [PATCH 05/13] kexec: i386: multiboot: fix possible memory leak in multiboot_x86_load Zhang Yanfei
2013-03-27 12:38   ` Simon Horman
2013-03-25 15:11 ` [PATCH 06/13] kexec: i386: multiboot: fix memory leak caused by get_command_line Zhang Yanfei
2013-03-27 12:38   ` Simon Horman
2013-03-25 15:12 ` [PATCH 07/13] kexec: ppc: elf: fix possible memory leak in elf_ppc_load Zhang Yanfei
2013-03-27 12:40   ` Simon Horman
2013-03-25 15:13 ` [PATCH 08/13] kexec: ppc: elf: fix memory leak caused by get_command_line Zhang Yanfei
2013-03-27 12:40   ` Simon Horman
2013-03-25 15:15 ` [PATCH 09/13] kexec: ppc: uImage: fix possible memory leak in ppc_load_bare_bits Zhang Yanfei
2013-03-27 12:41   ` Simon Horman
2013-03-25 15:15 ` [PATCH 10/13] kexec: ppc: uImage: fix memory leak caused by get_command_line Zhang Yanfei
2013-03-27 12:41   ` Simon Horman
2013-03-25 15:16 ` [PATCH 11/13] kexec: x86_64: bzImage64: " Zhang Yanfei
2013-03-27 12:41   ` Simon Horman
2013-03-25 15:17 ` [PATCH 12/13] kexec: x86_64: elf: " Zhang Yanfei
2013-03-27 12:42   ` Simon Horman
2013-03-25 15:18 ` Zhang Yanfei [this message]
2013-03-27 12:42   ` [PATCH 13/13] kexec: x86_64: elf: fix possible memory leak in elf_x86_64_load Simon Horman
2013-03-27 12:35 ` [PATCH 01/13] kexec: fix possible memory leak in check_reuse_initrd Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51506ABB.2030808@gmail.com \
    --to=zhangyanfei.yes@gmail.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox