lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260120111008.442109-1-alex@zazolabs.com>
Date: Tue, 20 Jan 2026 11:10:07 +0000
From: Alexander Atanasov <alex@...olabs.com>
To: Shuah Khan <shuah@...nel.org>,
	Christian Brauner <brauner@...nel.org>,
	Jeff Layton <jlayton@...nel.org>
Cc: Alexander Atanasov <alex@...olabs.com>,
	Guenter Roeck <linux@...ck-us.net>,
	Michael Kerrisk <mtk.manpages@...il.com>,
	Alejandro Colomar <alx.manpages@...il.com>,
	Clint George <clintbgeorge@...il.com>,
	Ranganath V N <vnranganath.20@...il.com>,
	linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] selftests/filesystems: follow std execveat argument convention in anon_inode_no_exec

While compiling filesystem selftests there is a warning:
anon_inode_test.c:45:37: warning: null passed to a callee that
       requires a non-null argument [-Wnonnull]
45 |  ASSERT_LT(execveat(fd_context, "", NULL, NULL, AT_EMPTY_PATH), 0);

Kernel code is okay to be passed NULL for argv, in which
case it generates argv by itself inside do_execveat_common.
Man page of execvat lists both argv and envp as _Nullable.
But system's unistd.h says different:
extern int execveat (int __fd, const char *__path, char *const __argv[],
                     char *const __envp[], int __flags)
    __THROW __nonnull ((2, 3));
(checked ubuntu 24.04 and fedora 43)

Which is the reason for the compiler warning.

Fix the warning by passing a proper argv array.

Fixes: f8ca403ae77cb ("selftests/filesystems: add exec() test for anonymous inodes")
Cc: Christian Brauner <brauner@...nel.org>
Cc: Guenter Roeck <linux@...ck-us.net>
Cc: Michael Kerrisk <mtk.manpages@...il.com>
Cc: Alejandro Colomar <alx.manpages@...il.com>
Cc: Clint George <clintbgeorge@...il.com>
Cc: Ranganath V N <vnranganath.20@...il.com>
Signed-off-by: Alexander Atanasov <alex@...olabs.com>
---
 tools/testing/selftests/filesystems/anon_inode_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Quote from execv's man referenced from execveat's:
On Linux, argv and envp can be specified as NULL.
In both cases, this has the same effect as specifying the argument as a pointer 
to a list containing a  single null pointer.
***Do not take advantage of this nonstandard and nonportable misfeature!***

Listed as possible to pass NULL, then a big fat warning in the man page
and a header that acctually marks this as invalid usage.
I failed to find the origin of the above contradiction.
It looks like POSIX/GNU/Linux missalignment.
I am putting this here for the record. So may be someone could step in
and make it right.

I've Cc-ed people who made fixes but they are just compile fixes, no
explanation of why the warning exists and in most of them the array is not a proper
argv.

diff --git a/tools/testing/selftests/filesystems/anon_inode_test.c b/tools/testing/selftests/filesystems/anon_inode_test.c
index 94c6c81c2301..191549a4304d 100644
--- a/tools/testing/selftests/filesystems/anon_inode_test.c
+++ b/tools/testing/selftests/filesystems/anon_inode_test.c
@@ -4,6 +4,7 @@
 
 #include <fcntl.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <sys/stat.h>
 
 #include "kselftest_harness.h"
@@ -37,12 +38,13 @@ TEST(anon_inode_no_chmod)
 
 TEST(anon_inode_no_exec)
 {
+	char *const argv[] = { "", NULL };
 	int fd_context;
 
 	fd_context = sys_fsopen("tmpfs", 0);
 	ASSERT_GE(fd_context, 0);
 
-	ASSERT_LT(execveat(fd_context, "", NULL, NULL, AT_EMPTY_PATH), 0);
+	ASSERT_LT(execveat(fd_context, "", argv, NULL, AT_EMPTY_PATH), 0);
 	ASSERT_EQ(errno, EACCES);
 
 	EXPECT_EQ(close(fd_context), 0);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