linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fs/exec: require argv[0] presence in do_execveat_common()
@ 2022-01-26 11:44 Ariadne Conill
  2022-01-26 14:40 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Ariadne Conill @ 2022-01-26 11:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-fsdevel, Eric Biederman, Kees Cook, Alexander Viro, Ariadne Conill

In several other operating systems, it is a hard requirement that the
first argument to execve(2) be the name of a program, thus prohibiting
a scenario where argc < 1.  POSIX 2017 also recommends this behaviour,
but it is not an explicit requirement[0]:

    The argument arg0 should point to a filename string that is
    associated with the process being started by one of the exec
    functions.

To ensure that execve(2) with argc < 1 is not a useful gadget for
shellcode to use, we can validate this in do_execveat_common() and
fail for this scenario, effectively blocking successful exploitation
of CVE-2021-4034 and similar bugs which depend on this gadget.

The use of -EFAULT for this case is similar to other systems, such
as FreeBSD, OpenBSD and Solaris.  QNX uses -EINVAL for this case.

Interestingly, Michael Kerrisk opened an issue about this in 2008[1],
but there was no consensus to support fixing this issue then.
Hopefully now that CVE-2021-4034 shows practical exploitative use
of this bug in a shellcode, we can reconsider.

[0]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=8408

Changes from v1:
- Rework commit message significantly.
- Make the argv[0] check explicit rather than hijacking the error-check
  for count().

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
---
 fs/exec.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index 79f2c9483302..e52c41991aab 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1899,6 +1899,10 @@ static int do_execveat_common(int fd, struct filename *filename,
 	retval = count(argv, MAX_ARG_STRINGS);
 	if (retval < 0)
 		goto out_free;
+	if (retval == 0) {
+		retval = -EFAULT;
+		goto out_free;
+	}
 	bprm->argc = retval;
 
 	retval = count(envp, MAX_ARG_STRINGS);
-- 
2.34.1


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

end of thread, other threads:[~2022-01-26 23:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 11:44 [PATCH v2] fs/exec: require argv[0] presence in do_execveat_common() Ariadne Conill
2022-01-26 14:40 ` Matthew Wilcox
2022-01-26 17:41   ` Ariadne Conill
2022-01-26 14:59 ` Matthew Wilcox
2022-01-26 16:40   ` Kees Cook
2022-01-26 16:57   ` Eric W. Biederman
2022-01-26 17:32     ` Ariadne Conill
2022-01-26 18:03     ` Matthew Wilcox
2022-01-26 18:38       ` Ariadne Conill
2022-01-26 20:09 ` Kees Cook
2022-01-26 20:23   ` Ariadne Conill
2022-01-26 20:56     ` Kees Cook
2022-01-26 21:13       ` Ariadne Conill
2022-01-26 21:25         ` Kees Cook
2022-01-26 21:30           ` Ariadne Conill
2022-01-26 22:49             ` Kees Cook
2022-01-26 23:07               ` Ariadne Conill

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