From 7ab2b642f8f5795afe90ac857fdc64192ec15b87 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 26 Jun 2019 08:00:39 +0000 Subject: [PATCH] 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. --- Makefile.am | 1 + NEWS | 2 +- fsopen.c | 20 +++++++++++ linux/syscallent-common.h | 1 + pathtrace.c | 1 + tests/.gitignore | 1 + tests/fsopen.c | 68 +++++++++++++++++++++++++++++++++++++ tests/gen_tests.in | 1 + tests/pure_executables.list | 1 + xlat/fsopen_flags.in | 1 + 10 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 fsopen.c create mode 100644 tests/fsopen.c create mode 100644 xlat/fsopen_flags.in diff --git a/Makefile.am b/Makefile.am index d4f9e1a8..9fe5055a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 34bea818..75bed509 100644 --- 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 index 00000000..1bae2c53 --- /dev/null +++ b/fsopen.c @@ -0,0 +1,20 @@ +/* + * 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/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; +} diff --git a/linux/syscallent-common.h b/linux/syscallent-common.h index 6844404f..abad8805 100644 --- a/linux/syscallent-common.h +++ b/linux/syscallent-common.h @@ -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" }, diff --git a/pathtrace.c b/pathtrace.c index 23667798..6de690e9 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -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: diff --git a/tests/.gitignore b/tests/.gitignore index 72340606..c0d5bd7b 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -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 index 00000000..2b0baf74 --- /dev/null +++ b/tests/fsopen.c @@ -0,0 +1,68 @@ +/* + * Check decoding of fsopen 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_fsopen + +# include +# include +# include + +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 diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 58afdc4e..f2377556 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -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 diff --git a/tests/pure_executables.list b/tests/pure_executables.list index 6e57eda5..9f57ad56 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -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 index 00000000..ce01ddf0 --- /dev/null +++ b/xlat/fsopen_flags.in @@ -0,0 +1 @@ +FSOPEN_CLOEXEC 1 -- 2.40.0