Skip to content

Commit 8b72ca9

Browse files
committed
exec: Move the call of prepare_binprm into search_binary_handler
The code in prepare_binary_handler needs to be run every time search_binary_handler is called so move the call into search_binary_handler itself to make the code simpler and easier to understand. Link: https://lkml.kernel.org/r/[email protected] Acked-by: Linus Torvalds <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: James Morris <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent a16b335 commit 8b72ca9

File tree

6 files changed

+5
-22
lines changed

6 files changed

+5
-22
lines changed

arch/alpha/kernel/binfmt_loader.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ static int load_binary(struct linux_binprm *bprm)
3535

3636
bprm->file = file;
3737
bprm->loader = loader;
38-
retval = prepare_binprm(bprm);
39-
if (retval < 0)
40-
return retval;
4138
return search_binary_handler(bprm);
4239
}
4340

fs/binfmt_em86.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ static int load_em86(struct linux_binprm *bprm)
9191

9292
bprm->file = file;
9393

94-
retval = prepare_binprm(bprm);
95-
if (retval < 0)
96-
return retval;
97-
9894
return search_binary_handler(bprm);
9995
}
10096

fs/binfmt_misc.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
221221
if (fmt->flags & MISC_FMT_CREDENTIALS)
222222
bprm->preserve_creds = 1;
223223

224-
retval = prepare_binprm(bprm);
225-
if (retval < 0)
226-
goto error;
227-
228224
retval = search_binary_handler(bprm);
229225
if (retval < 0)
230226
goto error;

fs/binfmt_script.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ static int load_script(struct linux_binprm *bprm)
143143
return PTR_ERR(file);
144144

145145
bprm->file = file;
146-
retval = prepare_binprm(bprm);
147-
if (retval < 0)
148-
return retval;
149146
return search_binary_handler(bprm);
150147
}
151148

fs/exec.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ static void bprm_fill_uid(struct linux_binprm *bprm)
16291629
*
16301630
* This may be called multiple times for binary chains (scripts for example).
16311631
*/
1632-
int prepare_binprm(struct linux_binprm *bprm)
1632+
static int prepare_binprm(struct linux_binprm *bprm)
16331633
{
16341634
loff_t pos = 0;
16351635

@@ -1650,8 +1650,6 @@ int prepare_binprm(struct linux_binprm *bprm)
16501650
return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
16511651
}
16521652

1653-
EXPORT_SYMBOL(prepare_binprm);
1654-
16551653
/*
16561654
* Arguments are '\0' separated strings found at the location bprm->p
16571655
* points to; chop off the first by relocating brpm->p to right after
@@ -1707,6 +1705,10 @@ int search_binary_handler(struct linux_binprm *bprm)
17071705
if (bprm->recursion_depth > 5)
17081706
return -ELOOP;
17091707

1708+
retval = prepare_binprm(bprm);
1709+
if (retval < 0)
1710+
return retval;
1711+
17101712
retval = security_bprm_check(bprm);
17111713
if (retval)
17121714
return retval;
@@ -1864,10 +1866,6 @@ static int __do_execve_file(int fd, struct filename *filename,
18641866
if (retval)
18651867
goto out;
18661868

1867-
retval = prepare_binprm(bprm);
1868-
if (retval < 0)
1869-
goto out;
1870-
18711869
retval = copy_strings_kernel(1, &bprm->filename, bprm);
18721870
if (retval < 0)
18731871
goto out;

include/linux/binfmts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static inline void insert_binfmt(struct linux_binfmt *fmt)
116116

117117
extern void unregister_binfmt(struct linux_binfmt *);
118118

119-
extern int prepare_binprm(struct linux_binprm *);
120119
extern int __must_check remove_arg_zero(struct linux_binprm *);
121120
extern int search_binary_handler(struct linux_binprm *);
122121
extern int begin_new_exec(struct linux_binprm * bprm);

0 commit comments

Comments
 (0)