Skip to contentSkip to conversation

fanotify tests update for 6.14-rc7

PATCH In review Amir Goldstein 3 participants 14 messages Mar 19, 2025 – Mar 27, 2025

lore
Share & tools
lore
#0 lore raw

cover fanotify tests update for 6.14-rc7

Petr,

6.14-rc7 had a minor change of semantics for pre-conent events. This change adapts the pre-content event tests to the latest semantics.

There is no git tag annotation, because the kernel fix is before a final kernel release, so no backporting is expected.

Thanks,
Amir.

Amir Goldstein (3):
fanotify24: remove redundant event_count field
fanotify24: print range info for pre-content events
fanotify24: add mmap() and user page fault to test

 configure.ac                                  |  3 +-
 include/lapi/fanotify.h                       | 12 +++
 .../kernel/syscalls/fanotify/fanotify24.c     | 90 ++++++++++++++-----
 3 files changed, 82 insertions(+), 23 deletions(-)
Signature · 5 lines
2.34.1


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

PATCH 1/3 fanotify24: remove redundant event_count field

treat the event-set as a null terminated array.

---
 .../kernel/syscalls/fanotify/fanotify24.c     | 31 +++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +15 -16
index 8a448ea50..539f74137 100644
@@ -60,13 +60,12 @@ static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
 	unsigned long long mask;
