[LTP] [PATCH 3/5] syscalls/fanotify03: add FAN_OPEN_EXEC_PERM tcase support

Matthew Bobrowski mbobrowski@mbobrowski.org
Tue Jan 22 23:36:06 CET 2019


* Defined FAN_OPEN_EXEC_PERM flag in local tests header file to
  accommodate for the fact if it's not defined in system user space
  headers

* Defined new tcase's for each mark type to support new fanotify flag
  FAN_OPEN_EXEC_PERM tests

* Updated fanotify_mark failure logic to report the instance where
  FAN_OPEN_EXEC_PERM flag is not available within the kernel

Signed-off-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 13 +++++
 testcases/kernel/syscalls/fanotify/fanotify03.c | 63 +++++++++++++++++++++----
 2 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 880dea534..c77e7a4ac 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -64,6 +64,19 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #ifndef FAN_MARK_FILESYSTEM
 #define FAN_MARK_FILESYSTEM	0x00000100
 #endif
+#ifndef FAN_OPEN_EXEC_PERM
+#define FAN_OPEN_EXEC_PERM	0x00040000
+#endif
+
+/*
+ * FAN_ALL_PERM_EVENTS has been deprecated, so any new permission events
+ * are not to be added to it. To cover the instance where a new permission
+ * event is defined, we create a new macro that is to include all
+ * permission events. Any new permission events should be added to this
+ * macro.
+ */
+#define LTP_ALL_PERM_EVENTS	(FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \
+				 FAN_ACCESS_PERM)
 
 struct fanotify_mark_type {
 	unsigned int flag;
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index 3fdd1aba8..c93f7a93e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -47,12 +47,18 @@ static pid_t child_pid;
 
 static char event_buf[EVENT_BUF_LEN];
 static int support_perm_events;
+static int support_exec_events;
 
 struct event {
 	unsigned long long mask;
 	unsigned int response;
 };
 
+/*
+ * Ensure to keep the first FAN_OPEN_EXEC_PERM test case before the first
+ * MARK_TYPE(FILESYSTEM) in order to allow for correct detection between
+ * exec events not supported and filesystem marks not supported.
+ */
 static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
@@ -61,7 +67,7 @@ static struct tcase {
 	struct event event_set[EVENT_SET_MAX];
 } tcases[] = {
 	{
-		"inode mark permission events",
+		"inode mark, FAN_OPEN_PERM | FAN_ACCESS_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
@@ -71,7 +77,16 @@ static struct tcase {
 		}
 	},
 	{
-		"mount mark permission events",
+		"inode mark, FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM events",
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM, 2,
+		{
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_EXEC_PERM, FAN_DENY}
+		}
+	},
+	{
+		"mount mark, FAN_OPEN_PERM | FAN_ACCESS_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
@@ -81,7 +96,16 @@ static struct tcase {
 		}
 	},
 	{
-		"filesystem mark permission events",
+		"mount mark, FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM events",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM, 2,
+		{
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_EXEC_PERM, FAN_DENY}
+		}
+	},
+	{
+		"filesystem mark, FAN_OPEN_PERM | FAN_ACCESS_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
@@ -89,7 +113,16 @@ static struct tcase {
 			{FAN_ACCESS_PERM, FAN_DENY},
 			{FAN_OPEN_PERM, FAN_DENY}
 		}
-	}
+	},
+	{
+		"filesystem mark, FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM events",
+		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+		FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM, 2,
+		{
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_EXEC_PERM, FAN_DENY}
+		}
+	},
 };
 
 static void generate_events(void)
@@ -183,8 +216,15 @@ static int setup_mark(unsigned int n)
 	for (; i < ARRAY_SIZE(files); i++) {
 		if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag,
 				  tc->mask, AT_FDCWD, files[i]) < 0) {
-			if (errno == EINVAL && 
-				mark->flag == FAN_MARK_FILESYSTEM) {
+			if (errno == EINVAL &&
+				(tc->mask & FAN_OPEN_EXEC_PERM && 
+				 !support_exec_events)) {
+				tst_res(TCONF,
+					"FAN_OPEN_EXEC_PERM not supported in "
+					"kernel?");
+				return -1;
+			} else if (errno == EINVAL &&
+					mark->flag == FAN_MARK_FILESYSTEM) {
 				tst_res(TCONF,
 					"FAN_MARK_FILESYSTEM not supported in "
 					"kernel?");
@@ -195,17 +235,20 @@ static int setup_mark(unsigned int n)
 					"not configured in kernel?");
 			} else {
 				tst_brk(TBROK | TERRNO,
-					"fanotify_mark (%d, FAN_MARK_ADD | %s, "
+					"fanotify_mark(%d, FAN_MARK_ADD | %s, "
 					"FAN_ACCESS_PERM | FAN_OPEN_PERM, "
 					"AT_FDCWD, %s) failed.",
 					fd_notify, mark->name, fname);
 			}
 		} else {
 			/*
-			 * To distinguish between perm event not supported and
-			 * filesystem mark not supported.
+			 * To distinguish between perm not supported, exec
+			 * events not supported and filesystem mark not
+			 * supported.
 			 */
 			support_perm_events = 1;
+			if (tc->mask & FAN_OPEN_EXEC_PERM)
+				support_exec_events = 1;
 		}
 	}
 
@@ -274,7 +317,7 @@ static void test_fanotify(unsigned int n)
 		}
 
 		/* Write response to the permission event */
-		if (event_set[test_num].mask & FAN_ALL_PERM_EVENTS) {
+		if (event_set[test_num].mask & LTP_ALL_PERM_EVENTS) {
 			struct fanotify_response resp;
 
 			resp.fd = event->fd;
-- 
2.16.4


-- 
Matthew Bobrowski


More information about the ltp mailing list