From: Dmitry V. Levin Date: Sat, 29 Jun 2019 17:38:25 +0000 (+0000) Subject: Implement decoding of fspick syscall X-Git-Tag: v5.2~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4f97019e33313b8667013273ba6db2717a492de;p=strace 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. --- diff --git a/Makefile.am b/Makefile.am index 4f0eb642..628e7e90 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 60d08848..06b5db9b 100644 --- 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 index 00000000..3d003796 --- /dev/null +++ b/fspick.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "defs.h" +#ifdef HAVE_LINUX_MOUNT_H +# include +#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; +} diff --git a/linux/syscallent-common.h b/linux/syscallent-common.h index af96dc7a..d753a87c 100644 --- a/linux/syscallent-common.h +++ b/linux/syscallent-common.h @@ -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" }, diff --git a/pathtrace.c b/pathtrace.c index a96b9ff6..aba621b7 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -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: diff --git a/tests/.gitignore b/tests/.gitignore index 14f50802..178e1076 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -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 index 00000000..f3d41eb3 --- /dev/null +++ b/tests/fspick-P.c @@ -0,0 +1,2 @@ +#define PATH_TRACING +#include "fspick.c" diff --git a/tests/fspick.c b/tests/fspick.c new file mode 100644 index 00000000..e794458f --- /dev/null +++ b/tests/fspick.c @@ -0,0 +1,110 @@ +/* + * Check decoding of fspick syscall. + * + * Copyright (c) 2019 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include +#include "scno.h" + +#ifdef __NR_fspick + +# include +# include +# include +# include +# include + +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 diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 4e80b203..7c50af8e 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -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 diff --git a/tests/pure_executables.list b/tests/pure_executables.list index e58f2941..c4081c77 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -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 index 00000000..52ed0350 --- /dev/null +++ b/xlat/fspick_flags.in @@ -0,0 +1,4 @@ +FSPICK_CLOEXEC 0x01 +FSPICK_SYMLINK_NOFOLLOW 0x02 +FSPICK_NO_AUTOMOUNT 0x04 +FSPICK_EMPTY_PATH 0x08