[PATCHv2] tst-pidfd.c: Test is UNSUPPORTED without PTRACE_MODE_ATTACH_REALCREDS

Message ID 20220627105016.4633-1-mark@klomp.org
State Superseded
Headers
Series [PATCHv2] tst-pidfd.c: Test is UNSUPPORTED without PTRACE_MODE_ATTACH_REALCREDS |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Mark Wielaard June 27, 2022, 10:50 a.m. UTC
  pidfd_getfd will fail with errno EPERM if the calling process did not
have PTRACE_MODE_ATTACH_REALCREDS permissions. Use FAIL_UNSUPPORTED
in that case.
---

v2: separate ENOSYS and EPERM checks and FAIL_UNSUPPORTED messages

https://code.wildebeest.org/git/user/mjw/glibc/commit/?h=container-perms&id=5b3288ce83c920b84efb589ad1e434035d873eb9

 sysdeps/unix/sysv/linux/tst-pidfd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/tst-pidfd.c b/sysdeps/unix/sysv/linux/tst-pidfd.c
index d93b6faa6f..8a6db8fe01 100644
--- a/sysdeps/unix/sysv/linux/tst-pidfd.c
+++ b/sysdeps/unix/sysv/linux/tst-pidfd.c
@@ -92,11 +92,16 @@  do_test (void)
   {
     /* The pidfd_getfd syscall was the last in the set of pidfd related
        syscalls added to the kernel.  Use pidfd_getfd to decide if this
-       kernel has pidfd support that we can test.  */
+       kernel has pidfd support that we can test.  And that we have
+       PTRACE_MODE_ATTACH_REALCREDS permissions to use pidfd_getfd.  */
     int r = pidfd_getfd (0, 0, 1);
     TEST_VERIFY_EXIT (r == -1);
     if (errno == ENOSYS)
       FAIL_UNSUPPORTED ("kernel does not support pidfd_getfd, skipping test");
+    if (errno == EPERM)
+      FAIL_UNSUPPORTED ("don't have permission to use pidfd_getfd "
+		        "(missing PTRACE_MODE_ATTACH_REALCREDS?), "
+		        "skipping test");
   }
 
   ppid = getpid ();