[Patch 6/9] fs/binfmt_misc.c: fix resource leaks
From: WANG Cong
Date: Thu May 08 2008 - 09:57:36 EST
->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@xxxxxxxxx>
---
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 7191306..bcc628c 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -174,7 +174,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
/* add the interp as argv[0] */
retval = copy_strings_kernel (1, &iname_addr, bprm);
if (retval < 0)
- goto _error;
+ goto _error_free;
bprm->argc ++;
bprm->interp = iname; /* for binfmt_script */
@@ -182,7 +182,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
interp_file = open_exec (iname);
retval = PTR_ERR (interp_file);
if (IS_ERR (interp_file))
- goto _error;
+ goto _error_free;
bprm->file = interp_file;
if (fmt->flags & MISC_FMT_CREDENTIALS) {
@@ -196,14 +196,22 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
retval = prepare_binprm (bprm);
if (retval < 0)
- goto _error;
+ goto _error_file;
retval = search_binary_handler (bprm, regs);
if (retval < 0)
- goto _error;
+ goto _error_file;
_ret:
return retval;
+
+_error_file:
+ allow_write_access(bprm->file);
+ fput(bprm->file);
+
+_error_free:
+ free_arg_pages(bprm);
+
_error:
if (fd_binary > 0)
sys_close(fd_binary);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/