Skip to content

Commit 50097f7

Browse files
oleg-nesterovtorvalds
authored andcommitted
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>
1 parent 43a4f26 commit 50097f7

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

fs/binfmt_misc.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
int size; /* size of magic/mask */
5555
char *magic; /* magic or filename extension */
5656
char *mask; /* mask, NULL for exact match */
57-
char *interpreter; /* filename of interpreter */
57+
const char *interpreter; /* filename of interpreter */
5858
char *name;
5959
struct dentry *dentry;
6060
struct file *interp_file;
@@ -131,8 +131,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
131131
{
132132
Node *fmt;
133133
struct file *interp_file = NULL;
134-
char iname[BINPRM_BUF_SIZE];
135-
const char *iname_addr = iname;
136134
int retval;
137135
int fd_binary = -1;
138136

@@ -143,10 +141,8 @@ static int load_misc_binary(struct linux_binprm *bprm)
143141
/* to keep locking time low, we copy the interpreter string */
144142
read_lock(&entries_lock);
145143
fmt = check_file(bprm);
146-
if (fmt) {
144+
if (fmt)
147145
dget(fmt->dentry);
148-
strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
149-
}
150146
read_unlock(&entries_lock);
151147
if (!fmt)
152148
return retval;
@@ -198,13 +194,13 @@ static int load_misc_binary(struct linux_binprm *bprm)
198194
bprm->argc++;
199195

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

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

@@ -213,7 +209,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
213209
if (!IS_ERR(interp_file))
214210
deny_write_access(interp_file);
215211
} else {
216-
interp_file = open_exec(iname);
212+
interp_file = open_exec(fmt->interpreter);
217213
}
218214
retval = PTR_ERR(interp_file);
219215
if (IS_ERR(interp_file))

0 commit comments

Comments
 (0)