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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <asm/unistd.h>
35 #if defined HAVE_SYS_FANOTIFY_H && defined HAVE_FANOTIFY_MARK && \
36 defined __NR_fanotify_mark
42 # include <sys/fanotify.h>
44 # include "kernel_types.h"
46 /* Performs fanotify_mark call via the syscall interface. */
48 do_call(kernel_ulong_t fd, kernel_ulong_t flags, const char *flags_str,
49 uint64_t mask, const char *mask_str, kernel_ulong_t dirfd,
50 const char *dirfd_str, kernel_ulong_t path, const char *path_str)
54 rc = syscall(__NR_fanotify_mark, fd, flags,
55 # if (LONG_MAX > INT_MAX) \
56 || (defined __x86_64__ && defined __ILP32__) \
57 || defined LINUX_MIPSN32
60 /* arch/parisc/kernel/sys_parisc32.c, commit ab8a261b */
62 LL_VAL_TO_PAIR((mask << 32) | (mask >> 32)),
69 printf("fanotify_mark(%d, %s, %s, %s, %s) = %s\n",
70 (int) fd, flags_str, mask_str, dirfd_str, path_str,
84 #define STR16 "0123456789abcdef"
85 #define STR64 STR16 STR16 STR16 STR16
94 static const kernel_ulong_t fds[] = {
95 (kernel_ulong_t) 0xdeadfeed12345678ULL,
96 (kernel_ulong_t) 0xffffffff00000000ULL,
97 (kernel_ulong_t) 0xdeb0d1edffffffffULL,
99 static const struct strval flags[] = {
100 { (kernel_ulong_t) 0xffffffff00000000ULL, "0" },
101 { (kernel_ulong_t) 0xdec0deddefaced00ULL,
102 "0xefaced00 /* FAN_MARK_??? */" },
103 { (kernel_ulong_t) 0xda7a105700000040ULL,
104 "FAN_MARK_IGNORED_SURV_MODIFY" },
105 { (kernel_ulong_t) 0xbadc0deddeadfeedULL,
106 "FAN_MARK_ADD|FAN_MARK_DONT_FOLLOW|FAN_MARK_ONLYDIR|"
107 "FAN_MARK_IGNORED_MASK|FAN_MARK_IGNORED_SURV_MODIFY|"
108 "FAN_MARK_FLUSH|0xdeadfe00" },
110 static const struct strval64 masks[] = {
112 { 0xdeadfeedfacebeefULL,
113 "FAN_ACCESS|FAN_MODIFY|FAN_CLOSE_WRITE|FAN_OPEN|"
114 "FAN_ACCESS_PERM|FAN_ONDIR|FAN_EVENT_ON_CHILD|"
115 "0xdeadfeedb2ccbec4" },
116 { ARG_ULL_STR(0xffffffffb7fcbfc4) " /* FAN_??? */" },
118 static const struct strval dirfds[] = {
119 { (kernel_ulong_t) 0xfacefeed00000001ULL, "1" },
120 { (kernel_ulong_t) 0xdec0ded0ffffffffULL, "FAN_NOFD" },
121 { (kernel_ulong_t) 0xbadfacedffffff9cULL, "AT_FDCWD" },
122 { (kernel_ulong_t) 0xdefaced1beeff00dULL, "-1091571699" },
124 static const char str64[] = STR64;
126 static char bogus_path1_addr[sizeof("0x") + sizeof(void *) * 2];
127 static char bogus_path1_after_addr[sizeof("0x") + sizeof(void *) * 2];
129 char *bogus_path1 = tail_memdup(str64, PATH1_SIZE);
130 char *bogus_path2 = tail_memdup(str64, sizeof(str64));
132 struct strval paths[] = {
133 { (kernel_ulong_t) 0, "NULL" },
134 { (kernel_ulong_t) (uintptr_t) (bogus_path1 + PATH1_SIZE),
135 bogus_path1_after_addr },
136 { (kernel_ulong_t) (uintptr_t) bogus_path1, bogus_path1_addr },
137 { (kernel_ulong_t) (uintptr_t) bogus_path2, "\"" STR64 "\"" },
148 snprintf(bogus_path1_addr, sizeof(bogus_path1_addr), "%p", bogus_path1);
149 snprintf(bogus_path1_after_addr, sizeof(bogus_path1_after_addr), "%p",
150 bogus_path1 + PATH1_SIZE);
152 rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
154 printf("fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY|FAN_ONDIR"
155 ", AT_FDCWD, \".\") = %s\n", sprintrc(rc));
157 for (i = 0; i < ARRAY_SIZE(fds); i++) {
158 for (j = 0; j < ARRAY_SIZE(flags); j++) {
159 for (k = 0; k < ARRAY_SIZE(masks); k++) {
160 for (l = 0; l < ARRAY_SIZE(dirfds); l++) {
161 for (m = 0; m < ARRAY_SIZE(paths); m++)
176 puts("+++ exited with 0 +++");
182 SKIP_MAIN_UNDEFINED("HAVE_SYS_FANOTIFY_H && HAVE_FANOTIFY_MARK && "
183 "__NR_fanotify_mark")