exec: binfmt_misc: kill the onstack iname[BINPRM_BUF_SIZE] array

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/20170922143653.GA17232@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ben Woodard <woodard@redhat.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jim Foraker <foraker1@llnl.gov>
Cc: <tdhooge@llnl.gov>
Cc: Travis Gummels <tgummels@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Oleg Nesterov 2017-10-03 16:15:58 -07:00 committed by Linus Torvalds
parent 43a4f26190
commit 50097f7493

View file

@ -54,7 +54,7 @@ typedef struct {
int size; /* size of magic/mask */ int size; /* size of magic/mask */
char *magic; /* magic or filename extension */ char *magic; /* magic or filename extension */
char *mask; /* mask, NULL for exact match */ char *mask; /* mask, NULL for exact match */
char *interpreter; /* filename of interpreter */ const char *interpreter; /* filename of interpreter */
char *name; char *name;
struct dentry *dentry; struct dentry *dentry;
struct file *interp_file; struct file *interp_file;
@ -131,8 +131,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
{ {
Node *fmt; Node *fmt;
struct file *interp_file = NULL; struct file *interp_file = NULL;
char iname[BINPRM_BUF_SIZE];
const char *iname_addr = iname;
int retval; int retval;
int fd_binary = -1; int fd_binary = -1;
@ -143,10 +141,8 @@ static int load_misc_binary(struct linux_binprm *bprm)
/* to keep locking time low, we copy the interpreter string */ /* to keep locking time low, we copy the interpreter string */
read_lock(&entries_lock); read_lock(&entries_lock);
fmt = check_file(bprm); fmt = check_file(bprm);
if (fmt) { if (fmt)
dget(fmt->dentry); dget(fmt->dentry);
strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
}
read_unlock(&entries_lock); read_unlock(&entries_lock);
if (!fmt) if (!fmt)
return retval; return retval;
@ -198,13 +194,13 @@ static int load_misc_binary(struct linux_binprm *bprm)
bprm->argc++; bprm->argc++;
/* add the interp as argv[0] */ /* 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) if (retval < 0)
goto error; goto error;
bprm->argc++; bprm->argc++;
/* Update interp in case binfmt_script needs it. */ /* Update interp in case binfmt_script needs it. */
retval = bprm_change_interp(iname, bprm); retval = bprm_change_interp(fmt->interpreter, bprm);
if (retval < 0) if (retval < 0)
goto error; goto error;
@ -213,7 +209,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
if (!IS_ERR(interp_file)) if (!IS_ERR(interp_file))
deny_write_access(interp_file); deny_write_access(interp_file);
} else { } else {
interp_file = open_exec(iname); interp_file = open_exec(fmt->interpreter);
} }
retval = PTR_ERR(interp_file); retval = PTR_ERR(interp_file);
if (IS_ERR(interp_file)) if (IS_ERR(interp_file))