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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250428063300.7137-3-yangtiezhu@loongson.cn>
Date: Mon, 28 Apr 2025 14:33:00 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Christian Brauner <brauner@...nel.org>,
	Shuah Khan <shuah@...nel.org>
Cc: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] selftests: pid_namespace: Skip tests if not root

CLONE_NEWPID or CLONE_NEWNS requires CAP_SYS_ADMIN, if the tests are not
running as root, just skip tests rather than fail and also give a warning
to the user.

Before:

  $ make -C tools/testing/selftests/pid_namespace
  $ tools/testing/selftests/pid_namespace/pid_max
  ...
  #  RUN           global.pid_max_simple ...
  # pid_max.c:337:pid_max_simple:Expected pid (-1) > 0 (0)
  ...
  #  RUN           global.pid_max_nested_limit ...
  # pid_max.c:346:pid_max_nested_limit:Expected pid (-1) > 0 (0)
  ...
  #  RUN           global.pid_max_nested ...
  # pid_max.c:355:pid_max_nested:Expected pid (-1) > 0 (0)
  ...
  # Totals: pass:0 fail:3 xfail:0 xpass:0 skip:0 error:0

After:

  $ make -C tools/testing/selftests/pid_namespace
  $ tools/testing/selftests/pid_namespace/pid_max
  ...
  #  RUN           global.pid_max_simple ...
  #      SKIP      Must be run as root
  ...
  #  RUN           global.pid_max_nested_limit ...
  #      SKIP      Must be run as root
  ...
  #  RUN           global.pid_max_nested ...
  #      SKIP      Must be run as root
  ...
  # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:3 error:0

While at it, remove the blank line in the TEST(pid_max_simple).

Fixes: 615ab43b838b ("tests/pid_namespace: add pid_max tests")
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
 tools/testing/selftests/pid_namespace/pid_max.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/pid_namespace/pid_max.c b/tools/testing/selftests/pid_namespace/pid_max.c
index 96f274f0582b..30937c5ee12b 100644
--- a/tools/testing/selftests/pid_namespace/pid_max.c
+++ b/tools/testing/selftests/pid_namespace/pid_max.c
@@ -332,8 +332,10 @@ TEST(pid_max_simple)
 {
 	pid_t pid;
 
-
 	pid = do_clone(pid_max_cb, NULL, CLONE_NEWPID | CLONE_NEWNS);
+	if (errno == EPERM)
+		SKIP(return, "Must be run as root");
+
 	ASSERT_GT(pid, 0);
 	ASSERT_EQ(0, wait_for_pid(pid));
 }
@@ -343,6 +345,9 @@ TEST(pid_max_nested_limit)
 	pid_t pid;
 
 	pid = do_clone(pid_max_nested_limit_outer, NULL, CLONE_NEWPID | CLONE_NEWNS);
+	if (errno == EPERM)
+		SKIP(return, "Must be run as root");
+
 	ASSERT_GT(pid, 0);
 	ASSERT_EQ(0, wait_for_pid(pid));
 }
@@ -352,6 +357,9 @@ TEST(pid_max_nested)
 	pid_t pid;
 
 	pid = do_clone(pid_max_nested_outer, NULL, CLONE_NEWPID | CLONE_NEWNS);
+	if (errno == EPERM)
+		SKIP(return, "Must be run as root");
+
 	ASSERT_GT(pid, 0);
 	ASSERT_EQ(0, wait_for_pid(pid));
 }
-- 
2.42.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