]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tst-pidfd.c: UNSUPPORTED if we get EPERM on valid pidfd_getfd call
authorMark Wielaard <mark@klomp.org>
Sun, 26 Jun 2022 20:17:17 +0000 (22:17 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 29 Jul 2022 16:52:12 +0000 (18:52 +0200)
pidfd_getfd can fail for a valid pidfd with errno EPERM for various
reasons in a restricted environment. Use FAIL_UNSUPPORTED in that case.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
sysdeps/unix/sysv/linux/tst-pidfd.c

index d93b6faa6f2283102331c44e1fa53b236ad93c91..037af22290a76ac6eb75cc87d2aba5d7e214cb38 100644 (file)
@@ -142,6 +142,13 @@ do_test (void)
     xrecvfrom (sockets[0], &remote_fd, sizeof (remote_fd), 0, NULL, 0);
 
     int fd = pidfd_getfd (pidfd, remote_fd, 0);
+    /* pidfd_getfd may fail with EPERM if the process does not have
+       PTRACE_MODE_ATTACH_REALCREDS permissions. This means the call
+       may be denied if the process doesn't have CAP_SYS_PTRACE or
+       if a LSM security_ptrace_access_check denies access.  */
+    if (fd == -1 && errno == EPERM)
+      FAIL_UNSUPPORTED ("don't have permission to use pidfd_getfd on pidfd, "
+                       "skipping test");
     TEST_VERIFY (fd > 0);
 
     char *path = xasprintf ("/proc/%d/fd/%d", pid, remote_fd);