Skip to contentSkip to conversation

Add test support for the new fanotify FAN_REPORT_PIDFD feature

PATCH In review Matthew Bobrowski via ltp 3 participants 8 messages Nov 9, 2021 – Nov 16, 2021

lore
Share & tools
lore
#0 lore raw

v3 cover Add test support for the new fanotify FAN_REPORT_PIDFD feature

This is a follow up series of the previous series [0] that I had posted through which factors in Amir's recommendation around the splitting of the new macro helper into a separate patch.

Apart from that, there's no difference.

[0] https://lore.kernel.org/ltp/[email protected]/

Matthew Bobrowski (3):
syscalls/fanotify: Add a helper macro which checks for the presence of
specific fanotify initialization flag(s)
syscalls/fanotify20: add new test for FAN_REPORT_PIDFD syscalls/fanotify21: test returned pidfd from fanotify in
FAN_REPORT_PIDFD mode

 testcases/kernel/syscalls/fanotify/.gitignore |   2 +
 testcases/kernel/syscalls/fanotify/fanotify.h |  26 ++
 .../kernel/syscalls/fanotify/fanotify20.c     | 128 ++++++++
 .../kernel/syscalls/fanotify/fanotify21.c     | 306 ++++++++++++++++++
 4 files changed, 462 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify20.c
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify21.c
Signature · 6 lines
2.34.0.rc0.344.g81b53c2807-goog

/M

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v3 1/3 syscalls/fanotify: Add a helper macro which checks for the presence of specific fanotify initialization flag(s)

This is a trivial macro that can be used throughout fanotify tests to check whether the underlying running kernel supports the supplied fanotify initialization flag(s).

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 5 +++++
 1 file changed, 5 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify.h +5 -0
index a2be18338..e2db3c6f5 100644
@@ -352,6 +352,11 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str,
 		fanotify_init_flags_supported_on_fs(flags, fname)); \
 	} while (0)
 
+#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(flags) do { \
+	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
+		fanotify_init_flags_supported_by_kernel(flags)); \
+	} while (0)
+
 static inline int fanotify_mark_supported_by_kernel(uint64_t flag)
 {
 	int fd;
Signature · 6 lines
2.34.0.rc0.344.g81b53c2807-goog

/M

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 1/3
#2 lore raw

Re: [LTP] [PATCH v3 1/3] syscalls/fanotify: Add a helper macro which checks for the presence of specific fanotify initialization flag(s)

Quoted 6 lines · Matthew Bobrowski

This is a trivial macro that can be used throughout fanotify tests to check whether the underlying running kernel supports the supplied fanotify initialization flag(s).

Quoted 24 lines
---
 testcases/kernel/syscalls/fanotify/fanotify.h | 5 +++++
 1 file changed, 5 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify.h +5 -1
index a2be18338..e2db3c6f5 100644
@@ -352,6 +352,11 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str,
                fanotify_init_flags_supported_on_fs(flags, fname)); \
        } while (0)
 
+#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(flags) do { \
+       fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
+               fanotify_init_flags_supported_by_kernel(flags)); \
+       } while (0)
+
 static inline int fanotify_mark_supported_by_kernel(uint64_t flag)
 {
        int fd;
--

2.34.0.rc0.344.g81b53c2807-goog

/M

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v3 1/3] syscalls/fanotify: Add a helper macro which checks for the presence of specific fanotify initialization flag(s)

Hi Matthew, Amir,

Tested on two distro kernels with support (Tumbleweed and Debian unstable)
+ on various old kernels without support.

Merged with very minor fixes, see diff below.

NOTE: we now support basic static analysis + checkpatch formatting check - run make check in fanotify directory or make check-fanotify20.

Thanks a lot!

Kind regards,
Petr

syscalls +2 -0
index 1e6d46744..d57c73e39 100644
@@ -605,6 +605,8 @@ fanotify16 fanotify16
 fanotify17 fanotify17
 fanotify18 fanotify18
 fanotify19 fanotify19
+fanotify20 fanotify20
+fanotify21 fanotify21
 
 ioperm01 ioperm01
 ioperm02 ioperm02
kernel/syscalls/fanotify/fanotify20.c +4 -1
index 9960d85eb..de0fdb782 100644
@@ -12,6 +12,9 @@
  * returns an expected error code when provided an invalid initialization flag
  * alongside FAN_REPORT_PIDFD. Additionally, it checks that the operability with
  * existing FAN_REPORT_* flags is maintained and functioning as intended.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
  */
 
 #define _GNU_SOURCE
