Skip to content

Commit c2109f0

Browse files
torvaldsgregkh
authored andcommitted
Revert "exec: load_script: don't blindly truncate shebang string"
commit cb5b020 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6f8c14e commit c2109f0

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎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)