lkml.org 
[lkml]   [2008]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[Patch 6/9] fs/binfmt_misc.c: fix resource leaks
Date
 ->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_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);

\
 
 \ /
  Last update: 2008-05-08 15:59    [W:0.139 / U:0.800 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site