@@ -39,7 +42,7 @@ static struct test_case_t {
 	},
 	{
 		"pass on FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME",
-		FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME ,
+		FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME,
 		0,
 		0,
 	},
kernel/syscalls/fanotify/fanotify21.c +12 -9
index e842dad17..6ae70c57e 100644
@@ -11,6 +11,9 @@
  * A test which verifies whether the returned struct
  * fanotify_event_info_pidfd in FAN_REPORT_PIDFD mode contains the
  * expected set of information.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
  */
 
 #define _GNU_SOURCE
@@ -56,7 +59,7 @@ struct test_case_t {
 
 static int fanotify_fd;
 static char event_buf[BUF_SZ];
-static struct pidfd_fdinfo_t *self_pidfd_fdinfo = NULL;
+static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
 
 static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
 {
@@ -158,7 +161,7 @@ static void do_test(unsigned int num)
 	 * buffer.
 	 */
 	len = SAFE_READ(0, fanotify_fd, event_buf, sizeof(event_buf));
-	while(i < len) {
+	while (i < len) {
 		struct fanotify_event_metadata *event;
 		struct fanotify_event_info_pidfd *info;
 		struct pidfd_fdinfo_t *event_pidfd_fdinfo = NULL;
@@ -197,7 +200,7 @@ static void do_test(unsigned int num)
 			tst_res(TFAIL,
 				"pidfd creation failed for pid: %u with pidfd error value "
 				"set to: %d",
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				info->pidfd);
 			goto next_event;
 		} else if (tc->want_pidfd_err &&
@@ -205,14 +208,14 @@ static void do_test(unsigned int num)
 			tst_res(TFAIL,
 				"pidfd set to an unexpected error: %d for pid: %u",
 				info->pidfd,
-				(unsigned)event->pid);
+				(unsigned int)event->pid);
 			goto next_event;
 		} else if (tc->want_pidfd_err &&
 			   info->pidfd == tc->want_pidfd_err) {
 			tst_res(TPASS,
 				"pid: %u terminated before pidfd was created, "
 				"pidfd set to the value of: %d, as expected",
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				FAN_NOPIDFD);
 			goto next_event;
 		}
@@ -227,15 +230,15 @@ static void do_test(unsigned int num)
 				"reading fdinfo for pidfd: %d "
 				"describing pid: %u failed",
 				info->pidfd,
-				(unsigned)event->pid);
+				(unsigned int)event->pid);
 			goto next_event;
 		} else if (event_pidfd_fdinfo->pid != event->pid) {
 			tst_res(TFAIL,
 				"pidfd provided for incorrect pid "
 				"(expected pidfd for pid: %u, got pidfd for "
 				"pid: %u)",
-				(unsigned)event->pid,
-				(unsigned)event_pidfd_fdinfo->pid);
+				(unsigned int)event->pid,
+				(unsigned int)event_pidfd_fdinfo->pid);
 			goto next_event;
 		} else if (memcmp(event_pidfd_fdinfo, self_pidfd_fdinfo,
 				  sizeof(struct pidfd_fdinfo_t))) {
@@ -261,7 +264,7 @@ static void do_test(unsigned int num)
 				"mask: %lld, pid: %u, fd: %d, "
 				"pidfd: %d, info_type: %d, info_len: %d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				event->fd,
 				info->pidfd,
 				info->hdr.info_type,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v3 1/3] syscalls/fanotify: Add a helper macro which checks for the presence of specific fanotify initialization flag(s)

Quoted 6 lines · Petr Vorel

Hi Matthew, Amir,

Tested on two distro kernels with support (Tumbleweed and Debian unstable)
+ on various old kernels without support.

Merged with very minor fixes, see diff below.

Noted the changes, they're fine by me. Thanks for the merge!

Quoted 2 lines

NOTE: we now support basic static analysis + checkpatch formatting check - run make check in fanotify directory or make check-fanotify20.

Oh, that's great, I had no idea. Quickly running it, looks like there's a bunch of clean up required for some of the older tests. Will have to get around to doing that at some point.

Quoted 114 lines
syscalls +2 -0
index 1e6d46744..d57c73e39 100644
@@ -605,6 +605,8 @@ fanotify16 fanotify16
 fanotify17 fanotify17
 fanotify18 fanotify18
 fanotify19 fanotify19
