2 * Check decoding of fanotify_mark syscall.
4 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
6 * Copyright (c) 2015-2018 The strace developers.
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <asm/unistd.h>
16 #if defined HAVE_SYS_FANOTIFY_H && defined HAVE_FANOTIFY_MARK && \
17 defined __NR_fanotify_mark
22 # include <sys/fanotify.h>
25 # define str_fan_mark_add "0x1"
26 # define str_fan_modify_ondir "0x40000002"
27 # define str_at_fdcwd "-100"
29 # define str_fan_mark_add "0x1 /* FAN_MARK_ADD */"
30 # define str_fan_modify_ondir "0x40000002 /* FAN_MODIFY|FAN_ONDIR */"
31 # define str_at_fdcwd "-100 /* AT_FDCWD */"
33 # define str_fan_mark_add "FAN_MARK_ADD"
34 # define str_fan_modify_ondir "FAN_MODIFY|FAN_ONDIR"
35 # define str_at_fdcwd "AT_FDCWD"
38 /* Performs fanotify_mark call via the syscall interface. */
40 do_call(kernel_ulong_t fd, kernel_ulong_t flags, const char *flags_str,
41 uint64_t mask, const char *mask_str, kernel_ulong_t dirfd,
42 const char *dirfd_str, kernel_ulong_t path, const char *path_str)
46 rc = syscall(__NR_fanotify_mark, fd, flags,
47 # if (LONG_MAX > INT_MAX) \
48 || (defined __x86_64__ && defined __ILP32__) \
49 || defined LINUX_MIPSN32
52 /* arch/parisc/kernel/sys_parisc32.c, commit ab8a261b */
54 LL_VAL_TO_PAIR((mask << 32) | (mask >> 32)),
61 printf("fanotify_mark(%d, %s, %s, %s, %s) = %s\n",
62 (int) fd, flags_str, mask_str, dirfd_str, path_str,
76 #define STR16 "0123456789abcdef"
77 #define STR64 STR16 STR16 STR16 STR16
86 static const kernel_ulong_t fds[] = {
87 (kernel_ulong_t) 0xdeadfeed12345678ULL,
89 (kernel_ulong_t) 0xdeb0d1edffffffffULL,
91 static const struct strval flags[] = {
92 { F8ILL_KULONG_MASK, "0" },
93 { (kernel_ulong_t) 0xdec0deddefaced00ULL,
99 { (kernel_ulong_t) 0xda7a105700000040ULL,
103 "0x40 /* FAN_MARK_IGNORED_SURV_MODIFY */"
105 "FAN_MARK_IGNORED_SURV_MODIFY"
108 { (kernel_ulong_t) 0xbadc0deddeadfeedULL,
109 #if XLAT_RAW || XLAT_VERBOSE
116 "FAN_MARK_ADD|FAN_MARK_DONT_FOLLOW|FAN_MARK_ONLYDIR|"
117 "FAN_MARK_IGNORED_MASK|FAN_MARK_IGNORED_SURV_MODIFY|"
118 "FAN_MARK_FLUSH|0xdeadfe00"
125 static const struct strval64 masks[] = {
127 { 0xdeadfeedfacebeefULL,
128 #if XLAT_RAW || XLAT_VERBOSE
135 "FAN_ACCESS|FAN_MODIFY|FAN_CLOSE_WRITE|FAN_OPEN|"
136 "FAN_ACCESS_PERM|FAN_ONDIR|FAN_EVENT_ON_CHILD|"
143 { ARG_ULL_STR(0xffffffffb7fcbfc4)
149 static const struct strval dirfds[] = {
150 { (kernel_ulong_t) 0xfacefeed00000001ULL, "1" },
151 { (kernel_ulong_t) 0xdec0ded0ffffffffULL,
160 { (kernel_ulong_t) 0xbadfacedffffff9cULL, str_at_fdcwd },
161 { (kernel_ulong_t) 0xdefaced1beeff00dULL, "-1091571699" },
163 static const char str64[] = STR64;
165 static char bogus_path1_addr[sizeof("0x") + sizeof(void *) * 2];
166 static char bogus_path1_after_addr[sizeof("0x") + sizeof(void *) * 2];
168 char *bogus_path1 = tail_memdup(str64, PATH1_SIZE);
169 char *bogus_path2 = tail_memdup(str64, sizeof(str64));
171 struct strval paths[] = {
172 { (kernel_ulong_t) 0, "NULL" },
173 { (kernel_ulong_t) (uintptr_t) (bogus_path1 + PATH1_SIZE),
174 bogus_path1_after_addr },
175 { (kernel_ulong_t) (uintptr_t) bogus_path1, bogus_path1_addr },
176 { (kernel_ulong_t) (uintptr_t) bogus_path2, "\"" STR64 "\"" },
187 snprintf(bogus_path1_addr, sizeof(bogus_path1_addr), "%p", bogus_path1);
188 snprintf(bogus_path1_after_addr, sizeof(bogus_path1_after_addr), "%p",
189 bogus_path1 + PATH1_SIZE);
191 rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
193 printf("fanotify_mark(-1, %s, %s, %s, \".\") = %s\n",
194 str_fan_mark_add, str_fan_modify_ondir, str_at_fdcwd,
197 for (i = 0; i < ARRAY_SIZE(fds); i++) {
198 for (j = 0; j < ARRAY_SIZE(flags); j++) {
199 for (k = 0; k < ARRAY_SIZE(masks); k++) {
200 for (l = 0; l < ARRAY_SIZE(dirfds); l++) {
201 for (m = 0; m < ARRAY_SIZE(paths); m++)
216 puts("+++ exited with 0 +++");
222 SKIP_MAIN_UNDEFINED("HAVE_SYS_FANOTIFY_H && HAVE_FANOTIFY_MARK && "
223 "__NR_fanotify_mark")