archive mirror
 help / color / mirror / Atom feed
From: Ariadne Conill <>
To: Andrew Morton <>
	Eric Biederman <>,
	Kees Cook <>,
	Alexander Viro <>,
	Ariadne Conill <>,
	Michael Kerrisk <>,
	Matthew Wilcox <>,
	Christian Brauner <>,
	Rich Felker <>,,
Subject: [PATCH v3] fs/exec: require argv[0] presence in do_execveat_common()
Date: Thu, 27 Jan 2022 00:07:24 +0000	[thread overview]
Message-ID: <> (raw)

In several other operating systems, it is a hard requirement that the
second 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

To ensure that execve(2) with argc < 1 is not a useful tool 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 execve(2) working
with argc < 1.

We use -EINVAL for this case, mirroring recent changes to FreeBSD and
OpenBSD.  -EINVAL is also used by QNX for this, while Solaris uses

In earlier versions of the patch, it was proposed that we create a
fake argv for applications to use when argc < 1, but it was concluded
that it would be better to just fail the execve(2) in these cases, as
launching a process with an empty or NULL argv[0] was likely to just
cause more problems.

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[2]
of this bug in a shellcode, we can reconsider.

This issue is being tracked in the KSPP issue tracker[3].

There are a few[4][5] minor edge cases (primarily in test suites) that
are caught by this, but we plan to work with the projects to fix those
edge cases.


Changes from v2:
- Switch to using -EINVAL as the error code for this.
- Use pr_warn_once() to warn when an execve(2) is rejected due to NULL

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

Reported-by: Michael Kerrisk <>
To: Andrew Morton <>
Cc: Matthew Wilcox <>
Cc: Christian Brauner <>
Cc: Rich Felker <>
Cc: Eric Biederman <>
Cc: Alexander Viro <>
Cc: Kees Cook <>
Signed-off-by: Ariadne Conill <>
 fs/exec.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index 79f2c9483302..982730cfe3b8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1897,6 +1897,10 @@ static int do_execveat_common(int fd, struct filename *filename,
 	retval = count(argv, MAX_ARG_STRINGS);
+	if (retval == 0) {
+		pr_warn_once("Attempted to run process '%s' with NULL argv\n", bprm->filename);
+		retval = -EINVAL;
+	}
 	if (retval < 0)
 		goto out_free;
 	bprm->argc = retval;

             reply	other threads:[~2022-01-27  0:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27  0:07 Ariadne Conill [this message]
2022-01-27  5:29 ` [PATCH v3] fs/exec: require argv[0] presence in do_execveat_common() Kees Cook
2022-01-27 16:51   ` Eric W. Biederman
2022-01-31 14:43 ` [fs/exec] 80bd5afdd8: kernel test robot
2022-01-31 15:08   ` Christian Brauner
2022-01-31 15:19     ` Matthew Wilcox
2022-01-31 15:37       ` Christian Brauner
2022-01-31 15:51         ` Matthew Wilcox
2022-01-31 16:14           ` Christian Brauner
2022-01-31 17:13             ` Christian Brauner
2022-01-31 21:59               ` Andrew Morton
2022-01-31 22:49                 ` Kees Cook
2022-02-01 13:28                   ` Christian Brauner
2022-02-01 13:28                 ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).