+fanotify20 fanotify20
+fanotify21 fanotify21
 
 ioperm01 ioperm01
 ioperm02 ioperm02
kernel/syscalls/fanotify/fanotify20.c +4 -1
index 9960d85eb..de0fdb782 100644
@@ -12,6 +12,9 @@
  * returns an expected error code when provided an invalid initialization flag
  * alongside FAN_REPORT_PIDFD. Additionally, it checks that the operability with
  * existing FAN_REPORT_* flags is maintained and functioning as intended.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
  */
 
 #define _GNU_SOURCE
@@ -39,7 +42,7 @@ static struct test_case_t {
 	},
 	{
 		"pass on FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME",
-		FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME ,
+		FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME,
 		0,
 		0,
 	},
kernel/syscalls/fanotify/fanotify21.c +11 -8
index e842dad17..6ae70c57e 100644
@@ -11,6 +11,9 @@
  * A test which verifies whether the returned struct
  * fanotify_event_info_pidfd in FAN_REPORT_PIDFD mode contains the
  * expected set of information.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
  */
 
 #define _GNU_SOURCE
@@ -56,7 +59,7 @@ struct test_case_t {
 
 static int fanotify_fd;
 static char event_buf[BUF_SZ];
-static struct pidfd_fdinfo_t *self_pidfd_fdinfo = NULL;
+static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
 
 static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
 {
@@ -158,7 +161,7 @@ static void do_test(unsigned int num)
 	 * buffer.
 	 */
 	len = SAFE_READ(0, fanotify_fd, event_buf, sizeof(event_buf));
-	while(i < len) {
+	while (i < len) {
 		struct fanotify_event_metadata *event;
 		struct fanotify_event_info_pidfd *info;
 		struct pidfd_fdinfo_t *event_pidfd_fdinfo = NULL;
@@ -197,7 +200,7 @@ static void do_test(unsigned int num)
 			tst_res(TFAIL,
 				"pidfd creation failed for pid: %u with pidfd error value "
 				"set to: %d",
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				info->pidfd);
 			goto next_event;
 		} else if (tc->want_pidfd_err &&
@@ -205,14 +208,14 @@ static void do_test(unsigned int num)
 			tst_res(TFAIL,
 				"pidfd set to an unexpected error: %d for pid: %u",
 				info->pidfd,
-				(unsigned)event->pid);
+				(unsigned int)event->pid);
 			goto next_event;
 		} else if (tc->want_pidfd_err &&
 			   info->pidfd == tc->want_pidfd_err) {
 			tst_res(TPASS,
 				"pid: %u terminated before pidfd was created, "
 				"pidfd set to the value of: %d, as expected",
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				FAN_NOPIDFD);
 			goto next_event;
 		}
@@ -227,15 +230,15 @@ static void do_test(unsigned int num)
 				"reading fdinfo for pidfd: %d "
 				"describing pid: %u failed",
 				info->pidfd,
-				(unsigned)event->pid);
+				(unsigned int)event->pid);
 			goto next_event;
 		} else if (event_pidfd_fdinfo->pid != event->pid) {
 			tst_res(TFAIL,
 				"pidfd provided for incorrect pid "
 				"(expected pidfd for pid: %u, got pidfd for "
 				"pid: %u)",
-				(unsigned)event->pid,
-				(unsigned)event_pidfd_fdinfo->pid);
+				(unsigned int)event->pid,
+				(unsigned int)event_pidfd_fdinfo->pid);
 			goto next_event;
 		} else if (memcmp(event_pidfd_fdinfo, self_pidfd_fdinfo,
 				  sizeof(struct pidfd_fdinfo_t))) {

kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 270

Quoted 8 lines
kernel/syscalls/fanotify/fanotify21.c +1 -1
@@ -261,7 +264,7 @@ static void do_test(unsigned int num)
 				"mask: %lld, pid: %u, fd: %d, "
 				"pidfd: %d, info_type: %d, info_len: %d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
+				(unsigned int)event->pid,
 				event->fd,
 				info->pidfd,
 				info->hdr.info_type,

/M

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v3 1/3] syscalls/fanotify: Add a helper macro which checks for the presence of specific fanotify initialization flag(s)

Hi Matthew, Amir,

Quoted 9 lines · Petr Vorel
Quoted 6 lines

Hi Matthew, Amir,

Tested on two distro kernels with support (Tumbleweed and Debian unstable)
+ on various old kernels without support.

Merged with very minor fixes, see diff below.

