Eric W. Biederman ccbb18b673 exec/binfmt_script: Don't modify bprm->buf and then return -ENOEXEC
The return code -ENOEXEC serves to tell search_binary_handler that it
should continue searching for the binfmt to handle a given file.  This
makes return -ENOEXEC with a bprm->buf that is needed to continue the
search problematic.

The current binfmt_script manages to escape problems as it closes and
clears bprm->file before return -ENOEXEC with bprm->buf modified.
This prevents search_binary_handler from looping as it explicitly
handles a NULL bprm->file.

I plan on moving all of the bprm->file managment into fs/exec.c and out
of the binary handlers so this will become a problem.

Move closing bprm->file and the test for BINPRM_PATH_INACCESSIBLE
down below the last return of -ENOEXEC.

Introduce i_sep and i_end to track the end of the first argument and
the end of the parameters respectively.  Using those, constification
of all char * pointers, and the helpers next_terminator and
next_non_spacetab guarantee the parameter parsing will not modify
bprm->buf.

Only modify bprm->buf to terminate the strings i_arg and i_name with
'\0' for passing to copy_strings_kernel.

When replacing loops with next_non_spacetab and next_terminator care
has been take that the logic of the parsing code (short of replacing
characters by '\0') remains the same.

Link: https://lkml.kernel.org/r/874ksczru6.fsf_-_@x220.int.ebiederm.org
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2020-05-21 10:16:57 -05:00
..
2020-03-27 09:29:56 +00:00
2019-09-19 09:42:37 -07:00
2020-03-31 12:58:36 -07:00
2020-02-17 21:08:37 -08:00
2019-11-11 09:21:59 -05:00
2020-04-07 13:48:26 -07:00
2020-02-13 09:16:07 +01:00
2020-04-08 21:37:18 -07:00
2019-09-19 09:42:37 -07:00
2020-02-05 05:28:20 +00:00
\n
2020-01-30 15:37:41 -08:00
2020-04-10 15:36:22 -07:00
2019-09-19 09:42:37 -07:00
2020-01-14 13:28:28 -08:00
2020-04-21 09:51:10 -06:00
2020-04-24 12:44:19 -07:00
2019-08-07 21:51:47 -04:00
2020-02-07 14:48:35 -05:00
2020-02-07 14:48:35 -05:00
2020-03-06 11:06:15 +01:00
2020-02-08 13:44:41 -08:00
2020-03-05 21:00:40 -05:00
2020-03-05 21:00:40 -05:00
2020-04-06 10:38:59 -04:00
2020-03-12 17:33:11 -07:00
2020-03-02 14:04:31 -07:00
2019-12-08 14:37:36 +01:00