diff mbox series

[4/4] tst-personality.c: Handle personality failing with errno EPERM

Message ID 20220626205915.33201-5-mark@klomp.org
State New
Headers show
Series [1/4] time/tst-clock2.c: clock_settime CLOCK_MONOTONIC might return EPERM | expand

Commit Message

Mark Wielaard June 26, 2022, 8:59 p.m. UTC
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 mbox series

Patch

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;
 }