mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 23:21:46 +00:00
[PATCH] sanitize handling of shared descriptor tables in failing execve()
* unshare_files() can fail; doing it after irreversible actions is wrong and de_thread() is certainly irreversible. * since we do it unconditionally anyway, we might as well do it in do_execve() and save ourselves the PITA in binfmt handlers, etc. * while we are at it, binfmt_som actually leaked files_struct on failure. As a side benefit, unshare_files(), put_files_struct() and reset_files_struct() become unexported. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
6b335d9c80
commit
fd8328be87
6 changed files with 20 additions and 70 deletions
|
@ -110,7 +110,6 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
|
|||
char *iname_addr = iname;
|
||||
int retval;
|
||||
int fd_binary = -1;
|
||||
struct files_struct *files = NULL;
|
||||
|
||||
retval = -ENOEXEC;
|
||||
if (!enabled)
|
||||
|
@ -133,21 +132,13 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
|
|||
|
||||
if (fmt->flags & MISC_FMT_OPEN_BINARY) {
|
||||
|
||||
files = current->files;
|
||||
retval = unshare_files();
|
||||
if (retval < 0)
|
||||
goto _ret;
|
||||
if (files == current->files) {
|
||||
put_files_struct(files);
|
||||
files = NULL;
|
||||
}
|
||||
/* if the binary should be opened on behalf of the
|
||||
* interpreter than keep it open and assign descriptor
|
||||
* to it */
|
||||
fd_binary = get_unused_fd();
|
||||
if (fd_binary < 0) {
|
||||
retval = fd_binary;
|
||||
goto _unshare;
|
||||
goto _ret;
|
||||
}
|
||||
fd_install(fd_binary, bprm->file);
|
||||
|
||||
|
@ -205,10 +196,6 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
|
|||
if (retval < 0)
|
||||
goto _error;
|
||||
|
||||
if (files) {
|
||||
put_files_struct(files);
|
||||
files = NULL;
|
||||
}
|
||||
_ret:
|
||||
return retval;
|
||||
_error:
|
||||
|
@ -216,9 +203,6 @@ _error:
|
|||
sys_close(fd_binary);
|
||||
bprm->interp_flags = 0;
|
||||
bprm->interp_data = 0;
|
||||
_unshare:
|
||||
if (files)
|
||||
reset_files_struct(current, files);
|
||||
goto _ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue