Browse Source

Implement decoding of fsopen syscall

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

* fsopen.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* pathtrace.c (pathtrace_match_set): Add SEN_fsopen.
* xlat/fsopen_flags.in: New file.
* linux/syscallent-common.h [BASE_NR + 430]: Wire up fsopen.
* NEWS: Mention this change.
* tests/fsopen.c: New file.
* tests/gen_tests.in (fsopen): New entry.
* tests/pure_executables.list: Add fsopen.
* tests/.gitignore: Likewise.
Dmitry V. Levin 5 months ago
parent
commit
7ab2b642f8
10 changed files with 96 additions and 1 deletions
  1. 1
    0
      Makefile.am
  2. 1
    1
      NEWS
  3. 20
    0
      fsopen.c
  4. 1
    0
      linux/syscallent-common.h
  5. 1
    0
      pathtrace.c
  6. 1
    0
      tests/.gitignore
  7. 68
    0
      tests/fsopen.c
  8. 1
    0
      tests/gen_tests.in
  9. 1
    0
      tests/pure_executables.list
  10. 1
    0
      xlat/fsopen_flags.in

+ 1
- 0
Makefile.am View File

@@ -132,6 +132,7 @@ strace_SOURCES =	\
132 132
 	flock.c		\
133 133
 	flock.h		\
134 134
 	fs_x_ioctl.c	\
135
+	fsopen.c	\
135 136
 	futex.c		\
136 137
 	gcc_compat.h	\
137 138
 	get_personality.c \

+ 1
- 1
NEWS View File

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

+ 20
- 0
fsopen.c View File

@@ -0,0 +1,20 @@
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/fsopen_flags.h"
13
+
14
+SYS_FUNC(fsopen)
15
+{
16
+	printstr(tcp, tcp->u_arg[0]);
17
+	tprints(", ");
18
+	printflags(fsopen_flags, tcp->u_arg[1], "FSOPEN_???");
19
+	return RVAL_DECODED | RVAL_FD;
20
+}

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

@@ -14,3 +14,4 @@
14 14
 [BASE_NR + 427] = { 4,	TD|TM,		SEN(io_uring_register),		"io_uring_register"	},
15 15
 [BASE_NR + 428] = { 3,	TD|TF,		SEN(open_tree),			"open_tree"		},
16 16
 [BASE_NR + 429] = { 5,	TD|TF,		SEN(move_mount),		"move_mount"		},
17
+[BASE_NR + 430] = { 2,	TD,		SEN(fsopen),			"fsopen"		},

+ 1
- 0
pathtrace.c View File

@@ -326,6 +326,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
326 326
 	case SEN_eventfd2:
327 327
 	case SEN_eventfd:
328 328
 	case SEN_fanotify_init:
329
+	case SEN_fsopen:
329 330
 	case SEN_inotify_init:
330 331
 	case SEN_inotify_init1:
331 332
 	case SEN_io_uring_enter:

+ 1
- 0
tests/.gitignore View File

@@ -89,6 +89,7 @@ filter-unavailable
89 89
 finit_module
90 90
 flock
91 91
 fork-f
92
+fsopen
92 93
 fstat
93 94
 fstat-Xabbrev
94 95
 fstat-Xraw

+ 68
- 0
tests/fsopen.c View File

@@ -0,0 +1,68 @@
1
+/*
2
+ * Check decoding of fsopen 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_fsopen
15
+
16
+# include <stdio.h>
17
+# include <stdint.h>
18
+# include <unistd.h>
19
+
20
+static const char *errstr;
21
+
22
+static long
23
+k_fsopen(const void *name, const unsigned int flags)
24
+{
25
+	const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
26
+	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
27
+	const kernel_ulong_t arg1 = (uintptr_t) name;
28
+	const kernel_ulong_t arg2 = fill | flags;
29
+	const long rc = syscall(__NR_fsopen, arg1, arg2, bad, bad, bad, bad);
30
+	errstr = sprintrc(rc);
31
+	return rc;
32
+}
33
+
34
+int
35
+main(void)
36
+{
37
+	char *const name1 = tail_alloc(DEFAULT_STRLEN + 2);
38
+	char *const name = name1 + 1;
39
+	const void *const efault = name + DEFAULT_STRLEN + 1;
40
+	const char *const empty = efault - 1;
41
+	fill_memory_ex(name1, DEFAULT_STRLEN + 1, '0', 10);
42
+	name1[DEFAULT_STRLEN + 1] = '\0';
43
+
44
+	k_fsopen(name, 0);
45
+	printf("fsopen(\"%s\", 0) = %s\n", name, errstr);
46
+
47
+	k_fsopen(name1, 1);
48
+	printf("fsopen(\"%.*s\"..., FSOPEN_CLOEXEC) = %s\n",
49
+	       DEFAULT_STRLEN, name1, errstr);
50
+
51
+	k_fsopen(0, 2);
52
+	printf("fsopen(NULL, 0x2 /* FSOPEN_??? */) = %s\n", errstr);
53
+
54
+	k_fsopen(efault, 0xfffffffe);
55
+	printf("fsopen(%p, 0xfffffffe /* FSOPEN_??? */) = %s\n", efault, errstr);
56
+
57
+	k_fsopen(empty, -1);
58
+	printf("fsopen(\"\", FSOPEN_CLOEXEC|0xfffffffe) = %s\n", errstr);
59
+
60
+	puts("+++ exited with 0 +++");
61
+	return 0;
62
+}
63
+
64
+#else
65
+
66
+SKIP_MAIN_UNDEFINED("__NR_fsopen")
67
+
68
+#endif

+ 1
- 0
tests/gen_tests.in View File

@@ -68,6 +68,7 @@ file_ioctl	+ioctl.test
68 68
 finit_module	-a25
69 69
 flock	-a19
70 70
 fork-f	-a26 -qq -f -e signal=none -e trace=chdir
71
+fsopen	-a35
71 72
 fstat	-a15 -v -P stat.sample
72 73
 fstat-Xabbrev -a15 -v -Xabbrev -P stat.sample -e trace=fstat
73 74
 fstat-Xraw -a15 -v -Xraw -P stat.sample -e trace=fstat

+ 1
- 0
tests/pure_executables.list View File

@@ -71,6 +71,7 @@ file_handle
71 71
 file_ioctl
72 72
 finit_module
73 73
 flock
74
+fsopen
74 75
 fstat
75 76
 fstat-Xabbrev
76 77
 fstat-Xraw

+ 1
- 0
xlat/fsopen_flags.in View File

@@ -0,0 +1 @@
1
+FSOPEN_CLOEXEC	1

Loading…
Cancel
Save