Skip to content

Commit

Permalink
exec: binfmt_misc: kill the onstack iname[BINPRM_BUF_SIZE] array
Browse files Browse the repository at this point in the history
After the previous change "fmt" can't go away, we can kill
iname/iname_addr and use fmt->interpreter.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Ben Woodard <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: Jim Foraker <[email protected]>
Cc: <[email protected]>
Cc: Travis Gummels <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Oct 4, 2017
1 parent 43a4f26 commit 50097f7
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct {
int size; /* size of magic/mask */
char *magic; /* magic or filename extension */
char *mask; /* mask, NULL for exact match */
char *interpreter; /* filename of interpreter */
const char *interpreter; /* filename of interpreter */
char *name;
struct dentry *dentry;
struct file *interp_file;
Expand Down Expand Up @@ -131,8 +131,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
{
Node *fmt;
struct file *interp_file = NULL;
char iname[BINPRM_BUF_SIZE];
const char *iname_addr = iname;
int retval;
int fd_binary = -1;

Expand All @@ -143,10 +141,8 @@ static int load_misc_binary(struct linux_binprm *bprm)
/* to keep locking time low, we copy the interpreter string */
read_lock(&entries_lock);
fmt = check_file(bprm);
if (fmt) {
if (fmt)
dget(fmt->dentry);
strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
}
read_unlock(&entries_lock);
if (!fmt)
return retval;
Expand Down Expand Up @@ -198,13 +194,13 @@ static int load_misc_binary(struct linux_binprm *bprm)
bprm->argc++;

/* add the interp as argv[0] */
retval = copy_strings_kernel(1, &iname_addr, bprm);
retval = copy_strings_kernel(1, &fmt->interpreter, bprm);
if (retval < 0)
goto error;
bprm->argc++;

/* Update interp in case binfmt_script needs it. */
retval = bprm_change_interp(iname, bprm);
retval = bprm_change_interp(fmt->interpreter, bprm);
if (retval < 0)
goto error;

Expand All @@ -213,7 +209,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
if (!IS_ERR(interp_file))
deny_write_access(interp_file);
} else {
interp_file = open_exec(iname);
interp_file = open_exec(fmt->interpreter);
}
retval = PTR_ERR(interp_file);
if (IS_ERR(interp_file))
Expand Down

0 comments on commit 50097f7

Please sign in to comment.