Skip to content

Commit cb5b020

Browse files
committed
Revert "exec: load_script: don't blindly truncate shebang string"
This reverts commit 8099b04. It turns out that people do actually depend on the shebang string being truncated, and on the fact that an interpreter (like perl) will often just re-interpret it entirely to get the full argument list. Reported-by: Samuel Dionne-Riel <samuel@dionne-riel.com> Acked-by: Kees Cook <keescook@chromium.org> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 23e93c9 commit cb5b020

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

fs/binfmt_script.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ static int load_script(struct linux_binprm *bprm)
4242
fput(bprm->file);
4343
bprm->file = NULL;
4444

45-
for (cp = bprm->buf+2;; cp++) {
46-
if (cp >= bprm->buf + BINPRM_BUF_SIZE)
47-
return -ENOEXEC;
48-
if (!*cp || (*cp == '\n'))
49-
break;
50-
}
45+
bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
46+
if ((cp = strchr(bprm->buf, '\n')) == NULL)
47+
cp = bprm->buf+BINPRM_BUF_SIZE-1;
5148
*cp = '\0';
52-
5349
while (cp > bprm->buf) {
5450
cp--;
5551
if ((*cp == ' ') || (*cp == '\t'))

0 commit comments

Comments
 (0)