From: Dmitry V. Levin Date: Thu, 15 Aug 2019 11:54:22 +0000 (+0000) Subject: Implement decoding of pidfd_open syscall X-Git-Tag: v5.3~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1a321c0794d00a8778f5a12d0593817396a3e55;p=strace Implement decoding of pidfd_open syscall ... 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. --- diff --git a/Makefile.am b/Makefile.am index 25a81f2c..8ce2147f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 87c62834..4c8b8340 100644 --- 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_*, diff --git a/linux/syscallent-common.h b/linux/syscallent-common.h index d753a87c..5db09223 100644 --- a/linux/syscallent-common.h +++ b/linux/syscallent-common.h @@ -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" }, diff --git a/pathtrace.c b/pathtrace.c index aba621b7..e3903b9d 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -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 index 00000000..bbc7f617 --- /dev/null +++ b/pidfd_open.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2019 Dmitry V. Levin + * 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; +} diff --git a/tests/.gitignore b/tests/.gitignore index f5133873..afb932d8 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -395,6 +395,9 @@ personality personality-Xabbrev personality-Xraw personality-Xverbose +pidfd_open +pidfd_open-P +pidfd_open-y pidfd_send_signal pipe pipe2 diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 8ad044a8..7ef5af6a 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -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 index 00000000..a80db647 --- /dev/null +++ b/tests/pidfd_open-P.c @@ -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 index 00000000..18bf947d --- /dev/null +++ b/tests/pidfd_open-y.c @@ -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 index 00000000..e567a99b --- /dev/null +++ b/tests/pidfd_open.c @@ -0,0 +1,99 @@ +/* + * Check decoding of pidfd_open syscall. + * + * Copyright (c) 2019 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include "scno.h" + +#ifdef __NR_pidfd_open + +# include +# include +# ifdef PATH_TRACING +# include +# 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\n", pid, rc +# else + "%s\n", pid, errstr +# endif + ); +# endif + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_pidfd_open"); + +#endif diff --git a/tests/pure_executables.list b/tests/pure_executables.list index f55ae8a8..e0e8cc99 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -339,6 +339,9 @@ personality personality-Xabbrev personality-Xraw personality-Xverbose +pidfd_open +pidfd_open-P +pidfd_open-y pidfd_send_signal pipe pipe2