]> granicus.if.org Git - strace/commitdiff
Implement decoding of fspick syscall
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 29 Jun 2019 17:38:25 +0000 (17:38 +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~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.

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

index 4f0eb642b785d7023a5c0dcac2f35f9bcf2a017d..628e7e907137b7433c866abdc9edf495e9dfb374 100644 (file)
@@ -135,6 +135,7 @@ strace_SOURCES =    \
        fsconfig.c      \
        fsmount.c       \
        fsopen.c        \
+       fspick.c        \
        futex.c         \
        gcc_compat.h    \
        get_personality.c \
diff --git a/NEWS b/NEWS
index 60d088489d06864b576bd6e74362fab15c594f6c..06b5db9b3a88a32064f1d36f4dc1358985efc483 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,8 +2,8 @@ Noteworthy changes in release ?.? (????-??-??)
 ==============================================
 
 * Improvements
-  * Implemented decoding of open_tree, move_mount, fsopen, fsconfig, and fsmount
-    syscalls.
+  * Implemented decoding of open_tree, move_mount, fsopen, fsconfig, fsmount,
+    and fspick syscalls.
   * Enhanced decoding of clone syscall.
   * Updated lists of AT_*, AUDIT_*, CLONE_*, ETH_*, KEY_*, KVM_*, TIPC_*,
     and V4L2_* constants.
diff --git a/fspick.c b/fspick.c
new file mode 100644 (file)
index 0000000..3d00379
--- /dev/null
+++ b/fspick.c
@@ -0,0 +1,25 @@
+/*
+ * 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/fspick_flags.h"
+
+SYS_FUNC(fspick)
+{
+       print_dirfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+
+       printpath(tcp, tcp->u_arg[1]);
+       tprints(", ");
+
+       printflags(fspick_flags, tcp->u_arg[2], "FSPICK_???");
+
+       return RVAL_DECODED | RVAL_FD;
+}
index af96dc7a0527cae107012d7950f0ae81be4ce926..d753a87c975a704a84a187f49f343cd16bf94224 100644 (file)
@@ -17,3 +17,4 @@
 [BASE_NR + 430] = { 2, TD,             SEN(fsopen),                    "fsopen"                },
 [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"                },
index a96b9ff68de1307d75b8abdd0a44752d97433a0a..aba621b77592af80e8f14fac6123dba0f1f947a7 100644 (file)
@@ -192,6 +192,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
        case SEN_faccessat:
        case SEN_fchmodat:
        case SEN_fchownat:
+       case SEN_fspick:
        case SEN_fstatat64:
        case SEN_futimesat:
        case SEN_inotify_add_watch:
index 14f508029332d7a98846357b0696a6a7d4708ac6..178e10764395649370204d65abb93bf4f869fe56 100644 (file)
@@ -93,6 +93,8 @@ fsconfig
 fsconfig-P
 fsmount
 fsopen
+fspick
+fspick-P
 fstat
 fstat-Xabbrev
 fstat-Xraw
diff --git a/tests/fspick-P.c b/tests/fspick-P.c
new file mode 100644 (file)
index 0000000..f3d41eb
--- /dev/null
@@ -0,0 +1,2 @@
+#define PATH_TRACING
+#include "fspick.c"
diff --git a/tests/fspick.c b/tests/fspick.c
new file mode 100644 (file)
index 0000000..e794458
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Check decoding of fspick 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_fspick
+
+# include <fcntl.h>
+# include <limits.h>
+# include <stdio.h>
+# include <stdint.h>
+# include <unistd.h>
+
+static const char *errstr;
+
+static long
+k_fspick(const unsigned int dfd,
+           const void *fname,
+           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 | dfd;
+       const kernel_ulong_t arg2 = (uintptr_t) fname;
+       const kernel_ulong_t arg3 = fill | flags;
+       const long rc = syscall(__NR_fspick, arg1, arg2, arg3, bad, bad, bad);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
+int
+main(void)
+{
+       skip_if_unavailable("/proc/self/fd/");
+
+       static const char path_full[] = "/dev/full";
+       const char *const path = tail_memdup(path_full, sizeof(path_full));
+       char *const fname = tail_alloc(PATH_MAX);
+       const void *const efault = fname + PATH_MAX;
+       const char *const empty = efault - 1;
+       fill_memory_ex(fname, PATH_MAX, '0', 10);
+
+        int dfd = open(path, O_WRONLY);
+        if (dfd < 0)
+                perror_msg_and_fail("open: %s", path);
+
+       k_fspick(-1, 0, 1);
+# ifndef PATH_TRACING
+       printf("fspick(-1, NULL, %s) = %s\n", "FSPICK_CLOEXEC", errstr);
+# endif
+
+       k_fspick(-100, fname, 0);
+# ifndef PATH_TRACING
+       printf("fspick(%s, \"%.*s\"..., 0) = %s\n",
+              "AT_FDCWD", (int) PATH_MAX - 1, fname, errstr);
+# endif
+
+       fname[PATH_MAX - 1] = '\0';
+       k_fspick(dfd, fname, 0xfffffff0);
+       printf("fspick(%d<%s>, \"%s\", %s) = %s\n",
+              dfd, path, fname, "0xfffffff0 /* FSPICK_??? */", errstr);
+
+       k_fspick(-1, efault, 0xf);
+#  ifndef PATH_TRACING
+       printf("fspick(-1, %p, %s) = %s\n",
+              efault,
+              "FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
+              "|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
+              errstr);
+#  endif
+
+       k_fspick(-1, empty, -1);
+#  ifndef PATH_TRACING
+       printf("fspick(-1, \"\", %s|0xfffffff0) = %s\n",
+              "FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW"
+              "|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH",
+              errstr);
+#  endif
+
+       if (k_fspick(-1, path, 0) < 0)
+               printf("fspick(-1, \"%s\", 0) = %s\n",
+                      path, errstr);
+       else
+               printf("fspick(-1, \"%s\", 0) = %s<%s>\n",
+                      path, errstr, path);
+
+       if (k_fspick(dfd, empty, 8) < 0)
+               printf("fspick(%d<%s>, \"\", %s) = %s\n",
+                      dfd, path, "FSPICK_EMPTY_PATH", errstr);
+       else
+               printf("fspick(%d<%s>, \"\", %s) = %s<%s>\n",
+                      dfd, path, "FSPICK_EMPTY_PATH", errstr, path);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fspick")
+
+#endif
index 4e80b203c23c72d9824d529d8fb36ac7c384fc0d..7c50af8e9222ba08454a500ef7b311df47e7430a 100644 (file)
@@ -72,6 +72,8 @@ fsconfig      -s300 -y
 fsconfig-P     -s300 -y -P /dev/full -e trace=fsconfig
 fsmount        -a18 -y
 fsopen -a35
+fspick -a27 -y
+fspick-P       -a27 -y -P /dev/full -e trace=fspick
 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 e58f2941799adeba042ac8e7c8cd5d0c2308acdf..c4081c77c4c462cb0e50f162ce2f8c4c57f4d53a 100755 (executable)
@@ -75,6 +75,8 @@ fsconfig
 fsconfig-P
 fsmount
 fsopen
+fspick
+fspick-P
 fstat
 fstat-Xabbrev
 fstat-Xraw
diff --git a/xlat/fspick_flags.in b/xlat/fspick_flags.in
new file mode 100644 (file)
index 0000000..52ed035
--- /dev/null
@@ -0,0 +1,4 @@
+FSPICK_CLOEXEC         0x01
+FSPICK_SYMLINK_NOFOLLOW        0x02
+FSPICK_NO_AUTOMOUNT    0x04
+FSPICK_EMPTY_PATH      0x08