Noted the changes, they're fine by me. Thanks for the merge!

+1

Quoted 6 lines
Quoted 2 lines

NOTE: we now support basic static analysis + checkpatch formatting check - run make check in fanotify directory or make check-fanotify20.

Oh, that's great, I had no idea. Quickly running it, looks like there's a bunch of clean up required for some of the older tests. Will have to get around to doing that at some point.

Thanks a lot, that's really appreciated.
Also, thanks a lot you and Amir for really maintaining fanotify tests.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

PATCH v3 2/3 syscalls/fanotify20: add new test for FAN_REPORT_PIDFD

In reply to Matthew Bobrowski via ltp

This test ensures that the fanotify API returns the expected error status code -EINVAL when an invalid flag is supplied alongside the new FAN_REPORT_PIDFD initialization flag. Currently, FAN_REPORT_TID is the only initialization flag that is not permitted in conjunction with FAN_REPORT_PIDFD, so we explicitly provide test coverage for this.

We also add an extra trivial test case to ensure that the initialization behavior with the other FAN_REPORT_* related flags is working as intended.

---
 testcases/kernel/syscalls/fanotify/.gitignore |   1 +
 testcases/kernel/syscalls/fanotify/fanotify.h |  21 +++
 .../kernel/syscalls/fanotify/fanotify20.c     | 128 ++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify20.c
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
index 9554b16b1..c99e6fff7 100644
@@ -17,4 +17,5 @@
 /fanotify17
 /fanotify18
 /fanotify19
+/fanotify20
 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +21 -0
index e2db3c6f5..c91162d97 100644
@@ -78,6 +78,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #define FAN_REPORT_NAME		0x00000800
 #define FAN_REPORT_DFID_NAME     (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
 #endif
+#ifndef FAN_REPORT_PIDFD
+#define FAN_REPORT_PIDFD	0x00000080
+#endif
 
 /* Non-uapi convenience macros */
 #ifndef FAN_REPORT_DFID_NAME_FID
@@ -125,6 +128,14 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #define FAN_OPEN_EXEC_PERM	0x00040000
 #endif
 
+/* Additional error status codes that can be returned to userspace */
+#ifndef FAN_NOPIDFD
+#define FAN_NOPIDFD		-1
+#endif
+#ifndef FAN_EPIDFD
+#define FAN_EPIDFD		-2
+#endif
+
 /* Flags required for unprivileged user group */
 #define FANOTIFY_REQUIRED_USER_INIT_FLAGS    (FAN_REPORT_FID)
 
@@ -164,6 +175,9 @@ typedef struct {
 #ifndef FAN_EVENT_INFO_TYPE_DFID
 #define FAN_EVENT_INFO_TYPE_DFID	3
 #endif
+#ifndef FAN_EVENT_INFO_TYPE_PIDFD
+#define FAN_EVENT_INFO_TYPE_PIDFD	4
+#endif
 
 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
 struct fanotify_event_info_header {
@@ -181,6 +195,13 @@ struct fanotify_event_info_fid {
 };
 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID */
 
+#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD
+struct fanotify_event_info_pidfd {
+	struct fanotify_event_info_header hdr;
+	int32_t pidfd;
+};
+#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD */
+
 /* NOTE: only for struct fanotify_event_info_fid */
 #ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL
 # define FSID_VAL_MEMBER(fsid, i) (fsid.__val[i])
testcases/kernel/syscalls/fanotify/fanotify20.c new file +128 -0

128 lines not on this page · raw message

Signature · 6 lines
2.34.0.rc0.344.g81b53c2807-goog

/M

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 3/3 syscalls/fanotify21: test returned pidfd from fanotify in FAN_REPORT_PIDFD mode

In reply to Matthew Bobrowski via ltp

This is a new test that performs verification on the values returned within the struct fanotify_event_info_pidfd record when the notification group has been initialized with the FAN_REPORT_PIDFD flag.

---
 testcases/kernel/syscalls/fanotify/.gitignore |   1 +
 .../kernel/syscalls/fanotify/fanotify21.c     | 306 ++++++++++++++++++
 2 files changed, 307 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify21.c
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
index c99e6fff7..35e73b91e 100644
@@ -18,4 +18,5 @@
 /fanotify18
 /fanotify19
 /fanotify20
+/fanotify21
 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify21.c new file +306 -0

306 lines not on this page · raw message

Signature · 6 lines
2.34.0.rc0.344.g81b53c2807-goog

/M

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp