diff options
| author | Andrew Morton <akpm@osdl.org> | 2003-12-29 05:41:27 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.osdl.org> | 2003-12-29 05:41:27 -0800 |
| commit | 04e9bcb4d10643da38b434492fb75dd10e0ceba8 (patch) | |
| tree | 74f8c1c07674f0c5302a6e4d7d2cad97bc5a4421 /fs/exec.c | |
| parent | 02cda956de0b28eeb2f65185e9800191fced01c4 (diff) | |
[PATCH] use new unshare_files helper
From: Chris Wright <chrisw@osdl.org>
Use unshare_files during binary loading to eliminate potential leak of
the binary's fd installed during execve(). As is, this breaks
binfmt_som.c
Diffstat (limited to 'fs/exec.c')
| -rw-r--r-- | fs/exec.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/fs/exec.c b/fs/exec.c index 84d224e71d3a..c8527e3d021b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -779,6 +779,7 @@ int flush_old_exec(struct linux_binprm * bprm) { char * name; int i, ch, retval; + struct files_struct *files; /* * Make sure we have a private signal table and that @@ -789,15 +790,25 @@ int flush_old_exec(struct linux_binprm * bprm) goto out; /* + * Make sure we have private file handles. Ask the + * fork helper to do the work for us and the exit + * helper to do the cleanup of the old one. + */ + files = current->files; /* refcounted so safe to hold */ + retval = unshare_files(); + if (retval) + goto out; + /* * Release all of the old mmap stuff */ retval = exec_mmap(bprm->mm); if (retval) - goto out; + goto mmap_failed; bprm->mm = NULL; /* We're using it now */ /* This is the point of no return */ + put_files_struct(files); current->sas_ss_sp = current->sas_ss_size = 0; @@ -830,6 +841,9 @@ int flush_old_exec(struct linux_binprm * bprm) return 0; +mmap_failed: + put_files_struct(current->files); + current->files = files; out: return retval; } |
