linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exec/binfmt_script: trip zero bytes from the buffer
@ 2021-06-15 16:23 Andrei Vagin
  2021-06-15 19:33 ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Andrei Vagin @ 2021-06-15 16:23 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: linux-kernel, Kees Cook, linux-fsdevel, Andrei Vagin

Without this fix, if we try to run a script that contains only the
interpreter line, the interpreter is executed with one extra empty
argument.

The code is written so that i_end has to be set to the end of valuable
data in the buffer.

Fixes: ccbb18b67323 ("exec/binfmt_script: Don't modify bprm->buf and then return -ENOEXEC")
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
 fs/binfmt_script.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c
index 1b6625e95958..e242680f96e1 100644
--- a/fs/binfmt_script.c
+++ b/fs/binfmt_script.c
@@ -68,6 +68,9 @@ static int load_script(struct linux_binprm *bprm)
 		if (!next_terminator(i_end, buf_end))
 			return -ENOEXEC;
 		i_end = buf_end;
+		/* Trim zero bytes from i_end */
+		while (i_end[-1] == 0)
+			i_end--;
 	}
 	/* Trim any trailing spaces/tabs from i_end */
 	while (spacetab(i_end[-1]))
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-25  8:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 16:23 [PATCH] exec/binfmt_script: trip zero bytes from the buffer Andrei Vagin
2021-06-15 19:33 ` Eric W. Biederman
2021-06-15 22:35   ` Andrei Vagin
2021-06-21 19:27     ` Eric W. Biederman
2021-06-25  8:30       ` Andrei Vagin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).