All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Eric Biederman <ebiederm@xmission.com>
Cc: Kees Cook <keescook@chromium.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,
	Ariadne Conill <ariadne@dereferenced.org>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	Christian Brauner <brauner@kernel.org>,
	Rich Felker <dalias@libc.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: [PATCH] selftests/exec: Avoid future NULL argv execve warning
Date: Mon, 31 Jan 2022 16:08:07 -0800	[thread overview]
Message-ID: <20220201000807.2453486-1-keescook@chromium.org> (raw)

Build actual argv for launching recursion test to avoid future warning
about using an empty argv in execve().

Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 tools/testing/selftests/exec/recursion-depth.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/exec/recursion-depth.c b/tools/testing/selftests/exec/recursion-depth.c
index 2dbd5bc45b3e..35348db00c52 100644
--- a/tools/testing/selftests/exec/recursion-depth.c
+++ b/tools/testing/selftests/exec/recursion-depth.c
@@ -24,8 +24,14 @@
 #include <sys/mount.h>
 #include <unistd.h>
 
+#define FILENAME "/tmp/1"
+#define HASHBANG "#!" FILENAME "\n"
+
 int main(void)
 {
+	char * const argv[] = { FILENAME, NULL };
+	int rv;
+
 	if (unshare(CLONE_NEWNS) == -1) {
 		if (errno == ENOSYS || errno == EPERM) {
 			fprintf(stderr, "error: unshare, errno %d\n", errno);
@@ -44,21 +50,19 @@ int main(void)
 		return 1;
 	}
 
-#define FILENAME "/tmp/1"
 
 	int fd = creat(FILENAME, 0700);
 	if (fd == -1) {
 		fprintf(stderr, "error: creat, errno %d\n", errno);
 		return 1;
 	}
-#define S "#!" FILENAME "\n"
-	if (write(fd, S, strlen(S)) != strlen(S)) {
+	if (write(fd, HASHBANG, strlen(HASHBANG)) != strlen(HASHBANG)) {
 		fprintf(stderr, "error: write, errno %d\n", errno);
 		return 1;
 	}
 	close(fd);
 
-	int rv = execve(FILENAME, NULL, NULL);
+	rv = execve(FILENAME, argv, NULL);
 	if (rv == -1 && errno == ELOOP) {
 		return 0;
 	}
-- 
2.30.2


             reply	other threads:[~2022-02-01  0:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01  0:08 Kees Cook [this message]
2022-02-02 15:13 ` [PATCH] selftests/exec: Avoid future NULL argv execve warning Alexey Dobriyan
2022-02-02 17:38   ` Shuah Khan
2022-02-02 21:00     ` Alexey Dobriyan
2022-02-04 16:11       ` Shuah Khan

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20220201000807.2453486-1-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=adobriyan@gmail.com \
    --cc=ariadne@dereferenced.org \
    --cc=brauner@kernel.org \
    --cc=dalias@libc.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=shuah@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.