exec: Move the call of prepare_binprm into search_binary_handler
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 14 May 2020 03:25:20 +0000 (22:25 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 21 May 2020 15:16:57 +0000 (10:16 -0500)
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/87d070zrvx.fsf_-_@x220.int.ebiederm.org
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: James Morris <jamorris@linux.microsoft.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
arch/alpha/kernel/binfmt_loader.c
fs/binfmt_em86.c
fs/binfmt_misc.c
fs/binfmt_script.c
fs/exec.c
include/linux/binfmts.h

index a8d0d6e..d712ba5 100644 (file)
@@ -35,9 +35,6 @@ static int load_binary(struct linux_binprm *bprm)
 
        bprm->file = file;
        bprm->loader = loader;
-       retval = prepare_binprm(bprm);
-       if (retval < 0)
-               return retval;
        return search_binary_handler(bprm);
 }
 
index 4664978..cedde23 100644 (file)
@@ -91,10 +91,6 @@ static int load_em86(struct linux_binprm *bprm)
 
        bprm->file = file;
 
-       retval = prepare_binprm(bprm);
-       if (retval < 0)
-               return retval;
-
        return search_binary_handler(bprm);
 }
 
index 2648297..50a73af 100644 (file)
@@ -221,10 +221,6 @@ static int load_misc_binary(struct linux_binprm *bprm)
        if (fmt->flags & MISC_FMT_CREDENTIALS)
                bprm->preserve_creds = 1;
 
-       retval = prepare_binprm(bprm);
-       if (retval < 0)
-               goto error;
-
        retval = search_binary_handler(bprm);
        if (retval < 0)
                goto error;
index e9e6a6f..8d718d8 100644 (file)
@@ -143,9 +143,6 @@ static int load_script(struct linux_binprm *bprm)
                return PTR_ERR(file);
 
        bprm->file = file;
-       retval = prepare_binprm(bprm);
-       if (retval < 0)
-               return retval;
        return search_binary_handler(bprm);
 }
 
index 028e0e3..5fc4584 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1629,7 +1629,7 @@ static void bprm_fill_uid(struct linux_binprm *bprm)
  *
  * This may be called multiple times for binary chains (scripts for example).
  */
-int prepare_binprm(struct linux_binprm *bprm)
+static int prepare_binprm(struct linux_binprm *bprm)
 {
        loff_t pos = 0;
 
@@ -1650,8 +1650,6 @@ int prepare_binprm(struct linux_binprm *bprm)
        return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
 }
 
-EXPORT_SYMBOL(prepare_binprm);
-
 /*
  * Arguments are '\0' separated strings found at the location bprm->p
  * 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)
        if (bprm->recursion_depth > 5)
                return -ELOOP;
 
+       retval = prepare_binprm(bprm);
+       if (retval < 0)
+               return retval;
+
        retval = security_bprm_check(bprm);
        if (retval)
                return retval;
@@ -1864,10 +1866,6 @@ static int __do_execve_file(int fd, struct filename *filename,
        if (retval)
                goto out;
 
-       retval = prepare_binprm(bprm);
-       if (retval < 0)
-               goto out;
-
        retval = copy_strings_kernel(1, &bprm->filename, bprm);
        if (retval < 0)
                goto out;
index dbb5614..8c7779d 100644 (file)
@@ -116,7 +116,6 @@ static inline void insert_binfmt(struct linux_binfmt *fmt)
 
 extern void unregister_binfmt(struct linux_binfmt *);
 
-extern int prepare_binprm(struct linux_binprm *);
 extern int __must_check remove_arg_zero(struct linux_binprm *);
 extern int search_binary_handler(struct linux_binprm *);
 extern int begin_new_exec(struct linux_binprm * bprm);