Browse Source

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.
Dmitry V. Levin 3 months ago
parent
commit
b1a321c079
11 changed files with 135 additions and 0 deletions
  1. 1
    0
      Makefile.am
  2. 1
    0
      NEWS
  3. 1
    0
      linux/syscallent-common.h
  4. 1
    0
      pathtrace.c
  5. 19
    0
      pidfd_open.c
  6. 3
    0
      tests/.gitignore
  7. 3
    0
      tests/gen_tests.in
  8. 2
    0
      tests/pidfd_open-P.c
  9. 2
    0
      tests/pidfd_open-y.c
  10. 99
    0
      tests/pidfd_open.c
  11. 3
    0
      tests/pure_executables.list

+ 1
- 0
Makefile.am View File

@@ -233,6 +233,7 @@ strace_SOURCES =	\
233 233
 	perf_event_struct.h \
234 234
 	perf_ioctl.c	\
235 235
 	personality.c	\
236
+	pidfd_open.c	\
236 237
 	pkeys.c		\
237 238
 	poll.c		\
238 239
 	prctl.c		\

+ 1
- 0
NEWS View File

@@ -2,6 +2,7 @@ Noteworthy changes in release ?.? (????-??-??)
2 2
 ==============================================
3 3
 
4 4
 * Improvements
5
+  * Implemented decoding of pidfd_open syscall.
5 6
   * Enhanced decoding of NETLINK_ROUTE protocol.
6 7
   * Implemented decoding of UNIX_DIAG_UID netlink attribute.
7 8
   * Updated lists of BPF_*, ETH_*, KEYCTL_*, KVM_*, MAP_*, SO_*, TCP_*, V4L2_*,

+ 1
- 0
linux/syscallent-common.h View File

@@ -18,3 +18,4 @@
18 18
 [BASE_NR + 431] = { 5,	TD|TF,		SEN(fsconfig),			"fsconfig"		},
19 19
 [BASE_NR + 432] = { 3,	TD,		SEN(fsmount),			"fsmount"		},
20 20
 [BASE_NR + 433] = { 3,	TD|TF,		SEN(fspick),			"fspick"		},
21
+[BASE_NR + 434] = { 2,	TD,		SEN(pidfd_open),		"pidfd_open"		},

+ 1
- 0
pathtrace.c View File

@@ -358,6 +358,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
358 358
 	case SEN_mq_timedsend_time32:
359 359
 	case SEN_mq_timedsend_time64:
360 360
 	case SEN_perf_event_open:
361
+	case SEN_pidfd_open:
361 362
 	case SEN_pipe:
362 363
 	case SEN_pipe2:
363 364
 	case SEN_printargs:

+ 19
- 0
pidfd_open.c View File

@@ -0,0 +1,19 @@
1
+/*
2
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
3
+ * All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: LGPL-2.1-or-later
6
+ */
7
+
8
+#include "defs.h"
9
+
10
+SYS_FUNC(pidfd_open)
11
+{
12
+	/* pid_t pid */
13
+	tprintf("%d", (int) tcp->u_arg[0]);
14
+
15
+	/* unsigned int flags */
16
+	tprintf(", %#x", (unsigned int) tcp->u_arg[1]);
17
+
18
+	return RVAL_DECODED | RVAL_FD;
19
+}

+ 3
- 0
tests/.gitignore View File

@@ -395,6 +395,9 @@ personality
395 395
 personality-Xabbrev
396 396
 personality-Xraw
397 397
 personality-Xverbose
398
+pidfd_open
399
+pidfd_open-P
400
+pidfd_open-y
398 401
 pidfd_send_signal
399 402
 pipe
400 403
 pipe2

+ 3
- 0
tests/gen_tests.in View File

@@ -338,6 +338,9 @@ perf_event_open_unabbrev	-a1 -v -e trace=perf_event_open
338 338
 personality-Xabbrev	+personality.test -Xabbrev
339 339
 personality-Xraw	+personality.test -a15 -Xraw
340 340
 personality-Xverbose	+personality.test -Xverbose
341
+pidfd_open	-a17
342
+pidfd_open-P	-a17 -P /dev/full -e trace=pidfd_open
343
+pidfd_open-y	-a17 -y -e trace=pidfd_open
341 344
 pidfd_send_signal
342 345
 pipe2	-a15
343 346
 pkey_alloc	-a17

+ 2
- 0
tests/pidfd_open-P.c View File

@@ -0,0 +1,2 @@
1
+#define PATH_TRACING
2
+#include "pidfd_open.c"

+ 2
- 0
tests/pidfd_open-y.c View File

@@ -0,0 +1,2 @@
1
+#define PRINT_PATHS
2
+#include "pidfd_open.c"

+ 99
- 0
tests/pidfd_open.c View File

@@ -0,0 +1,99 @@
1
+/*
2
+ * Check decoding of pidfd_open syscall.
3
+ *
4
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
5
+ * All rights reserved.
6
+ *
7
+ * SPDX-License-Identifier: GPL-2.0-or-later
8
+ */
9
+
10
+#include "tests.h"
11
+#include "scno.h"
12
+
13
+#ifdef __NR_pidfd_open
14
+
15
+# include <stdio.h>
16
+# include <unistd.h>
17
+# ifdef PATH_TRACING
18
+#  include <fcntl.h>
19
+# endif
20
+
21
+static const char *errstr;
22
+
23
+static long
24
+k_pidfd_open(const unsigned int pid, const unsigned int flags)
25
+{
26
+	const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
27
+	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
28
+	const kernel_ulong_t arg1 = fill | pid;
29
+	const kernel_ulong_t arg2 = fill | flags;
30
+	const long rc = syscall(__NR_pidfd_open,
31
+				arg1, arg2, bad, bad, bad, bad);
32
+	errstr = sprintrc(rc);
33
+	return rc;
34
+}
35
+
36
+int
37
+main(void)
38
+{
39
+# if defined PATH_TRACING || defined PRINT_PATHS
40
+	skip_if_unavailable("/proc/self/fd/");
41
+# endif
42
+
43
+# ifdef PATH_TRACING
44
+	static const char path_full[] = "/dev/full";
45
+	(void) close(0);
46
+	if (open(path_full, O_WRONLY))
47
+		perror_msg_and_skip(path_full);
48
+# endif
49
+
50
+	k_pidfd_open(0, 0);
51
+# ifndef PATH_TRACING
52
+	printf("pidfd_open(0, 0) = %s\n", errstr);
53
+# endif
54
+
55
+	k_pidfd_open(-1U, 0);
56
+# ifndef PATH_TRACING
57
+	printf("pidfd_open(-1, 0) = %s\n", errstr);
58
+# endif
59
+
60
+	k_pidfd_open(0, -1U);
61
+# ifndef PATH_TRACING
62
+	printf("pidfd_open(0, %#x) = %s\n", -1U, errstr);
63
+# endif
64
+
65
+	const unsigned int flags = 0xfacefeed;
66
+	const int pid = getpid();
67
+
68
+	k_pidfd_open(pid, flags);
69
+# ifndef PATH_TRACING
70
+	printf("pidfd_open(%d, %#x) = %s\n", pid, flags, errstr);
71
+# endif
72
+
73
+# ifdef PRINT_PATHS
74
+	long rc = k_pidfd_open(pid, 0);
75
+	if (rc < 0)
76
+		perror_msg_and_skip("pidfd_open");
77
+# else
78
+	k_pidfd_open(pid, 0);
79
+# endif
80
+
81
+# ifndef PATH_TRACING
82
+	printf("pidfd_open(%d, 0) = "
83
+#  ifdef PRINT_PATHS
84
+	       "%ld<anon_inode:[pidfd]>\n", pid, rc
85
+#  else
86
+	       "%s\n", pid, errstr
87
+#  endif
88
+	       );
89
+# endif
90
+
91
+	puts("+++ exited with 0 +++");
92
+	return 0;
93
+}
94
+
95
+#else
96
+
97
+SKIP_MAIN_UNDEFINED("__NR_pidfd_open");
98
+
99
+#endif

+ 3
- 0
tests/pure_executables.list View File

@@ -339,6 +339,9 @@ personality
339 339
 personality-Xabbrev
340 340
 personality-Xraw
341 341
 personality-Xverbose
342
+pidfd_open
343
+pidfd_open-P
344
+pidfd_open-y
342 345
 pidfd_send_signal
343 346
 pipe
344 347
 pipe2

Loading…
Cancel
Save