-	int event_count;
 	struct event event_set[EVENT_SET_MAX];
 } tcases[] = {
 	{
 		"inode mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -77,7 +76,7 @@ static struct tcase {
 	{
 		"inode mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -87,7 +86,7 @@ static struct tcase {
 	{
 		"mount mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -98,7 +97,7 @@ static struct tcase {
 	{
 		"mount mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -108,7 +107,7 @@ static struct tcase {
 	{
 		"filesystem mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -119,7 +118,7 @@ static struct tcase {
 	{
 		"filesystem mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -129,7 +128,7 @@ static struct tcase {
 	{
 		"parent watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -139,14 +138,14 @@ static struct tcase {
 	{
 		"parent not watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 0,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 		}
 	},
 	{
 		"inode mark, FAN_PRE_ACCESS event allowed",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_PRE_ACCESS, 1,
+		FAN_PRE_ACCESS,
 		{
 			/* This allows multiple FAN_PRE_ACCESS events */
 			{FAN_PRE_ACCESS, FAN_ALLOW},
@@ -225,7 +224,7 @@ static void generate_events(struct tcase *tc)
 	 */
 	if (!exp_errno) {
 		fd = SAFE_OPEN(FILE_EXEC_PATH, O_RDWR);
-		if (!tc->event_count)
+		if (!tc->event_set[0].mask)
 			exp_errno = ETXTBSY;
 	}
 
@@ -335,10 +334,10 @@ static void test_fanotify(unsigned int n)
 	/*
 	 * Process events
 	 *
-	 * tc->count + 1 is to let read() wait for child process to exit
-	 * and to accomodate for extra access events
+	 * even if we do not expect another event, let read() wait for child
+	 * process to exit and accomodate for multiple access events
 	 */
-	while (test_num < tc->event_count + 1 && fd_notify != -1) {
+	while (test_num < EVENT_SET_MAX && fd_notify != -1) {
 		struct fanotify_event_metadata *event;
 
 		if (i == len) {
@@ -363,7 +362,7 @@ static void test_fanotify(unsigned int n)
 		 * generate an unknown number of access permission events if they
 		 * are allowed.
 		 */
-		if (test_num > 0 && test_num == tc->event_count &&
+		if (test_num > 0 && !event_set[test_num].mask &&
 		    event_set[test_num-1].response == FAN_ALLOW)
 			test_num--;
 
@@ -418,7 +417,7 @@ static void test_fanotify(unsigned int n)
 		test_num++;
 	}
 
-	for (; test_num < tc->event_count; test_num++) {
+	for (; event_set[test_num].mask && test_num < EVENT_SET_MAX; test_num++) {
 		tst_res(TFAIL, "didn't get event: mask=%llx",
 			event_set[test_num].mask);
 
Signature · 5 lines
2.34.1


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

Re: [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field

Quoted 3 lines · Amir Goldstein

treat the event-set as a null terminated array.

Looks good. Feel free to add:

Honza

Quoted 138 lines
---
 .../kernel/syscalls/fanotify/fanotify24.c     | 31 +++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +15 -16
index 8a448ea50..539f74137 100644
@@ -60,13 +60,12 @@ static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
 	unsigned long long mask;
-	int event_count;
 	struct event event_set[EVENT_SET_MAX];
 } tcases[] = {
 	{
 		"inode mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -77,7 +76,7 @@ static struct tcase {
 	{
 		"inode mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -87,7 +86,7 @@ static struct tcase {
 	{
 		"mount mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -98,7 +97,7 @@ static struct tcase {
 	{
 		"mount mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -108,7 +107,7 @@ static struct tcase {
 	{
 		"filesystem mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -119,7 +118,7 @@ static struct tcase {
 	{
 		"filesystem mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -129,7 +128,7 @@ static struct tcase {
 	{
 		"parent watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD, 3,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
 		{
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY},
@@ -139,14 +138,14 @@ static struct tcase {
 	{
 		"parent not watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
-		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 0,
+		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
 		}
 	},
 	{
 		"inode mark, FAN_PRE_ACCESS event allowed",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_PRE_ACCESS, 1,
+		FAN_PRE_ACCESS,
 		{
 			/* This allows multiple FAN_PRE_ACCESS events */
 			{FAN_PRE_ACCESS, FAN_ALLOW},
@@ -225,7 +224,7 @@ static void generate_events(struct tcase *tc)
 	 */
 	if (!exp_errno) {
 		fd = SAFE_OPEN(FILE_EXEC_PATH, O_RDWR);
-		if (!tc->event_count)
+		if (!tc->event_set[0].mask)
 			exp_errno = ETXTBSY;
 	}
 
@@ -335,10 +334,10 @@ static void test_fanotify(unsigned int n)
 	/*
 	 * Process events
 	 *
-	 * tc->count + 1 is to let read() wait for child process to exit
-	 * and to accomodate for extra access events
+	 * even if we do not expect another event, let read() wait for child
+	 * process to exit and accomodate for multiple access events
 	 */
-	while (test_num < tc->event_count + 1 && fd_notify != -1) {
+	while (test_num < EVENT_SET_MAX && fd_notify != -1) {
 		struct fanotify_event_metadata *event;
 
 		if (i == len) {
@@ -363,7 +362,7 @@ static void test_fanotify(unsigned int n)
 		 * generate an unknown number of access permission events if they
 		 * are allowed.
 		 */
-		if (test_num > 0 && test_num == tc->event_count &&
+		if (test_num > 0 && !event_set[test_num].mask &&
 		    event_set[test_num-1].response == FAN_ALLOW)
 			test_num--;
 
@@ -418,7 +417,7 @@ static void test_fanotify(unsigned int n)
 		test_num++;
 	}
 
-	for (; test_num < tc->event_count; test_num++) {
+	for (; event_set[test_num].mask && test_num < EVENT_SET_MAX; test_num++) {
 		tst_res(TFAIL, "didn't get event: mask=%llx",
 			event_set[test_num].mask);
 
Signature · 1 line
2.34.1
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

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

Re: [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field

Hi Amir, Jan,

Quoted 8 lines · Amir Goldstein
Quoted 3 lines

treat the event-set as a null terminated array.

Looks good. Feel free to add:

Thanks Jan, merged this one.

Amir, because Jan plans to have look on the remaining two, I'll wait for him.

Kind regards,
Petr

Quoted 1 line

Honza

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

PATCH 2/3 fanotify24: print range info for pre-content events

In reply to Amir Goldstein

range info is expected only for pre-content events

---
 configure.ac                                   |  3 ++-
 include/lapi/fanotify.h                        | 12 ++++++++++++
 .../kernel/syscalls/fanotify/fanotify24.c      | 18 ++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
configure.ac +2 -1
index 344b2ae2c..9b9883eac 100644
@@ -179,7 +179,8 @@ AC_CHECK_TYPES([enum kcmp_type],,,[#include <linux/kcmp.h>])
 AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
 AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
-		struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])
+		struct fanotify_event_info_header, struct fanotify_event_info_pidfd,
+		struct fanotify_event_info_range],,,[#include <sys/fanotify.h>])
 AC_CHECK_TYPES([struct file_clone_range],,,[#include <linux/fs.h>])
 AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 
include/lapi/fanotify.h +12 -0
index 9076685e8..76907ea5f 100644
@@ -178,6 +178,9 @@ typedef struct {
 #ifndef FAN_EVENT_INFO_TYPE_ERROR
 #define FAN_EVENT_INFO_TYPE_ERROR	5
 #endif
+#ifndef FAN_EVENT_INFO_TYPE_RANGE
+#define FAN_EVENT_INFO_TYPE_RANGE	6
+#endif
 
 #ifndef FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
 #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME	10
@@ -217,6 +220,15 @@ struct fanotify_event_info_error {
 };
 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR */
 
+#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_RANGE
+struct fanotify_event_info_range {
+	struct fanotify_event_info_header hdr;
+	__u32 pad;
+	__u64 offset;
+	__u64 count;
+};
+#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_RANGE */
+
 /* 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/fanotify24.c +18 -0
index 539f74137..2d2479b39 100644
@@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
 	 */
 	while (test_num < EVENT_SET_MAX && fd_notify != -1) {
 		struct fanotify_event_metadata *event;
+		struct fanotify_event_info_range *range;
 
 		if (i == len) {
 			/* Get more events */
@@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
 			test_num--;
 
 		event = (struct fanotify_event_metadata *)&event_buf[i];
+		range = (struct fanotify_event_info_range *)(event + 1);
 		/* Permission events cannot be merged, so the event mask
 		 * reported should exactly match the event mask within the
 		 * event set.
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
 				(unsigned int)event->pid,
 				(unsigned int)child_pid,
 				event->fd);
+		} else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
+			if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+				tst_res(TFAIL,
+					"got event: mask=%llx pid=%u fd=%d "
+					"(expected range info)",
+					(unsigned long long)event->mask,
+					(unsigned int)event->pid,
+					event->fd);
+			} else {
+				tst_res(TPASS,
+					"got event: mask=%llx pid=%u fd=%d "
+					"offset=%llu count=%llu",
+					(unsigned long long)event->mask,
+					(unsigned int)event->pid, event->fd,
+					range->offset, range->count);
+			}
 		} else {
 			tst_res(TPASS,
 				"got event: mask=%llx pid=%u fd=%d",
Signature · 5 lines
2.34.1


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

Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events

Quoted 3 lines · Amir Goldstein

range info is expected only for pre-content events

Just one nit below. Otherwise feel free to add:

Quoted 21 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +2 -0
index 539f74137..2d2479b39 100644
@@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
 	 */
 	while (test_num < EVENT_SET_MAX && fd_notify != -1) {
 		struct fanotify_event_metadata *event;
+		struct fanotify_event_info_range *range;
 
 		if (i == len) {
 			/* Get more events */
@@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
 			test_num--;
 
 		event = (struct fanotify_event_metadata *)&event_buf[i];
+		range = (struct fanotify_event_info_range *)(event + 1);
 		/* Permission events cannot be merged, so the event mask
 		 * reported should exactly match the event mask within the
 		 * event set.

testcases/kernel/syscalls/fanotify/fanotify24.c static void test_fanotify(unsigned int n) · line 391

Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
 				(unsigned int)event->pid,
 				(unsigned int)child_pid,
 				event->fd);
+		} else if (event->mask & LTP_PRE_CONTENT_EVENTS) {

You should probably check here that the event->len is sufficiently large to contain the range info. Otherwise 'range' might point beyond the end of event and result in odd behavior...

Honza

Quoted 21 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +15 -0
+			if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+				tst_res(TFAIL,
+					"got event: mask=%llx pid=%u fd=%d "
+					"(expected range info)",
+					(unsigned long long)event->mask,
+					(unsigned int)event->pid,
+					event->fd);
+			} else {
+				tst_res(TPASS,
+					"got event: mask=%llx pid=%u fd=%d "
+					"offset=%llu count=%llu",
+					(unsigned long long)event->mask,
+					(unsigned int)event->pid, event->fd,
+					range->offset, range->count);
+			}
 		} else {
 			tst_res(TPASS,
 				"got event: mask=%llx pid=%u fd=%d",
Signature · 1 line
2.34.1
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

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

Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events

Quoted 25 lines · Jan Kara
Quoted 3 lines · Amir Goldstein

range info is expected only for pre-content events

Just one nit below. Otherwise feel free to add:

Quoted 15 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
index 539f74137..2d2479b39 100644
@@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
       */
      while (test_num < EVENT_SET_MAX && fd_notify != -1) {
              struct fanotify_event_metadata *event;
+             struct fanotify_event_info_range *range;
 
              if (i == len) {
                      /* Get more events */
@@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
                      test_num--;
 
Quoted 15 lines

testcases/kernel/syscalls/fanotify/fanotify24.c static void test_fanotify(unsigned int n) · line 391

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +2 -0
              event = (struct fanotify_event_metadata *)&event_buf[i];
+             range = (struct fanotify_event_info_range *)(event + 1);
              /* Permission events cannot be merged, so the event mask
               * reported should exactly match the event mask within the
               * event set.
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
                              (unsigned int)event->pid,
                              (unsigned int)child_pid,
                              event->fd);
+             } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {

You should probably check here that the event->len is sufficiently large to contain the range info. Otherwise 'range' might point beyond the end of event and result in odd behavior...

Right. feel free to use the amended version below

Quoted 9 lines

Honza

Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +7 -0
+                     if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+                             tst_res(TFAIL,
+                                     "got event: mask=%llx pid=%u fd=%d "
+                                     "(expected range info)",
+                                     (unsigned long long)event->mask,
+                                     (unsigned int)event->pid,
+                                     event->fd);
                        if (event->event_len < sizeof(*event) +

sizeof(*range) ||
range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u
len=%d fd=%d "

                                        "(expected range info)",
                                        (unsigned long long)event->mask,
                                        (unsigned int)event->pid,
                                        (unsigned int)event->event_len,
                                        event->fd);

Thanks,
Amir.

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

Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events

Hi Amir, Jan,

Quoted 31 lines
Quoted 9 lines

testcases/kernel/syscalls/fanotify/fanotify24.c static void test_fanotify(unsigned int n) · line 391

Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
                              (unsigned int)event->pid,
                              (unsigned int)child_pid,
                              event->fd);
+             } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {

You should probably check here that the event->len is sufficiently large to contain the range info. Otherwise 'range' might point beyond the end of event and result in odd behavior...

Right. feel free to use the amended version below

Quoted 9 lines

Honza

Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +7 -0
+                     if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+                             tst_res(TFAIL,
+                                     "got event: mask=%llx pid=%u fd=%d "
+                                     "(expected range info)",
+                                     (unsigned long long)event->mask,
+                                     (unsigned int)event->pid,
+                                     event->fd);
                        if (event->event_len < sizeof(*event) +

sizeof(*range) ||
range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u
len=%d fd=%d "

Quoted 5 lines
                                        "(expected range info)",
                                        (unsigned long long)event->mask,
                                        (unsigned int)event->pid,
                                        (unsigned int)event->event_len,
                                        event->fd);

Thanks! I dared instead of copy pasting to use fan_hsm branch from your fork. Jan, thanks for the review!
Merged the rest of the pachset.

Kind regards,
Petr

Quoted 2 lines

Thanks,
Amir.

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

Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events

Quoted 40 lines · Petr Vorel

Hi Amir, Jan,

Quoted 31 lines
Quoted 9 lines

testcases/kernel/syscalls/fanotify/fanotify24.c static void test_fanotify(unsigned int n) · line 391

Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
                              (unsigned int)event->pid,
                              (unsigned int)child_pid,
                              event->fd);
+             } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {

You should probably check here that the event->len is sufficiently large to contain the range info. Otherwise 'range' might point beyond the end of event and result in odd behavior...

Right. feel free to use the amended version below

Quoted 9 lines

Honza

Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +7 -0
+                     if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+                             tst_res(TFAIL,
+                                     "got event: mask=%llx pid=%u fd=%d "
+                                     "(expected range info)",
+                                     (unsigned long long)event->mask,
+                                     (unsigned int)event->pid,
+                                     event->fd);
                        if (event->event_len < sizeof(*event) +

sizeof(*range) ||
range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u
len=%d fd=%d "

Quoted 5 lines
                                        "(expected range info)",
                                        (unsigned long long)event->mask,
                                        (unsigned int)event->pid,
                                        (unsigned int)event->event_len,
                                        event->fd);
Quoted 1 line

Thanks! I dared instead of copy pasting to use fan_hsm branch from your fork.

Sure. That's good too.

Thanks,
Amir.

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

PATCH 3/3 fanotify24: add mmap() and user page fault to test

In reply to Amir Goldstein

Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()") in 6.14-rc7 added a pre-content hooh in mmap() before the final release of the fsnotify pre-content event feature.

To test pre-content hook on mmap(), increase the size of the test file to 101 pages use mmap() to setup a buffer from the end of the test file.

Change some of the test cases to allow the write() and use this buffer as the input buffer to write(), which tests deadlock avoidance by suppresing pre-content hook on user page faults.

---
 .../kernel/syscalls/fanotify/fanotify24.c     | 41 ++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +35 -6
index 2d2479b39..3a76f2c1b 100644
@@ -46,6 +46,7 @@
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
 static volatile int fd_notify;
+static size_t page_sz;
 
 static pid_t child_pid;
 
@@ -68,7 +69,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -78,6 +80,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -89,7 +92,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -99,6 +103,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -110,7 +115,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -120,6 +126,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -130,6 +137,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY}
@@ -169,6 +177,7 @@ static int expected_errno(unsigned int response)
 static void generate_events(struct tcase *tc)
 {
 	int fd;
+	char *addr;
 	char *const argv[] = {FILE_EXEC_PATH, NULL};
 	struct event *event = tc->event_set;
 	int exp_ret, exp_errno = 0;
@@ -186,8 +195,25 @@ static void generate_events(struct tcase *tc)
 
 	exp_ret = exp_errno ? -1 : 1;
 	errno = 0;
-	/* FAN_PRE_ACCESS events are reported also on write */
-	if (write(fd, fname, 1) != exp_ret || errno != exp_errno) {
+	/*
+	 * FAN_PRE_ACCESS events are reported on map() and write(), but should
+	 * not be reported when faulting in the user page at offset page_sz*100
+	 * that is used as an input buffer to the write() syscall.
+	 */
+	addr = SAFE_MMAP(NULL, page_sz, PROT_READ, MAP_PRIVATE, fd, page_sz*100);
+	if (!addr || errno != exp_errno) {
+		tst_res(TFAIL, "mmap() got errno %d (expected %d)", errno, exp_errno);
+		exit(3);
+	} else if (errno == exp_errno) {
+		tst_res(TINFO, "mmap() got errno %d as expected", errno);
+	}
+
+	exp_errno = expected_errno(event->response);
+	event++;
+
+	exp_ret = exp_errno ? -1 : 1;
+	errno = 0;
+	if (write(fd, addr, 1) != exp_ret || errno != exp_errno) {
 		tst_res(TFAIL, "write() got errno %d (expected %d)", errno, exp_errno);
 		exit(3);
 	} else if (errno == exp_errno) {
@@ -199,7 +225,7 @@ static void generate_events(struct tcase *tc)
 	exp_errno = expected_errno(event->response);
 	event++;
 
-	exp_ret = exp_errno ? -1 : 1;
+	exp_ret = exp_errno ? -1 : BUF_SIZE;
 	errno = 0;
 	if (read(fd, buf, BUF_SIZE) != exp_ret || errno != exp_errno) {
 		tst_res(TFAIL, "read() got errno %d (expected %d)", errno, exp_errno);
@@ -449,8 +475,11 @@ static void test_fanotify(unsigned int n)
 
 static void setup(void)
 {
+	page_sz = getpagesize();
+
 	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
+	SAFE_TRUNCATE(fname, page_sz*101);
 
 	REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_PRE_CONTENT, FAN_MARK_FILESYSTEM,
 						FAN_PRE_ACCESS, fname);
Signature · 5 lines
2.34.1


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

Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test

Hi Amir,

Quoted 29 lines

Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()") in 6.14-rc7 added a pre-content hooh in mmap() before the final release of the fsnotify pre-content event feature.

To test pre-content hook on mmap(), increase the size of the test file to 101 pages use mmap() to setup a buffer from the end of the test file.

Change some of the test cases to allow the write() and use this buffer as the input buffer to write(), which tests deadlock avoidance by suppresing pre-content hook on user page faults.

---
 .../kernel/syscalls/fanotify/fanotify24.c     | 41 ++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
index 2d2479b39..3a76f2c1b 100644
@@ -46,6 +46,7 @@
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
 static volatile int fd_notify;
+static size_t page_sz;
 
 static pid_t child_pid;
 

testcases/kernel/syscalls/fanotify/fanotify24.c static struct tcase { · line 73

Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +2 -1
@@ -68,7 +69,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},

If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for reusing the write buffer, right? Obviously it's needed but on the first look it looks like error.

<snip>

Kind regards,
Petr

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

Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test

Quoted 31 lines · Petr Vorel

Hi Amir,

Quoted 27 lines

Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()") in 6.14-rc7 added a pre-content hooh in mmap() before the final release of the fsnotify pre-content event feature.

To test pre-content hook on mmap(), increase the size of the test file to 101 pages use mmap() to setup a buffer from the end of the test file.

Change some of the test cases to allow the write() and use this buffer as the input buffer to write(), which tests deadlock avoidance by suppresing pre-content hook on user page faults.

---
 .../kernel/syscalls/fanotify/fanotify24.c     | 41 ++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
index 2d2479b39..3a76f2c1b 100644
@@ -46,6 +46,7 @@
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
 static volatile int fd_notify;
+static size_t page_sz;
 
 static pid_t child_pid;
Quoted 11 lines

testcases/kernel/syscalls/fanotify/fanotify24.c static struct tcase { · line 73

Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +2 -1
@@ -68,7 +69,8 @@ static struct tcase {
              FAN_OPEN_PERM | FAN_PRE_ACCESS,
              {
                      {FAN_OPEN_PERM, FAN_ALLOW},
-                     {FAN_PRE_ACCESS, FAN_DENY},
+                     {FAN_PRE_ACCESS, FAN_ALLOW},
+                     {FAN_PRE_ACCESS, FAN_ALLOW},

If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for reusing the write buffer, right? Obviously it's needed but on the first look it looks like error.

Sorry, this wasn't properly explained.

This change adds a test for pre-mmap events.

First of all, we added an mmap() call before the write(), so we need to add another expected FAN_PRE_ACCESS for the mmap() and we allow the mmap for all test cases.

Secondly, we Change some of the test cases to allow the write() and use the mmaped buffer as the input buffer.

The reason that we allow the write() is to verify that we do not get another FAN_PRE_ACCESS event from reading from the mmaped input buffer.

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by
#12 lore raw

Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test

Quoted 52 lines · Petr Vorel
Quoted 31 lines

Hi Amir,

Quoted 27 lines

Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()") in 6.14-rc7 added a pre-content hooh in mmap() before the final release of the fsnotify pre-content event feature.

To test pre-content hook on mmap(), increase the size of the test file to 101 pages use mmap() to setup a buffer from the end of the test file.

Change some of the test cases to allow the write() and use this buffer as the input buffer to write(), which tests deadlock avoidance by suppresing pre-content hook on user page faults.

---
 .../kernel/syscalls/fanotify/fanotify24.c     | 41 ++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +1 -0
index 2d2479b39..3a76f2c1b 100644
@@ -46,6 +46,7 @@
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
 static volatile int fd_notify;
+static size_t page_sz;
 
 static pid_t child_pid;
Quoted 11 lines

testcases/kernel/syscalls/fanotify/fanotify24.c static struct tcase { · line 73

Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify24.c +2 -1
@@ -68,7 +69,8 @@ static struct tcase {
              FAN_OPEN_PERM | FAN_PRE_ACCESS,
              {
                      {FAN_OPEN_PERM, FAN_ALLOW},
-                     {FAN_PRE_ACCESS, FAN_DENY},
+                     {FAN_PRE_ACCESS, FAN_ALLOW},
+                     {FAN_PRE_ACCESS, FAN_ALLOW},

If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for reusing the write buffer, right? Obviously it's needed but on the first look it looks like error.

Sorry, this wasn't properly explained.

This change adds a test for pre-mmap events.

First of all, we added an mmap() call before the write(), so we need to add another expected FAN_PRE_ACCESS for the mmap() and we allow the mmap for all test cases.

Quoted 6 lines

Secondly, we Change some of the test cases to allow the write() and use the mmaped buffer as the input buffer.

The reason that we allow the write() is to verify that we do not get another FAN_PRE_ACCESS event from reading from the mmaped input buffer.

Thanks for the explanation. It would deserve to update the commit message, but it's probably obvious to Jan and I add link to lore before merging, therefore maybe it's enough as is.

Anyway, whole patchset LGTM. Waiting till tomorrow before merging if Jan has some input.

Kind regards,
Petr

Quoted 2 lines

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 3/3
#13 lore raw

Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test

In reply to Amir Goldstein
Quoted 4 lines · Amir Goldstein

Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()") in 6.14-rc7 added a pre-content hooh in mmap() before the final release of the fsnotify pre-content event feature.

Quoted 8 lines

To test pre-content hook on mmap(), increase the size of the test file to 101 pages use mmap() to setup a buffer from the end of the test file.

Change some of the test cases to allow the write() and use this buffer as the input buffer to write(), which tests deadlock avoidance by suppresing pre-content hook on user page faults.

Looks good. Feel free to add:

Honza

Quoted 138 lines
---
 .../kernel/syscalls/fanotify/fanotify24.c     | 41 ++++++++++++++++---
 1 file changed, 35 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +35 -6
index 2d2479b39..3a76f2c1b 100644
@@ -46,6 +46,7 @@
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
 static volatile int fd_notify;
+static size_t page_sz;
 
 static pid_t child_pid;
 
@@ -68,7 +69,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -78,6 +80,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -89,7 +92,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -99,6 +103,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -110,7 +115,8 @@ static struct tcase {
 		FAN_OPEN_PERM | FAN_PRE_ACCESS,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_PRE_ACCESS, FAN_DENY},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
 		}
@@ -120,6 +126,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -130,6 +137,7 @@ static struct tcase {
 		INIT_FANOTIFY_MARK_TYPE(PARENT),
 		FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
 		{
+			{FAN_PRE_ACCESS, FAN_ALLOW},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_PRE_ACCESS, FAN_DENY},
 			{FAN_OPEN_EXEC_PERM, FAN_DENY}
@@ -169,6 +177,7 @@ static int expected_errno(unsigned int response)
 static void generate_events(struct tcase *tc)
 {
 	int fd;
+	char *addr;
 	char *const argv[] = {FILE_EXEC_PATH, NULL};
 	struct event *event = tc->event_set;
 	int exp_ret, exp_errno = 0;
@@ -186,8 +195,25 @@ static void generate_events(struct tcase *tc)
 
 	exp_ret = exp_errno ? -1 : 1;
 	errno = 0;
-	/* FAN_PRE_ACCESS events are reported also on write */
-	if (write(fd, fname, 1) != exp_ret || errno != exp_errno) {
+	/*
+	 * FAN_PRE_ACCESS events are reported on map() and write(), but should
+	 * not be reported when faulting in the user page at offset page_sz*100
+	 * that is used as an input buffer to the write() syscall.
+	 */
+	addr = SAFE_MMAP(NULL, page_sz, PROT_READ, MAP_PRIVATE, fd, page_sz*100);
+	if (!addr || errno != exp_errno) {
+		tst_res(TFAIL, "mmap() got errno %d (expected %d)", errno, exp_errno);
+		exit(3);
+	} else if (errno == exp_errno) {
+		tst_res(TINFO, "mmap() got errno %d as expected", errno);
+	}
+
+	exp_errno = expected_errno(event->response);
+	event++;
+
+	exp_ret = exp_errno ? -1 : 1;
+	errno = 0;
+	if (write(fd, addr, 1) != exp_ret || errno != exp_errno) {
 		tst_res(TFAIL, "write() got errno %d (expected %d)", errno, exp_errno);
 		exit(3);
 	} else if (errno == exp_errno) {
@@ -199,7 +225,7 @@ static void generate_events(struct tcase *tc)
 	exp_errno = expected_errno(event->response);
 	event++;
 
-	exp_ret = exp_errno ? -1 : 1;
+	exp_ret = exp_errno ? -1 : BUF_SIZE;
 	errno = 0;
 	if (read(fd, buf, BUF_SIZE) != exp_ret || errno != exp_errno) {
 		tst_res(TFAIL, "read() got errno %d (expected %d)", errno, exp_errno);
@@ -449,8 +475,11 @@ static void test_fanotify(unsigned int n)
 
 static void setup(void)
 {
+	page_sz = getpagesize();
+
 	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
+	SAFE_TRUNCATE(fname, page_sz*101);
 
 	REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_PRE_CONTENT, FAN_MARK_FILESYSTEM,
 						FAN_PRE_ACCESS, fname);
Signature · 1 line
2.34.1
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

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