public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: libc-alpha@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 4/4] tst-personality.c: Handle personality failing with errno EPERM
Date: Sun, 26 Jun 2022 22:59:15 +0200	[thread overview]
Message-ID: <20220626205915.33201-5-mark@klomp.org> (raw)
In-Reply-To: <20220626205915.33201-1-mark@klomp.org>

When running under a systemd service with LockPersonality set or
in a container with a personality seccomp filter the personality
syscall might fail with errno EPERM for some personality calls
so that the kernel execution domain can not be changed from the
default. Return 77 (to indicate the test is unsupported) in that
case.
---
 sysdeps/unix/sysv/linux/tst-personality.c | 37 ++++++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/tst-personality.c b/sysdeps/unix/sysv/linux/tst-personality.c
index 5bbc3c4d0b..8fbba2b262 100644
--- a/sysdeps/unix/sysv/linux/tst-personality.c
+++ b/sysdeps/unix/sysv/linux/tst-personality.c
@@ -30,13 +30,40 @@ do_test (void)
   errno = 0xdefaced;
   saved_persona = personality (0xffffffff);
 
-  if (personality (test_persona) != saved_persona
-      || personality (0xffffffff) == -1
-      || personality (PER_LINUX) == -1
-      || personality (0xffffffff) != PER_LINUX
-      || 0xdefaced != errno)
+  if (saved_persona == -1 && errno == EPERM)
+    return 77;
+
+  if (personality (test_persona) != saved_persona)
+    {
+      if (errno == EPERM)
+	{
+	  rc = 77;
+	  goto out;
+	}
+      else
+	rc = 1;
+    }
+
+  if (personality (0xffffffff) == -1)
+    rc = 1;
+
+  if (personality (PER_LINUX) == -1)
+    {
+      if (errno == EPERM)
+	{
+	  rc = 77;
+	  goto out;
+	}
+      rc = 1;
+    }
+
+  if (personality (0xffffffff) != PER_LINUX)
+    rc = 1;
+
+  if (0xdefaced != errno)
     rc = 1;
 
+out:
   (void) personality (saved_persona);
   return rc;
 }
-- 
2.30.2


      parent reply	other threads:[~2022-06-26 21:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26 20:59 Handle running make check in a restricted environment Mark Wielaard
2022-06-26 20:59 ` [PATCH 1/4] time/tst-clock2.c: clock_settime CLOCK_MONOTONIC might return EPERM Mark Wielaard
2022-06-26 21:15   ` Florian Weimer
2022-06-27  9:35     ` Mark Wielaard
2022-06-26 20:59 ` [PATCH 2/4] tst-pkey.c: Handle no permission to alloc memory protection keys Mark Wielaard
2022-06-26 21:17   ` Florian Weimer
2022-06-26 21:40     ` Florian Weimer
2022-06-27  9:50     ` Mark Wielaard
2022-06-27 11:39       ` Florian Weimer
2022-06-27 14:08         ` Mark Wielaard
2022-06-26 20:59 ` [PATCH 3/4] tst-pidfd.c: Test is UNSUPPORTED without PTRACE_MODE_ATTACH_REALCREDS Mark Wielaard
2022-06-26 21:20   ` Florian Weimer
2022-06-27 10:01     ` Mark Wielaard
2022-06-27 11:14       ` Florian Weimer
2022-06-27 11:51         ` Christian Brauner
2022-06-27 14:17           ` Mark Wielaard
2022-06-27 14:21             ` Adhemerval Zanella
2022-06-27 14:25             ` Christian Brauner
2022-06-27 14:42           ` Florian Weimer
2022-06-27 14:57             ` Adhemerval Zanella
2022-06-27 15:08               ` Christian Brauner
2022-06-27 15:14                 ` Adhemerval Zanella
2022-06-27 16:48                   ` Mark Wielaard
2022-06-27 17:03                     ` Adhemerval Zanella
2022-07-01 10:38                       ` Mark Wielaard
2022-06-27 15:03             ` Christian Brauner
2022-06-27 14:23   ` Adhemerval Zanella
2022-06-27 16:36     ` Mark Wielaard
2022-06-26 20:59 ` Mark Wielaard [this message]

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=20220626205915.33201-5-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=libc-alpha@sourceware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).