[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220201000807.2453486-1-keescook@chromium.org>
Date: Mon, 31 Jan 2022 16:08:07 -0800
From: Kees Cook <keescook@...omium.org>
To: Eric Biederman <ebiederm@...ssion.com>
Cc: Kees Cook <keescook@...omium.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Shuah Khan <shuah@...nel.org>, linux-kselftest@...r.kernel.org,
Ariadne Conill <ariadne@...eferenced.org>,
Michael Kerrisk <mtk.manpages@...il.com>,
Matthew Wilcox <willy@...radead.org>,
Christian Brauner <brauner@...nel.org>,
Rich Felker <dalias@...c.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH] selftests/exec: Avoid future NULL argv execve warning
Build actual argv for launching recursion test to avoid future warning
about using an empty argv in execve().
Cc: Eric Biederman <ebiederm@...ssion.com>
Cc: Alexey Dobriyan <adobriyan@...il.com>
Cc: Shuah Khan <shuah@...nel.org>
Cc: linux-kselftest@...r.kernel.org
Signed-off-by: Kees Cook <keescook@...omium.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
Powered by blists - more mailing lists