GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected],
	Willy Tarreau <[email protected]>,
	"Paul E . McKenney" <[email protected]>
Subject: [PATCH nolibc 08/14] selftests/nolibc: skip the chroot_root and link_dir tests when not privileged
Date: Mon, 20 Mar 2023 18:11:31 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <6a3206d0-e5cd-4990-9604-444a24a8207c@paulmck-laptop>

From: Willy Tarreau <[email protected]>

These two tests always fail when the program is started natively as an
unprivileged user, and require the user to carefully check the output
of "make run-user" and ignore them.

Let's add an euid check and condition these two tests to euid==0. Now
the test case stops needlessly reporting failures. E.g.:

  $ make -C tools/testing/selftests/nolibc run-user
  ...
    CC      nolibc-test
  123 test(s) passed.

Signed-off-by: Willy Tarreau <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 772f88bda0f1..6a7c13f0cd61 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -477,6 +477,7 @@ static int test_getpagesize(void)
 int run_syscall(int min, int max)
 {
 	struct stat stat_buf;
+	int euid0;
 	int proc;
 	int test;
 	int tmp;
@@ -486,6 +487,9 @@ int run_syscall(int min, int max)
 	/* <proc> indicates whether or not /proc is mounted */
 	proc = stat("/proc", &stat_buf) == 0;
 
+	/* this will be used to skip certain tests that can't be run unprivileged */
+	euid0 = geteuid() == 0;
+
 	for (test = min; test >= 0 && test <= max; test++) {
 		int llen = 0; // line length
 
@@ -511,7 +515,7 @@ int run_syscall(int min, int max)
 		CASE_TEST(chmod_net);         EXPECT_SYSZR(proc, chmod("/proc/self/net", 0555)); break;
 		CASE_TEST(chmod_self);        EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break;
 		CASE_TEST(chown_self);        EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break;
-		CASE_TEST(chroot_root);       EXPECT_SYSZR(1, chroot("/")); break;
+		CASE_TEST(chroot_root);       EXPECT_SYSZR(euid0, chroot("/")); break;
 		CASE_TEST(chroot_blah);       EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break;
 		CASE_TEST(chroot_exe);        EXPECT_SYSER(proc, chroot("/proc/self/exe"), -1, ENOTDIR); break;
 		CASE_TEST(close_m1);          EXPECT_SYSER(1, close(-1), -1, EBADF); break;
@@ -536,7 +540,7 @@ int run_syscall(int min, int max)
 		CASE_TEST(ioctl_tiocinq);     EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break;
 		CASE_TEST(link_root1);        EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break;
 		CASE_TEST(link_blah);         EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break;
-		CASE_TEST(link_dir);          EXPECT_SYSER(1, link("/", "/blah"), -1, EPERM); break;
+		CASE_TEST(link_dir);          EXPECT_SYSER(euid0, link("/", "/blah"), -1, EPERM); break;
 		CASE_TEST(link_cross);        EXPECT_SYSER(proc, link("/proc/self/net", "/blah"), -1, EXDEV); break;
 		CASE_TEST(lseek_m1);          EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break;
 		CASE_TEST(lseek_0);           EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break;
-- 
2.40.0.rc2


  parent reply	other threads:[~2023-03-21  1:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  1:11 [PATCH nolibc 0/14] nolibc updates for v6.4 Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 01/14] tools/nolibc: always disable stack protector for tests Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 02/14] tools/nolibc: Add gitignore to avoid git complaints about sysroot Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 03/14] tools/nolibc: add stdint.h Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 04/14] tools/nolibc: add integer types and integer limit macros Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 05/14] tools/nolibc: enlarge column width of tests Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 06/14] tools/nolibc: add tests for the integer limits in stdint.h Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 07/14] tools/nolibc: add getuid() and geteuid() Paul E. McKenney
2023-03-21  1:11 ` Paul E. McKenney [this message]
2023-03-21  1:11 ` [PATCH nolibc 09/14] tools/nolibc: check for S_I* macros before defining them Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 10/14] tools/nolibc: Include linux/fcntl.h and remove duplicate code Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 11/14] tools/nolibc: Add statx() and make stat() rely on statx() if necessary Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 12/14] tools/nolibc: Add support for LoongArch Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 13/14] selftests/nolibc: " Paul E. McKenney
2023-03-21  1:11 ` [PATCH nolibc 14/14] selftests/nolibc: Adjust indentation for Makefile Paul E. McKenney

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox