Browse Source

Implement decoding of fspick syscall

... introduced by Linux kernel commits v5.2-rc1~141^2~1,
v5.2-rc1~20^2~1, and v5.2-rc1~20^2.

* fspick.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* pathtrace.c (pathtrace_match_set): Add SEN_fspick.
* xlat/fspick_flags.in: New file.
* linux/syscallent-common.h [BASE_NR + 433]: Wire up fspick.
* NEWS: Mention this change.
* tests/fspick.c: New file.
* tests/fspick-P.c: Likewise.
* tests/gen_tests.in (fspick, fspick-P): New entries.
* tests/pure_executables.list: Add fspick and fspick-P.
* tests/.gitignore: Likewise.
Dmitry V. Levin 4 months ago
parent
commit
e4f97019e3
11 changed files with 152 additions and 2 deletions
  1. 1
    0
      Makefile.am
  2. 2
    2
      NEWS
  3. 25
    0
      fspick.c
  4. 1
    0
      linux/syscallent-common.h
  5. 1
    0
      pathtrace.c
  6. 2
    0
      tests/.gitignore
  7. 2
    0
      tests/fspick-P.c
  8. 110
    0
      tests/fspick.c
  9. 2
    0
      tests/gen_tests.in
  10. 2
    0
      tests/pure_executables.list
  11. 4
    0
      xlat/fspick_flags.in

+ 1
- 0
Makefile.am View File

@@ -135,6 +135,7 @@ strace_SOURCES =	\
135 135
 	fsconfig.c	\
136 136
 	fsmount.c	\
137 137
 	fsopen.c	\
138
+	fspick.c	\
138 139
 	futex.c		\
139 140
 	gcc_compat.h	\
140 141
 	get_personality.c \

+ 2
- 2
NEWS View File

@@ -2,8 +2,8 @@ Noteworthy changes in release ?.? (????-??-??)
2 2
 ==============================================
3 3
 
4 4
 * Improvements
5
-  * Implemented decoding of open_tree, move_mount, fsopen, fsconfig, and fsmount
6
-    syscalls.
5
+  * Implemented decoding of open_tree, move_mount, fsopen, fsconfig, fsmount,
6
+    and fspick syscalls.
7 7
   * Enhanced decoding of clone syscall.
8 8
   * Updated lists of AT_*, AUDIT_*, CLONE_*, ETH_*, KEY_*, KVM_*, TIPC_*,
9 9
     and V4L2_* constants.

+ 25
- 0
fspick.c View File

@@ -0,0 +1,25 @@
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
+#ifdef HAVE_LINUX_MOUNT_H
10
+# include <linux/mount.h>
11
+#endif
12
+#include "xlat/fspick_flags.h"
13
+
14
+SYS_FUNC(fspick)
15
+{
16
+	print_dirfd(tcp, tcp->u_arg[0]);
17
+	tprints(", ");
18
+
19
+	printpath(tcp, tcp->u_arg[1]);
20
+	tprints(", ");
21
+
22
+	printflags(fspick_flags, tcp->u_arg[2], "FSPICK_???");
23
+
24
+	return RVAL_DECODED | RVAL_FD;
25
+}

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

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

+ 1
- 0
pathtrace.c View File

@@ -192,6 +192,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
192 192
 	case SEN_faccessat:
193 193
 	case SEN_fchmodat:
194 194
 	case SEN_fchownat:
195
+	case SEN_fspick:
195 196
 	case SEN_fstatat64:
196 197
 	case SEN_futimesat:
197 198
 	case SEN_inotify_add_watch:

+ 2
- 0
tests/.gitignore View File

@@ -93,6 +93,8 @@ fsconfig
93 93
 fsconfig-P
94 94
 fsmount
95 95
 fsopen
96
+fspick
97
+fspick-P
96 98
 fstat
97 99
 fstat-Xabbrev
98 100
 fstat-Xraw

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

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

+ 110
- 0
tests/fspick.c View File

@@ -0,0 +1,110 @@
1
+/*
2
+ * Check decoding of fspick 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 <asm/unistd.h>
12
+#include "scno.h"
13
+
14
+#ifdef __NR_fspick
15
+
16
+# include <fcntl.h>
17
+# include <limits.h>
18
+# include <stdio.h>
19
+# include <stdint.h>
20
+# include <unistd.h>
21
+
22
+static const char *errstr;
23
+
24
+static long
25
+k_fspick(const unsigned int dfd,
26
+	    const void *fname,
27
+	    const unsigned int flags)
28
+{
29
+	const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
30
+	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
31
+	const kernel_ulong_t arg1 = fill | dfd;
32
+	const kernel_ulong_t arg2 = (uintptr_t) fname;
33
+	const kernel_ulong_t arg3 = fill | flags;
34
+	const long rc = syscall(__NR_fspick, arg1, arg2, arg3, bad, bad, bad);
35
+	errstr = sprintrc(rc);
36
+	return rc;
37
+}
38
+
39
+int
40
+main(void)
41
+{
42
+	skip_if_unavailable("/proc/self/fd/");
43
+
44
+	static const char path_full[] = "/dev/full";
45
+	const char *const path = tail_memdup(path_full, sizeof(path_full));
46
+	char *const fname = tail_alloc(PATH_MAX);
47
+	const void *const efault = fname + PATH_MAX;
48
+	const char *const empty = efault - 1;
49
+	fill_memory_ex(fname, PATH_MAX, '0', 10);
50
+
51
+        int dfd = open(path, O_WRONLY);
52
+        if (dfd < 0)
53
+                perror_msg_and_fail("open: %s", path);
54
+
55
+	k_fspick(-1, 0, 1);
56
+# ifndef PATH_TRACING
57
+	printf("fspick(-1, NULL, %s) = %s\n", "FSPICK_CLOEXEC", errstr);
58
+# endif
59
+
60
+	k_fspick(-100, fname, 0);
61
+# ifndef PATH_TRACING
62
+	printf("fspick(%s, \"%.*s\"..., 0) = %s\n",
63
+	       "AT_FDCWD", (int) PATH_MAX - 1, fname, errstr);
64
+# endif
65
+
66
+	fname[PATH_MAX - 1] = '\0';
67
+	k_fspick(dfd, fname, 0xfffffff0);
68
+	printf("fspick(%d<%s>, \"%s\", %s) = %s\n",
69
+	       dfd, path, fname, "0xfffffff0 /* FSPICK_??? */", errstr);
70
+
71
+	k_fspick(-1, efault, 0xf);
72
+#  ifndef PATH_TRACING
73
+	printf("fspick(-1, %p, %s) = %s\n",
74
+	       efault,
75
+	       "FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
76
+	       "|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
77
+	       errstr);
78
+#  endif
79
+
80
+	k_fspick(-1, empty, -1);
81
+#  ifndef PATH_TRACING
82
+	printf("fspick(-1, \"\", %s|0xfffffff0) = %s\n",
83
+	       "FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
84
+	       "|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
85
+	       errstr);
86
+#  endif
87
+
88
+	if (k_fspick(-1, path, 0) < 0)
89
+		printf("fspick(-1, \"%s\", 0) = %s\n",
90
+		       path, errstr);
91
+	else
92
+		printf("fspick(-1, \"%s\", 0) = %s<%s>\n",
93
+		       path, errstr, path);
94
+
95
+	if (k_fspick(dfd, empty, 8) < 0)
96
+		printf("fspick(%d<%s>, \"\", %s) = %s\n",
97
+		       dfd, path, "FSPICK_EMPTY_PATH", errstr);
98
+	else
99
+		printf("fspick(%d<%s>, \"\", %s) = %s<%s>\n",
100
+		       dfd, path, "FSPICK_EMPTY_PATH", errstr, path);
101
+
102
+	puts("+++ exited with 0 +++");
103
+	return 0;
104
+}
105
+
106
+#else
107
+
108
+SKIP_MAIN_UNDEFINED("__NR_fspick")
109
+
110
+#endif

+ 2
- 0
tests/gen_tests.in View File

@@ -72,6 +72,8 @@ fsconfig	-s300 -y
72 72
 fsconfig-P	-s300 -y -P /dev/full -e trace=fsconfig
73 73
 fsmount	-a18 -y
74 74
 fsopen	-a35
75
+fspick	-a27 -y
76
+fspick-P	-a27 -y -P /dev/full -e trace=fspick
75 77
 fstat	-a15 -v -P stat.sample
76 78
 fstat-Xabbrev -a15 -v -Xabbrev -P stat.sample -e trace=fstat
77 79
 fstat-Xraw -a15 -v -Xraw -P stat.sample -e trace=fstat

+ 2
- 0
tests/pure_executables.list View File

@@ -75,6 +75,8 @@ fsconfig
75 75
 fsconfig-P
76 76
 fsmount
77 77
 fsopen
78
+fspick
79
+fspick-P
78 80
 fstat
79 81
 fstat-Xabbrev
80 82
 fstat-Xraw

+ 4
- 0
xlat/fspick_flags.in View File

@@ -0,0 +1,4 @@
1
+FSPICK_CLOEXEC		0x01
2
+FSPICK_SYMLINK_NOFOLLOW	0x02
3
+FSPICK_NO_AUTOMOUNT	0x04
4
+FSPICK_EMPTY_PATH	0x08

Loading…
Cancel
Save