Oleg Nesterov 56ade33b1b exec: load_script: don't blindly truncate shebang string
[ Upstream commit 8099b047ecc431518b9bb6bdbba3549bbecdc343 ]

load_script() simply truncates bprm->buf and this is very wrong if the
length of shebang string exceeds BINPRM_BUF_SIZE-2.  This can silently
truncate i_arg or (worse) we can execute the wrong binary if buf[2:126]
happens to be the valid executable path.

Change load_script() to return ENOEXEC if it can't find '\n' or zero in
bprm->buf.  Note that '\0' can come from either
prepare_binprm()->memset() or from kernel_read(), we do not care.

Link: http://lkml.kernel.org/r/20181112160931.GA28463@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Ben Woodard <woodard@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-02-12 19:46:10 +01:00
..
2018-07-08 15:30:51 +02:00
2018-07-17 11:39:26 +02:00
2018-12-05 19:41:25 +01:00
2018-12-17 09:28:54 +01:00
2019-02-12 19:46:09 +01:00
2019-02-12 19:46:03 +01:00
2018-12-21 14:13:04 +01:00
2017-09-04 19:05:15 -04:00
2018-05-16 10:10:25 +02:00