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
41 # include <sys/fanotify.h>
43 /* Performs fanotify_mark call via the syscall interface. */
45 do_call(kernel_ulong_t fd, kernel_ulong_t flags, const char *flags_str,
46 uint64_t mask, const char *mask_str, kernel_ulong_t dirfd,
47 const char *dirfd_str, kernel_ulong_t path, const char *path_str)
51 rc = syscall(__NR_fanotify_mark, fd, flags,
52 # if (LONG_MAX > INT_MAX) \
53 || (defined __x86_64__ && defined __ILP32__) \
54 || defined LINUX_MIPSN32
57 /* arch/parisc/kernel/sys_parisc32.c, commit ab8a261b */
59 LL_VAL_TO_PAIR((mask << 32) | (mask >> 32)),
66 printf("fanotify_mark(%d, %s, %s, %s, %s) = %s\n",
67 (int) fd, flags_str, mask_str, dirfd_str, path_str,
81 #define STR16 "0123456789abcdef"
82 #define STR64 STR16 STR16 STR16 STR16
91 static const kernel_ulong_t fds[] = {
92 (kernel_ulong_t) 0xdeadfeed12345678ULL,
93 (kernel_ulong_t) 0xffffffff00000000ULL,
94 (kernel_ulong_t) 0xdeb0d1edffffffffULL,
96 static const struct strval flags[] = {
97 { (kernel_ulong_t) 0xffffffff00000000ULL, "0" },
98 { (kernel_ulong_t) 0xdec0deddefaced00ULL,
99 "0xefaced00 /* FAN_MARK_??? */" },
100 { (kernel_ulong_t) 0xda7a105700000040ULL,
101 "FAN_MARK_IGNORED_SURV_MODIFY" },
102 { (kernel_ulong_t) 0xbadc0deddeadfeedULL,
103 "FAN_MARK_ADD|FAN_MARK_DONT_FOLLOW|FAN_MARK_ONLYDIR|"
104 "FAN_MARK_IGNORED_MASK|FAN_MARK_IGNORED_SURV_MODIFY|"
105 "FAN_MARK_FLUSH|0xdeadfe00" },
107 static const struct strval64 masks[] = {
109 { 0xdeadfeedfacebeefULL,
110 "FAN_ACCESS|FAN_MODIFY|FAN_CLOSE_WRITE|FAN_OPEN|"
111 "FAN_ACCESS_PERM|FAN_ONDIR|FAN_EVENT_ON_CHILD|"
112 "0xdeadfeedb2ccbec4" },
113 { ARG_ULL_STR(0xffffffffb7fcbfc4) " /* FAN_??? */" },
115 static const struct strval dirfds[] = {
116 { (kernel_ulong_t) 0xfacefeed00000001ULL, "1" },
117 { (kernel_ulong_t) 0xdec0ded0ffffffffULL, "FAN_NOFD" },
118 { (kernel_ulong_t) 0xbadfacedffffff9cULL, "AT_FDCWD" },
119 { (kernel_ulong_t) 0xdefaced1beeff00dULL, "-1091571699" },
121 static const char str64[] = STR64;
123 static char bogus_path1_addr[sizeof("0x") + sizeof(void *) * 2];
124 static char bogus_path1_after_addr[sizeof("0x") + sizeof(void *) * 2];
126 char *bogus_path1 = tail_memdup(str64, PATH1_SIZE);
127 char *bogus_path2 = tail_memdup(str64, sizeof(str64));
129 struct strval paths[] = {
130 { (kernel_ulong_t) 0, "NULL" },
131 { (kernel_ulong_t) (uintptr_t) (bogus_path1 + PATH1_SIZE),
132 bogus_path1_after_addr },
133 { (kernel_ulong_t) (uintptr_t) bogus_path1, bogus_path1_addr },
134 { (kernel_ulong_t) (uintptr_t) bogus_path2, "\"" STR64 "\"" },
145 snprintf(bogus_path1_addr, sizeof(bogus_path1_addr), "%p", bogus_path1);
146 snprintf(bogus_path1_after_addr, sizeof(bogus_path1_after_addr), "%p",
147 bogus_path1 + PATH1_SIZE);
149 rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
151 printf("fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY|FAN_ONDIR"
152 ", AT_FDCWD, \".\") = %s\n", sprintrc(rc));
154 for (i = 0; i < ARRAY_SIZE(fds); i++) {
155 for (j = 0; j < ARRAY_SIZE(flags); j++) {
156 for (k = 0; k < ARRAY_SIZE(masks); k++) {
157 for (l = 0; l < ARRAY_SIZE(dirfds); l++) {
158 for (m = 0; m < ARRAY_SIZE(paths); m++)
173 puts("+++ exited with 0 +++");
179 SKIP_MAIN_UNDEFINED("HAVE_SYS_FANOTIFY_H && HAVE_FANOTIFY_MARK && "
180 "__NR_fanotify_mark")