summaryrefslogtreecommitdiff
path: root/tests/fanotify_mark.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fanotify_mark.c')
-rw-r--r--tests/fanotify_mark.c121
1 files changed, 77 insertions, 44 deletions
diff --git a/tests/fanotify_mark.c b/tests/fanotify_mark.c
index bd14f4790..15eab3e01 100644
--- a/tests/fanotify_mark.c
+++ b/tests/fanotify_mark.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
* Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
- * Copyright (c) 2015-2020 The strace developers.
+ * Copyright (c) 2015-2021 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
@@ -21,6 +21,8 @@
# include <unistd.h>
# include <sys/fanotify.h>
+# include "secontext.h"
+
# if XLAT_RAW
# define str_fan_mark_add "0x1"
# define str_fan_modify_ondir "0x40000002"
@@ -35,6 +37,7 @@
# define str_at_fdcwd "AT_FDCWD"
# endif
+# ifndef TEST_SECONTEXT
/* Performs fanotify_mark call via the syscall interface. */
static void
do_call(kernel_ulong_t fd, kernel_ulong_t flags, const char *flags_str,
@@ -44,18 +47,18 @@ do_call(kernel_ulong_t fd, kernel_ulong_t flags, const char *flags_str,
long rc;
rc = syscall(__NR_fanotify_mark, fd, flags,
-# if (LONG_MAX > INT_MAX) \
- || (defined __x86_64__ && defined __ILP32__) \
- || defined LINUX_MIPSN32
+# if (LONG_MAX > INT_MAX) \
+ || (defined __x86_64__ && defined __ILP32__) \
+ || defined LINUX_MIPSN32
mask,
-# else
+# else
/* arch/parisc/kernel/sys_parisc32.c, commit ab8a261b */
-# ifdef HPPA
+# ifdef HPPA
LL_VAL_TO_PAIR((mask << 32) | (mask >> 32)),
-# else
+# else
LL_VAL_TO_PAIR(mask),
+# endif
# endif
-# endif
dirfd, path);
printf("fanotify_mark(%d, %s, %s, %s, %s) = %s\n",
@@ -68,12 +71,14 @@ struct strval {
const char *str;
};
-# define STR16 "0123456789abcdef"
-# define STR64 STR16 STR16 STR16 STR16
+# define STR16 "0123456789abcdef"
+# define STR64 STR16 STR16 STR16 STR16
+# endif /* !TEST_SECONTEXT */
int
main(void)
{
+# ifndef TEST_SECONTEXT
enum {
PATH1_SIZE = 64,
};
@@ -87,47 +92,47 @@ main(void)
{ F8ILL_KULONG_MASK, "0" },
{ (kernel_ulong_t) 0xdec0deddefacec00ULL,
"0xefacec00"
-# if !XLAT_RAW
+# if !XLAT_RAW
" /* FAN_MARK_??? */"
-# endif
+# endif
},
{ (kernel_ulong_t) 0xda7a105700000040ULL,
-# if XLAT_RAW
+# if XLAT_RAW
"0x40"
-# elif XLAT_VERBOSE
+# elif XLAT_VERBOSE
"0x40 /* FAN_MARK_IGNORED_SURV_MODIFY */"
-# else
+# else
"FAN_MARK_IGNORED_SURV_MODIFY"
-# endif
+# endif
},
{ (kernel_ulong_t) 0xbadc0deddeadffffULL,
-# if XLAT_RAW || XLAT_VERBOSE
+# if XLAT_RAW || XLAT_VERBOSE
"0xdeadffff"
-# endif
-# if XLAT_VERBOSE
+# endif
+# if XLAT_VERBOSE
" /* "
-# endif
-# if !XLAT_RAW
+# endif
+# if !XLAT_RAW
"FAN_MARK_ADD|FAN_MARK_REMOVE|FAN_MARK_DONT_FOLLOW|"
"FAN_MARK_ONLYDIR|FAN_MARK_MOUNT|FAN_MARK_IGNORED_MASK|"
"FAN_MARK_IGNORED_SURV_MODIFY|FAN_MARK_FLUSH|"
"FAN_MARK_FILESYSTEM|0xdeadfe00"
-# endif
-# if XLAT_VERBOSE
+# endif
+# if XLAT_VERBOSE
" */"
-# endif
+# endif
},
};
static const struct strval64 masks[] = {
{ ARG_ULL_STR(0) },
{ 0xdeadfeedffffffffULL,
-# if XLAT_RAW || XLAT_VERBOSE
+# if XLAT_RAW || XLAT_VERBOSE
"0xdeadfeedffffffff"
-# endif
-# if XLAT_VERBOSE
+# endif
+# if XLAT_VERBOSE
" /* "
-# endif
-# if !XLAT_RAW
+# endif
+# if !XLAT_RAW
"FAN_ACCESS|"
"FAN_MODIFY|"
"FAN_ATTRIB|"
@@ -149,27 +154,27 @@ main(void)
"FAN_ONDIR|"
"FAN_EVENT_ON_CHILD|"
"0xdeadfeedb7f0a000"
-# endif
-# if XLAT_VERBOSE
+# endif
+# if XLAT_VERBOSE
" */"
-# endif
+# endif
},
{ ARG_ULL_STR(0xffffffffb7f0a000)
-# if !XLAT_RAW
+# if !XLAT_RAW
" /* FAN_??? */"
-# endif
+# endif
},
};
static const struct strval dirfds[] = {
{ (kernel_ulong_t) 0xfacefeed00000001ULL, "1" },
{ (kernel_ulong_t) 0xdec0ded0ffffffffULL,
-# if XLAT_RAW
+# if XLAT_RAW
"-1"
-# elif XLAT_VERBOSE
+# elif XLAT_VERBOSE
"-1 /* FAN_NOFD */"
-# else
+# else
"FAN_NOFD"
-# endif
+# endif
},
{ (kernel_ulong_t) 0xbadfacedffffff9cULL, str_at_fdcwd },
{ (kernel_ulong_t) 0xdefaced1beeff00dULL, "-1091571699" },
@@ -202,12 +207,6 @@ main(void)
snprintf(bogus_path1_after_addr, sizeof(bogus_path1_after_addr), "%p",
bogus_path1 + PATH1_SIZE);
- rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
- -100, ".");
- printf("fanotify_mark(-1, %s, %s, %s, \".\") = %s\n",
- str_fan_mark_add, str_fan_modify_ondir, str_at_fdcwd,
- sprintrc(rc));
-
for (i = 0; i < ARRAY_SIZE(fds); i++) {
for (j = 0; j < ARRAY_SIZE(flags); j++) {
for (k = 0; k < ARRAY_SIZE(masks); k++) {
@@ -226,6 +225,40 @@ main(void)
}
}
}
+# else /* TEST_SECONTEXT */
+ int rc;
+# endif
+ /*
+ * Test with AT_FDCWD.
+ */
+
+ char *my_secontext = SECONTEXT_PID_MY();
+ char path[] = ".";
+ char *path_secontext = SECONTEXT_FILE(path);
+
+ rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
+ -100, path);
+ printf("%s%s(-1, %s, %s, %s, \"%s\"%s) = %s\n",
+ my_secontext, "fanotify_mark",
+ str_fan_mark_add, str_fan_modify_ondir, str_at_fdcwd,
+ path, path_secontext,
+ sprintrc(rc));
+
+ /*
+ * Test with dirfd.
+ */
+
+ int cwd_fd = get_dir_fd(".");
+ char *cwd_secontext = SECONTEXT_FILE(".");
+
+ rc = fanotify_mark(-1, FAN_MARK_ADD, FAN_MODIFY | FAN_ONDIR,
+ cwd_fd, path);
+ printf("%s%s(-1, %s, %s, %d%s, \"%s\"%s) = %s\n",
+ my_secontext, "fanotify_mark",
+ str_fan_mark_add, str_fan_modify_ondir,
+ cwd_fd, cwd_secontext,
+ path, path_secontext,
+ sprintrc(rc));
puts("+++ exited with 0 +++");
return 0;