public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: WANG Cong <xiyou.wangcong@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>,
	WANG Cong <xiyou.wangcong@gmail.com>,
	WANG Cong <wangcong@zeuux.org>
Subject: [Patch 5/9] fs/binfmt_em86.c: fix resource leaks
Date: Thu,  8 May 2008 21:52:30 +0800	[thread overview]
Message-ID: <12102548313018-git-send-email-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <1210254754206-git-send-email-xiyou.wangcong@gmail.com>

 ->load_binary()'s caller only frees resources which ->load_binary() applied
when it succeeded, so ->load_binary() itself should free the resources on
failure.

Signed-off-by: WANG Cong <wangcong@zeuux.org>

---
diff --git a/fs/binfmt_em86.c b/fs/binfmt_em86.c
index f9c88d0..caa8466 100644
--- a/fs/binfmt_em86.c
+++ b/fs/binfmt_em86.c
@@ -69,11 +69,13 @@ static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
 	bprm->argc++;
 	if (i_arg) {
 		retval = copy_strings_kernel(1, &i_arg, bprm);
-		if (retval < 0) return retval; 
+		if (retval < 0)
+			goto out;
 		bprm->argc++;
 	}
 	retval = copy_strings_kernel(1, &i_name, bprm);
-	if (retval < 0)	return retval;
+	if (retval < 0)
+		goto out;
 	bprm->argc++;
 
 	/*
@@ -82,16 +84,27 @@ static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
 	 * space, and we don't need to copy it.
 	 */
 	file = open_exec(interp);
-	if (IS_ERR(file))
-		return PTR_ERR(file);
+	if (IS_ERR(file)) {
+		retval = PTR_ERR(file);
+		goto out;
+	}
 
 	bprm->file = file;
 
 	retval = prepare_binprm(bprm);
-	if (retval < 0)
-		return retval;
+	if (retval < 0) {
+		if (bprm->file) {
+			allow_write_access(bprm->file);
+			fput(bprm->file);
+		}
+		goto out;
+	}
 
 	return search_binary_handler(bprm, regs);
+
+out:
+	free_arg_pages(bprm);
+	return retval;
 }
 
 static struct linux_binfmt em86_format = {

  parent reply	other threads:[~2008-05-08 13:57 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08 13:52 [Patch 0/9] Fix resource leaks for exec related stuffs WANG Cong
2008-05-08 13:52 ` [Patch 1/9] fs/exec.c: export free_arg_pages WANG Cong
2008-05-10 19:12   ` Al Viro
2008-05-12  3:59     ` WANG Cong
2008-05-08 13:52 ` [Patch 2/9] fs/exec.c: fix resource leaks and wrong goto's WANG Cong
2008-05-10 19:16   ` Al Viro
2008-05-08 13:52 ` [Patch 3/9] fs/compat.c: " WANG Cong
2008-05-10 19:21   ` Al Viro
2008-05-10 20:35     ` Al Viro
2008-05-12  3:46       ` WANG Cong
2008-05-12  4:05         ` Al Viro
2008-05-08 13:52 ` [Patch 4/9] fs/binfmt_script.c: fix resource leaks WANG Cong
2008-05-10 19:24   ` Al Viro
2008-05-08 13:52 ` WANG Cong [this message]
2008-05-10 19:25   ` [Patch 5/9] fs/binfmt_em86.c: " Al Viro
2008-05-12  3:53     ` WANG Cong
2008-05-08 13:52 ` [Patch 6/9] fs/binfmt_misc.c: " WANG Cong
2008-05-10 19:25   ` Al Viro
2008-05-08 13:52 ` [Patch 7/9] fs/exec.c: fix wrong return value of prepare_binprm() WANG Cong
2008-05-10 19:31   ` Al Viro
2008-05-12  3:56     ` WANG Cong
2008-05-12  4:01       ` Al Viro
2008-05-12  4:15         ` WANG Cong
2008-05-12  4:37           ` Al Viro
2008-05-12  4:52             ` WANG Cong
2008-05-08 13:52 ` [Patch 8/9] fs/binfmt_elf.c: fix wrong return values WANG Cong
2008-05-08 13:52 ` [Patch 9/9] fs/exec.c: fix a wrong goto path WANG Cong
2008-05-10 19:37   ` Al Viro
2008-05-12  3:51     ` WANG Cong
2008-05-12  3:58       ` Al Viro
2008-05-10 20:47 ` [Patch 0/9] Fix resource leaks for exec related stuffs Al Viro

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=12102548313018-git-send-email-xiyou.wangcong@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wangcong@zeuux.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