From 363c347676edc07826f6320e55950e253fa33554 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 25 Jun 2019 11:32:26 +0000 Subject: [PATCH] Implement decoding of move_mount syscall ... introduced by Linux kernel commits v5.2-rc1~141^2~8, v5.2-rc1~20^2~1, and v5.2-rc1~20^2. * move_mount.c: New file. * Makefile.am (strace_SOURCES): Add it. * pathtrace.c (pathtrace_match_set): Add SEN_move_mount. * xlat/move_mount_flags.in: New file. * linux/syscallent-common.h [BASE_NR + 429]: Wire up move_mount. * NEWS: Mention this change. * tests/move_mount.c: New file. * tests/move_mount-P.c: Likewise. * tests/gen_tests.in (move_mount, move_mount-P): New entries. * tests/pure_executables.list: Add move_mount and move_mount-P. * tests/.gitignore: Likewise. --- Makefile.am | 1 + NEWS | 2 +- linux/syscallent-common.h | 1 + move_mount.c | 24 +++++++++ pathtrace.c | 1 + tests/.gitignore | 2 + tests/gen_tests.in | 2 + tests/move_mount-P.c | 2 + tests/move_mount.c | 103 ++++++++++++++++++++++++++++++++++++ tests/pure_executables.list | 2 + xlat/move_mount_flags.in | 6 +++ 11 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 move_mount.c create mode 100644 tests/move_mount-P.c create mode 100644 tests/move_mount.c create mode 100644 xlat/move_mount_flags.in diff --git a/Makefile.am b/Makefile.am index 4c56935a..d4f9e1a8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,6 +186,7 @@ strace_SOURCES = \ mmap_notify.h \ mmsghdr.c \ mount.c \ + move_mount.c \ mpers_type.h \ mq.c \ msghdr.c \ diff --git a/NEWS b/NEWS index 8a21b789..34bea818 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ Noteworthy changes in release ?.? (????-??-??) ============================================== * Improvements - * Implemented decoding of open_tree syscall. + * Implemented decoding of open_tree and move_mount syscalls. * Enhanced decoding of clone syscall. * Updated lists of AT_*, AUDIT_*, CLONE_*, ETH_*, KEY_*, KVM_*, TIPC_*, and V4L2_* constants. diff --git a/linux/syscallent-common.h b/linux/syscallent-common.h index 6d404d2d..6844404f 100644 --- a/linux/syscallent-common.h +++ b/linux/syscallent-common.h @@ -13,3 +13,4 @@ [BASE_NR + 426] = { 6, TD|TS, SEN(io_uring_enter), "io_uring_enter" }, [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" }, diff --git a/move_mount.c b/move_mount.c new file mode 100644 index 00000000..b299b73c --- /dev/null +++ b/move_mount.c @@ -0,0 +1,24 @@ +/* + * 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/move_mount_flags.h" + +SYS_FUNC(move_mount) +{ + print_dirfd(tcp, tcp->u_arg[0]); + printpath(tcp, tcp->u_arg[1]); + tprints(", "); + print_dirfd(tcp, tcp->u_arg[2]); + printpath(tcp, tcp->u_arg[3]); + tprints(", "); + printflags(move_mount_flags, tcp->u_arg[4], "MOVE_MOUNT_???"); + return RVAL_DECODED; +} diff --git a/pathtrace.c b/pathtrace.c index 53ac8031..23667798 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -223,6 +223,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set) return upathmatch(tcp, tcp->u_arg[1], set); case SEN_linkat: + case SEN_move_mount: case SEN_renameat2: case SEN_renameat: /* fd, path, fd, path */ diff --git a/tests/.gitignore b/tests/.gitignore index e51895ce..72340606 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -265,6 +265,8 @@ mount mount-Xabbrev mount-Xraw mount-Xverbose +move_mount +move_mount-P move_pages move_pages-Xabbrev move_pages-Xraw diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 45fc5e5a..58afdc4e 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -223,6 +223,8 @@ mount -a33 mount-Xabbrev -a33 -e trace=mount -Xabbrev mount-Xraw -a33 -e trace=mount -Xraw mount-Xverbose -a33 -e trace=mount -Xverbose +move_mount -y +move_mount-P -y -P /dev/full -e trace=move_mount move_pages -s3 move_pages-Xabbrev -s3 -e trace=move_pages -Xabbrev move_pages-Xraw -s3 -a36 -e trace=move_pages -Xraw diff --git a/tests/move_mount-P.c b/tests/move_mount-P.c new file mode 100644 index 00000000..1e1cd5c8 --- /dev/null +++ b/tests/move_mount-P.c @@ -0,0 +1,2 @@ +#define PATH_TRACING +#include "move_mount.c" diff --git a/tests/move_mount.c b/tests/move_mount.c new file mode 100644 index 00000000..6df39491 --- /dev/null +++ b/tests/move_mount.c @@ -0,0 +1,103 @@ +/* + * Check decoding of move_mount 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_move_mount + +# include +# include +# include +# include +# include + +static const char *errstr; + +static long +k_move_mount(const unsigned int from_dfd, const void *from_fname, + const unsigned int to_dfd, const void *to_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 | from_dfd; + const kernel_ulong_t arg2 = (uintptr_t) from_fname; + const kernel_ulong_t arg3 = fill | to_dfd; + const kernel_ulong_t arg4 = (uintptr_t) to_fname; + const kernel_ulong_t arg5 = fill | flags; + const long rc = syscall(__NR_move_mount, + arg1, arg2, arg3, arg4, arg5, 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)); + const void *const efault = path + sizeof(path_full); + const char *const empty = efault - 1; + char *const fname = tail_alloc(PATH_MAX); + 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_move_mount(-1, 0, -100, efault, 0); +# ifndef PATH_TRACING + printf("move_mount(-1, NULL, AT_FDCWD, %p, 0) = %s\n", efault, errstr); +# endif + + k_move_mount(-100, efault, -1, 0, 0); +# ifndef PATH_TRACING + printf("move_mount(AT_FDCWD, %p, -1, NULL, 0) = %s\n", efault, errstr); +# endif + + k_move_mount(dfd, fname, -100, empty, 1); + printf("move_mount(%d<%s>, \"%.*s\"..., AT_FDCWD, \"\", %s) = %s\n", + dfd, path, (int) PATH_MAX - 1, fname, "MOVE_MOUNT_F_SYMLINKS", errstr); + + k_move_mount(-100, empty, dfd, fname, 0x10); + printf("move_mount(AT_FDCWD, \"\", %d<%s>, \"%.*s\"..., %s) = %s\n", + dfd, path, (int) PATH_MAX - 1, fname, "MOVE_MOUNT_T_SYMLINKS", errstr); + +# define f_flags_str "MOVE_MOUNT_F_SYMLINKS|MOVE_MOUNT_F_AUTOMOUNTS|MOVE_MOUNT_F_EMPTY_PATH" + fname[PATH_MAX - 1] = '\0'; + k_move_mount(dfd, fname, -100, empty, 7); + printf("move_mount(%d<%s>, \"%s\", AT_FDCWD, \"\", %s) = %s\n", + dfd, path, fname, f_flags_str, errstr); + +# define t_flags_str "MOVE_MOUNT_T_SYMLINKS|MOVE_MOUNT_T_AUTOMOUNTS|MOVE_MOUNT_T_EMPTY_PATH" + k_move_mount(-100, empty, dfd, fname, 0x70); + printf("move_mount(AT_FDCWD, \"\", %d<%s>, \"%s\", %s) = %s\n", + dfd, path, fname, t_flags_str, errstr); + + k_move_mount(-1, path, -100, empty, 0x77); + printf("move_mount(-1, \"%s\", AT_FDCWD, \"\", %s) = %s\n", + path, f_flags_str "|" t_flags_str, errstr); + + k_move_mount(-100, empty, -1, path, -1); + printf("move_mount(AT_FDCWD, \"\", -1, \"%s\", %s) = %s\n", + path, f_flags_str "|" t_flags_str "|0xffffff88", errstr); + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_move_mount") + +#endif diff --git a/tests/pure_executables.list b/tests/pure_executables.list index e6e99abe..6e57eda5 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -223,6 +223,8 @@ mount mount-Xabbrev mount-Xraw mount-Xverbose +move_mount +move_mount-P move_pages move_pages-Xabbrev move_pages-Xraw diff --git a/xlat/move_mount_flags.in b/xlat/move_mount_flags.in new file mode 100644 index 00000000..441387c4 --- /dev/null +++ b/xlat/move_mount_flags.in @@ -0,0 +1,6 @@ +MOVE_MOUNT_F_SYMLINKS 0x01 +MOVE_MOUNT_F_AUTOMOUNTS 0x02 +MOVE_MOUNT_F_EMPTY_PATH 0x04 +MOVE_MOUNT_T_SYMLINKS 0x10 +MOVE_MOUNT_T_AUTOMOUNTS 0x20 +MOVE_MOUNT_T_EMPTY_PATH 0x40 -- 2.40.0