]> granicus.if.org Git - strace/commitdiff
Implement decoding of pidfd_open syscall
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 15 Aug 2019 11:54:22 +0000 (11:54 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 15 Aug 2019 11:54:22 +0000 (11:54 +0000)
... introduced by Linux kernel commits v5.3-rc1~142^2~2
and v5.3-rc1~142^2~1.

* pidfd_open.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* pathtrace.c (pathtrace_match_set): Add SEN_pidfd_open.
* linux/syscallent-common.h [BASE_NR + 434]: Wire up pidfd_open.
* NEWS: Mention this change.
* tests/pidfd_open.c: New file.
* tests/pidfd_open-P.c: Likewise.
* tests/pidfd_open-y.c: Likewise.
* tests/gen_tests.in (pidfd_open, pidfd_open-P, pidfd_open-y): New
entries.
* tests/pure_executables.list: Add pidfd_open, pidfd_open-P, and
pidfd_open-y.
* tests/.gitignore: Likewise.

Makefile.am
NEWS
linux/syscallent-common.h
pathtrace.c
pidfd_open.c [new file with mode: 0644]
tests/.gitignore
tests/gen_tests.in
tests/pidfd_open-P.c [new file with mode: 0644]
tests/pidfd_open-y.c [new file with mode: 0644]
tests/pidfd_open.c [new file with mode: 0644]
tests/pure_executables.list

index 25a81f2c42effe2307fe43869be9abf50703f5b0..8ce2147f75dbe2ec33e239ad3d966201c9da8f18 100644 (file)
@@ -233,6 +233,7 @@ strace_SOURCES =    \
        perf_event_struct.h \
        perf_ioctl.c    \
        personality.c   \
+       pidfd_open.c    \
        pkeys.c         \
        poll.c          \
        prctl.c         \
diff --git a/NEWS b/NEWS
index 87c628347e641661d70b2fe4fe4ba495d14dee02..4c8b83409edaed6374d4d751ef28e8a0ea820b22 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Noteworthy changes in release ?.? (????-??-??)
 ==============================================
 
 * Improvements
+  * Implemented decoding of pidfd_open syscall.
   * Enhanced decoding of NETLINK_ROUTE protocol.
   * Implemented decoding of UNIX_DIAG_UID netlink attribute.
   * Updated lists of BPF_*, ETH_*, KEYCTL_*, KVM_*, MAP_*, SO_*, TCP_*, V4L2_*,
index d753a87c975a704a84a187f49f343cd16bf94224..5db092239dd5291ef321620cfef0bf3d28fc4851 100644 (file)
@@ -18,3 +18,4 @@
 [BASE_NR + 431] = { 5, TD|TF,          SEN(fsconfig),                  "fsconfig"              },
 [BASE_NR + 432] = { 3, TD,             SEN(fsmount),                   "fsmount"               },
 [BASE_NR + 433] = { 3, TD|TF,          SEN(fspick),                    "fspick"                },
+[BASE_NR + 434] = { 2, TD,             SEN(pidfd_open),                "pidfd_open"            },
index aba621b77592af80e8f14fac6123dba0f1f947a7..e3903b9d44b8f9ae335fdf5e4f9d31c51f6d272f 100644 (file)
@@ -358,6 +358,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
        case SEN_mq_timedsend_time32:
        case SEN_mq_timedsend_time64:
        case SEN_perf_event_open:
+       case SEN_pidfd_open:
        case SEN_pipe:
        case SEN_pipe2:
        case SEN_printargs:
diff --git a/pidfd_open.c b/pidfd_open.c
new file mode 100644 (file)
index 0000000..bbc7f61
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+
+SYS_FUNC(pidfd_open)
+{
+       /* pid_t pid */
+       tprintf("%d", (int) tcp->u_arg[0]);
+
+       /* unsigned int flags */
+       tprintf(", %#x", (unsigned int) tcp->u_arg[1]);
+
+       return RVAL_DECODED | RVAL_FD;
+}
index f5133873d647d2864feae82df3b61e652e19d55d..afb932d807124ab3a0dd7ec0e594449411b64679 100644 (file)
@@ -395,6 +395,9 @@ personality
 personality-Xabbrev
 personality-Xraw
 personality-Xverbose
+pidfd_open
+pidfd_open-P
+pidfd_open-y
 pidfd_send_signal
 pipe
 pipe2
index 8ad044a831f3ca774ecb8336059576f4d8df917a..7ef5af6ac64fb0fe662b603a039c32f793b493a1 100644 (file)
@@ -338,6 +338,9 @@ perf_event_open_unabbrev    -a1 -v -e trace=perf_event_open
 personality-Xabbrev    +personality.test -Xabbrev
 personality-Xraw       +personality.test -a15 -Xraw
 personality-Xverbose   +personality.test -Xverbose
+pidfd_open     -a17
+pidfd_open-P   -a17 -P /dev/full -e trace=pidfd_open
+pidfd_open-y   -a17 -y -e trace=pidfd_open
 pidfd_send_signal
 pipe2  -a15
 pkey_alloc     -a17
diff --git a/tests/pidfd_open-P.c b/tests/pidfd_open-P.c
new file mode 100644 (file)
index 0000000..a80db64
--- /dev/null
@@ -0,0 +1,2 @@
+#define PATH_TRACING
+#include "pidfd_open.c"
diff --git a/tests/pidfd_open-y.c b/tests/pidfd_open-y.c
new file mode 100644 (file)
index 0000000..18bf947
--- /dev/null
@@ -0,0 +1,2 @@
+#define PRINT_PATHS
+#include "pidfd_open.c"
diff --git a/tests/pidfd_open.c b/tests/pidfd_open.c
new file mode 100644 (file)
index 0000000..e567a99
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Check decoding of pidfd_open syscall.
+ *
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include "scno.h"
+
+#ifdef __NR_pidfd_open
+
+# include <stdio.h>
+# include <unistd.h>
+# ifdef PATH_TRACING
+#  include <fcntl.h>
+# endif
+
+static const char *errstr;
+
+static long
+k_pidfd_open(const unsigned int pid, const unsigned int flags)
+{
+       const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
+       const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
+       const kernel_ulong_t arg1 = fill | pid;
+       const kernel_ulong_t arg2 = fill | flags;
+       const long rc = syscall(__NR_pidfd_open,
+                               arg1, arg2, bad, bad, bad, bad);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
+int
+main(void)
+{
+# if defined PATH_TRACING || defined PRINT_PATHS
+       skip_if_unavailable("/proc/self/fd/");
+# endif
+
+# ifdef PATH_TRACING
+       static const char path_full[] = "/dev/full";
+       (void) close(0);
+       if (open(path_full, O_WRONLY))
+               perror_msg_and_skip(path_full);
+# endif
+
+       k_pidfd_open(0, 0);
+# ifndef PATH_TRACING
+       printf("pidfd_open(0, 0) = %s\n", errstr);
+# endif
+
+       k_pidfd_open(-1U, 0);
+# ifndef PATH_TRACING
+       printf("pidfd_open(-1, 0) = %s\n", errstr);
+# endif
+
+       k_pidfd_open(0, -1U);
+# ifndef PATH_TRACING
+       printf("pidfd_open(0, %#x) = %s\n", -1U, errstr);
+# endif
+
+       const unsigned int flags = 0xfacefeed;
+       const int pid = getpid();
+
+       k_pidfd_open(pid, flags);
+# ifndef PATH_TRACING
+       printf("pidfd_open(%d, %#x) = %s\n", pid, flags, errstr);
+# endif
+
+# ifdef PRINT_PATHS
+       long rc = k_pidfd_open(pid, 0);
+       if (rc < 0)
+               perror_msg_and_skip("pidfd_open");
+# else
+       k_pidfd_open(pid, 0);
+# endif
+
+# ifndef PATH_TRACING
+       printf("pidfd_open(%d, 0) = "
+#  ifdef PRINT_PATHS
+              "%ld<anon_inode:[pidfd]>\n", pid, rc
+#  else
+              "%s\n", pid, errstr
+#  endif
+              );
+# endif
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_pidfd_open");
+
+#endif
index f55ae8a83f048554812c15154581926ef4ba3e81..e0e8cc99021bf83769b5cd91aa4741b7d6bb30e7 100755 (executable)
@@ -339,6 +339,9 @@ personality
 personality-Xabbrev
 personality-Xraw
 personality-Xverbose
+pidfd_open
+pidfd_open-P
+pidfd_open-y
 pidfd_send_signal
 pipe
 pipe2