]> granicus.if.org Git - strace/commitdiff
Implement decoding of fsopen syscall
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 26 Jun 2019 08:00:39 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 29 Jun 2019 17:38:25 +0000 (17:38 +0000)
... 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.

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

index d4f9e1a886b07db7df56321dc850463e5c7cb1e4..9fe5055af3941fca68a40975ffe69a8f12d566d7 100644 (file)
@@ -132,6 +132,7 @@ strace_SOURCES =    \
        flock.c         \
        flock.h         \
        fs_x_ioctl.c    \
+       fsopen.c        \
        futex.c         \
        gcc_compat.h    \
        get_personality.c \
diff --git a/NEWS b/NEWS
index 34bea8186062358c4f3fa1d909c93775df289101..75bed509d750a88b076bbe13e9e466acb6f0359a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@ Noteworthy changes in release ?.? (????-??-??)
 ==============================================
 
 * Improvements
-  * Implemented decoding of open_tree and move_mount syscalls.
+  * Implemented decoding of open_tree, move_mount, and fsopen syscalls.
   * Enhanced decoding of clone syscall.
   * Updated lists of AT_*, AUDIT_*, CLONE_*, ETH_*, KEY_*, KVM_*, TIPC_*,
     and V4L2_* constants.
diff --git a/fsopen.c b/fsopen.c
new file mode 100644 (file)
index 0000000..1bae2c5
--- /dev/null
+++ b/fsopen.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+#ifdef HAVE_LINUX_MOUNT_H
+# include <linux/mount.h>
+#endif
+#include "xlat/fsopen_flags.h"
+
+SYS_FUNC(fsopen)
+{
+       printstr(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       printflags(fsopen_flags, tcp->u_arg[1], "FSOPEN_???");
+       return RVAL_DECODED | RVAL_FD;
+}
index 6844404f41105922f251b1327a06fda5b3680081..abad88057b3f355cc8bf67793c5be0c65b6ceb00 100644 (file)
@@ -14,3 +14,4 @@
 [BASE_NR + 427] = { 4, TD|TM,          SEN(io_uring_register),         "io_uring_register"     },
 [BASE_NR + 428] = { 3, TD|TF,          SEN(open_tree),                 "open_tree"             },
 [BASE_NR + 429] = { 5, TD|TF,          SEN(move_mount),                "move_mount"            },
+[BASE_NR + 430] = { 2, TD,             SEN(fsopen),                    "fsopen"                },
index 23667798a74bf5e9eafccfad6e8e9876536d1d7d..6de690e9f45333c98e417d285485397e577ff5a5 100644 (file)
@@ -326,6 +326,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
        case SEN_eventfd2:
        case SEN_eventfd:
        case SEN_fanotify_init:
+       case SEN_fsopen:
        case SEN_inotify_init:
        case SEN_inotify_init1:
        case SEN_io_uring_enter:
index 7234060618a2b31bcbefcd41198b5f29ccc74f5e..c0d5bd7b072110d84fe52c35f5adc3a973691815 100644 (file)
@@ -89,6 +89,7 @@ filter-unavailable
 finit_module
 flock
 fork-f
+fsopen
 fstat
 fstat-Xabbrev
 fstat-Xraw
diff --git a/tests/fsopen.c b/tests/fsopen.c
new file mode 100644 (file)
index 0000000..2b0baf7
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Check decoding of fsopen 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 <asm/unistd.h>
+#include "scno.h"
+
+#ifdef __NR_fsopen
+
+# include <stdio.h>
+# include <stdint.h>
+# include <unistd.h>
+
+static const char *errstr;
+
+static long
+k_fsopen(const void *name, 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 = (uintptr_t) name;
+       const kernel_ulong_t arg2 = fill | flags;
+       const long rc = syscall(__NR_fsopen, arg1, arg2, bad, bad, bad, bad);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
+int
+main(void)
+{
+       char *const name1 = tail_alloc(DEFAULT_STRLEN + 2);
+       char *const name = name1 + 1;
+       const void *const efault = name + DEFAULT_STRLEN + 1;
+       const char *const empty = efault - 1;
+       fill_memory_ex(name1, DEFAULT_STRLEN + 1, '0', 10);
+       name1[DEFAULT_STRLEN + 1] = '\0';
+
+       k_fsopen(name, 0);
+       printf("fsopen(\"%s\", 0) = %s\n", name, errstr);
+
+       k_fsopen(name1, 1);
+       printf("fsopen(\"%.*s\"..., FSOPEN_CLOEXEC) = %s\n",
+              DEFAULT_STRLEN, name1, errstr);
+
+       k_fsopen(0, 2);
+       printf("fsopen(NULL, 0x2 /* FSOPEN_??? */) = %s\n", errstr);
+
+       k_fsopen(efault, 0xfffffffe);
+       printf("fsopen(%p, 0xfffffffe /* FSOPEN_??? */) = %s\n", efault, errstr);
+
+       k_fsopen(empty, -1);
+       printf("fsopen(\"\", FSOPEN_CLOEXEC|0xfffffffe) = %s\n", errstr);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fsopen")
+
+#endif
index 58afdc4ef52be96cbe23844d50f90357360758ff..f2377556628b5a5fd2f393f84b8f4cefae72b042 100644 (file)
@@ -68,6 +68,7 @@ file_ioctl    +ioctl.test
 finit_module   -a25
 flock  -a19
 fork-f -a26 -qq -f -e signal=none -e trace=chdir
+fsopen -a35
 fstat  -a15 -v -P stat.sample
 fstat-Xabbrev -a15 -v -Xabbrev -P stat.sample -e trace=fstat
 fstat-Xraw -a15 -v -Xraw -P stat.sample -e trace=fstat
index 6e57eda5f8f5f5bf15fff8d5e65ee84fb5fc3026..9f57ad5612de2022288a886bdc01ab82a593c6e1 100755 (executable)
@@ -71,6 +71,7 @@ file_handle
 file_ioctl
 finit_module
 flock
+fsopen
 fstat
 fstat-Xabbrev
 fstat-Xraw
diff --git a/xlat/fsopen_flags.in b/xlat/fsopen_flags.in
new file mode 100644 (file)
index 0000000..ce01ddf
--- /dev/null
@@ -0,0 +1 @@
+FSOPEN_CLOEXEC 1