Skip to contentSkip to conversation

syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

PATCH New Matthew Bobrowski 4 participants 12 messages Jun 20, 2019 – Jun 24, 2019

lore
Share & tools
lore
#0 lore raw

v5 cover syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

This patch series contains the changes needed to validate the new FAN_REPORT_FID flag and directory modification event functionality within the fanotify API.

Changes since version 4:

	* Fixed problems with unbalanced file descriptor close.
	* Reorded functions in the test files fanotify13, fanotify14 and
	  fanotify15 so that they all follow a basic template i.e.

	  test()
	  ...
	  do_setup()
	  do_cleanup()

Thank you Amir for your feedback.

Amir Goldstein (1):
syscalls/fanotify13: add test coverage for fsid cache bug

Matthew Bobrowski (3):
syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality syscalls/fanotify14: new test to validate FAN_REPORT_FID interface
return values
syscalls/fanotify15: verify fid for dirent events

 configure.ac                                    |   1 +
 runtest/syscalls                                |   3 +
 testcases/kernel/syscalls/fanotify/.gitignore   |   3 +
 testcases/kernel/syscalls/fanotify/fanotify.h   |  81 +++++-
 testcases/kernel/syscalls/fanotify/fanotify05.c |   1 +
 testcases/kernel/syscalls/fanotify/fanotify13.c | 328 ++++++++++++++++++++++++
 testcases/kernel/syscalls/fanotify/fanotify14.c | 176 +++++++++++++
 testcases/kernel/syscalls/fanotify/fanotify15.c | 246 ++++++++++++++++++
 8 files changed, 836 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify13.c
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify14.c
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify15.c
Signature · 5 lines
2.16.4


-- 
Matthew Bobrowski
#1 lore raw

PATCH v5 1/4 syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality

A newly defined test file to validate the fanotify FAN_REPORT_FID functionality. A new line entry for this test file has been added within runtest/syscalls.

Additionally, defined a helper function that can be used to obtain __kernel_fsid_t and file_handle objects. This helper will be used by test files related to verifying FAN_REPORT_FID. The name_to_handle_at() function is conditionally added to accommodate for builds on older distributions.

Added _GNU_SOURCE feature test macro to syscalls/fanotify05 in order to resolve build warnings.

---
 configure.ac                                    |   1 +
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/fanotify/.gitignore   |   1 +
 testcases/kernel/syscalls/fanotify/fanotify.h   |  56 ++++-
 testcases/kernel/syscalls/fanotify/fanotify05.c |   1 +
 testcases/kernel/syscalls/fanotify/fanotify13.c | 316 ++++++++++++++++++++++++
 6 files changed, 373 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify13.c
configure.ac +1 -0
index 5ecc92781..9538b2322 100644
@@ -70,6 +70,7 @@ AC_CHECK_FUNCS([ \
     kcmp \
     mkdirat \
     mknodat \
+    name_to_handle_at \
     openat \
     preadv \
     preadv2 \
runtest/syscalls +1 -0
index a1106fb84..e682f5087 100644
@@ -534,6 +534,7 @@ fanotify09 fanotify09
 fanotify10 fanotify10
 fanotify11 fanotify11
 fanotify12 fanotify12
+fanotify13 fanotify13
 
 ioperm01 ioperm01
 ioperm02 ioperm02
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
index 4256b8cd3..16bdd99e5 100644
@@ -10,4 +10,5 @@
 /fanotify10
 /fanotify11
 /fanotify12
+/fanotify13
 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +53 -3

74 lines not on this page · raw message

testcases/kernel/syscalls/fanotify/fanotify05.c +1 -0
index de72e346a..112295709 100644
@@ -11,6 +11,7 @@
  *     Generate enough events without reading them and check that overflow
  *     event is generated.
  */
+#define _GNU_SOURCE
 #include "config.h"
 
 #include <stdio.h>
testcases/kernel/syscalls/fanotify/fanotify13.c new file +316 -0

316 lines not on this page · raw message

Signature · 5 lines
2.16.4


-- 
Matthew Bobrowski
#2 lore raw

PATCH v5 2/4 syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values

In reply to Matthew Bobrowski

A newly defined test file has been introduced to validate that the fanotify interface returns the correct error values upon specifying invalid flags and masks in conjunction with FAN_REPORT_FID. A new line entry within runtest/syscalls for this new test file.

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/fanotify/.gitignore   |   1 +
 testcases/kernel/syscalls/fanotify/fanotify.h   |  25 ++++
 testcases/kernel/syscalls/fanotify/fanotify14.c | 176 ++++++++++++++++++++++++
 4 files changed, 203 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify14.c
runtest/syscalls +1 -0
index e682f5087..56f84824a 100644
@@ -535,6 +535,7 @@ fanotify10 fanotify10
 fanotify11 fanotify11
 fanotify12 fanotify12
 fanotify13 fanotify13
+fanotify14 fanotify14
 
 ioperm01 ioperm01
 ioperm02 ioperm02
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
index 16bdd99e5..bf389c96a 100644
@@ -11,4 +11,5 @@
 /fanotify11
 /fanotify12
 /fanotify13
+/fanotify14
 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +25 -0
index a5ac14acb..f9803c1cc 100644
@@ -69,6 +69,31 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #ifndef FAN_MARK_FILESYSTEM
 #define FAN_MARK_FILESYSTEM	0x00000100
 #endif
+/* New dirent event masks */
+#ifndef FAN_ATTRIB
+#define FAN_ATTRIB		0x00000004
+#endif
+#ifndef FAN_MOVED_FROM
+#define FAN_MOVED_FROM		0x00000040
+#endif
+#ifndef FAN_MOVED_TO
+#define FAN_MOVED_TO		0x00000080
+#endif
+#ifndef FAN_CREATE
+#define FAN_CREATE		0x00000100
+#endif
+#ifndef FAN_DELETE
+#define FAN_DELETE		0x00000200
+#endif
+#ifndef FAN_DELETE_SELF
+#define FAN_DELETE_SELF		0x00000400
+#endif
+#ifndef FAN_MOVE_SELF
+#define FAN_MOVE_SELF		0x00000800
+#endif
+#ifndef FAN_MOVE
+#define FAN_MOVE		(FAN_MOVED_FROM | FAN_MOVED_TO)
+#endif
 #ifndef FAN_OPEN_EXEC
 #define FAN_OPEN_EXEC		0x00001000
 #endif
testcases/kernel/syscalls/fanotify/fanotify14.c new file +176 -0

176 lines not on this page · raw message

Signature · 5 lines
2.16.4


-- 
Matthew Bobrowski
#3 lore raw

PATCH v5 2/4 syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values

Hi!

testcases/kernel/syscalls/fanotify/fanotify14.c line 175

Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify14.c new file +2 -0
+#else
+	TST_TEST_TCONF("System does not have required fanotify support")
                                                                        ^
							I've added
							missing
							semicolon here.
Quoted 1 line

+#endif

And applied whole patchset together with the fix from Amir.

Thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH v5 2/4 syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values

Quoted 4 lines · Cyril Hrubis

Hi!

testcases/kernel/syscalls/fanotify/fanotify14.c line 175

Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify14.c new file +2 -0
+#else
+     TST_TEST_TCONF("System does not have required fanotify support")
Quoted 8 lines
                                                                        ^
                                                        I've added
                                                        missing
                                                        semicolon here.
Quoted 1 line

+#endif

And applied whole patchset together with the fix from Amir.

Hi Cyril,

v5 series has 4 patches and I only see you applied the 3 first patches. This one was not applied:

syscalls/fanotify13: add test coverage for fsid cache bug

The extra patch adds coverage to a bug found round rc5 time whose fix was merged to kernel v5.2-rc6:
c285a2f01d69 fanotify: update connector fsid cache on add mark

Thanks,
Amir.

#5 lore raw

PATCH v5 2/4 syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values

Hi!

Quoted 6 lines

Hi Cyril,

v5 series has 4 patches and I only see you applied the 3 first patches. This one was not applied:

syscalls/fanotify13: add test coverage for fsid cache bug

Looks like the last one didn't make it to my mailbox, the series ends with 3/4, sorry I haven't noticed.

Matthew can you please resend the last one?

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v5 2/4 syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 5 lines

Hi Cyril,

v5 series has 4 patches and I only see you applied the 3 first patches. This one was not applied:

Quoted 6 lines
Quoted 1 line

syscalls/fanotify13: add test coverage for fsid cache bug

Looks like the last one didn't make it to my mailbox, the series ends with 3/4, sorry I haven't noticed.

Matthew can you please resend the last one?

Interesting as to why that never ended up coming through. Anyway, Amir has sent the missing patch through to you.

Signature · 1 line
Matthew Bobrowski
#7 lore raw

PATCH v5 3/4 syscalls/fanotify15: verify fid for dirent events

In reply to Matthew Bobrowski

A new test file that provides coverage for new dirent events has been added. A new line entry within the runtest/syscalls file has been also added to support the testing of these new dirent events.

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/fanotify/.gitignore   |   1 +
 testcases/kernel/syscalls/fanotify/fanotify15.c | 246 ++++++++++++++++++++++++
 3 files changed, 248 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify15.c
runtest/syscalls +1 -0
index 56f84824a..25cb29dab 100644
@@ -536,6 +536,7 @@ fanotify11 fanotify11
 fanotify12 fanotify12
 fanotify13 fanotify13
 fanotify14 fanotify14
+fanotify15 fanotify15
 
 ioperm01 ioperm01
 ioperm02 ioperm02
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
index bf389c96a..68e4cc7aa 100644
@@ -12,4 +12,5 @@
 /fanotify12
 /fanotify13
 /fanotify14
+/fanotify15
 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify15.c new file +246 -0

246 lines not on this page · raw message

Signature · 5 lines
2.16.4


-- 
Matthew Bobrowski
#8 lore raw

PATCH v5 4/4 syscalls/fanotify13: add test coverage for fsid cache bug

In reply to Matthew Bobrowski

This bug was reported by syzbot:
https://lore.kernel.org/linux-fsdevel/CAOQ4uxhsnOXXVCuOT4p4c_koBMFfprWwdtCPGNGhzprFaJZwRA@mail.gmail.com/T/#t

---
 testcases/kernel/syscalls/fanotify/fanotify13.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify13.c +16 -4
index 33ee2f1c8..8f9baacfa 100644
@@ -84,6 +84,7 @@ static struct test_case_t {
 	}
 };
 
+static int nofid_fd;
 static int fanotify_fd;
 static char events_buf[BUF_SIZE];
 static struct event_t event_set[EVENT_MAX];
@@ -280,21 +281,32 @@ out:
 
 static void do_setup(void)
 {
-	int fd;
-
 	/* Check for kernel fanotify support */
-	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
-	SAFE_CLOSE(fd);
+	nofid_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
 
 	/* Create file and directory objects for testing */
 	create_objects();
 
+	/*
+	 * Create a mark on first inode without FAN_REPORT_FID, to test
+	 * uninitialized connector->fsid cache. This mark remains for all test
+	 * cases and is not expected to get any events (no writes in this test).
+	 */
+	if (fanotify_mark(nofid_fd, FAN_MARK_ADD, FAN_CLOSE_WRITE, AT_FDCWD,
+			  FILE_PATH_ONE) == -1) {
+		tst_brk(TBROK | TERRNO,
+			"fanotify_mark(%d, FAN_MARK_ADD, FAN_CLOSE_WRITE, "
+			"AT_FDCWD, "FILE_PATH_ONE") failed",
+			nofid_fd);
+	}
+
 	/* Get the filesystem fsid and file handle for each created object */
 	get_object_stats();
 }
 
 static void do_cleanup(void)
 {
+	SAFE_CLOSE(nofid_fd);
 	if (fanotify_fd > 0)
 		SAFE_CLOSE(fanotify_fd);
 }
Signature · 5 lines
2.16.4


-- 
Matthew Bobrowski
#9 lore raw

v5 cover syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

In reply to Matthew Bobrowski

Hi Amir, Matthew,

LGTM. Just one of this commits fails on centos 6

https://api.travis-ci.org/v3/job/548162141/log.txt
https://travis-ci.org/pevik/ltp/jobs/548162141

gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/usr/src/ltp/include -I/usr/src/ltp/../ltp-build/include -I/usr/src/ltp/include/old/   -L/usr/src/ltp/../ltp-build/lib  /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify01.c   -lltp -o fanotify01
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/usr/src/ltp/include -I/usr/src/ltp/../ltp-build/include -I/usr/src/ltp/include/old/   -L/usr/src/ltp/../ltp-build/lib  /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify02.c   -lltp -o fanotify02

In file included from /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify01.c:21:
/usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:130: error: expected specifier-qualifier-list before '__kernel_fsid_t' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:141: error: expected declaration specifiers or '...' before '__kernel_fsid_t' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: 'struct file_handle' declared inside parameter list /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: its scope is only this definition or declaration, which is probably not what you want /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h: In function 'fanotify_get_fid':
/usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: 'fsid' undeclared (first use in this function) /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: (Each undeclared identifier is reported only once /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: for each function it appears in.) /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:144: warning: unused variable 'mount_id' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: unused parameter 'handle'
In file included from /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify02.c:21:
/usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:130: error: expected specifier-qualifier-list before '__kernel_fsid_t' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:141: error: expected declaration specifiers or '...' before '__kernel_fsid_t' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: 'struct file_handle' declared inside parameter list /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: its scope is only this definition or declaration, which is probably not what you want /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h: In function 'fanotify_get_fid':
/usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: 'fsid' undeclared (first use in this function) /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: (Each undeclared identifier is reported only once /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:150: error: for each function it appears in.) /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:144: warning: unused variable 'mount_id' /usr/src/ltp/testcases/kernel/syscalls/fanotify/fanotify.h:142: warning: unused parameter 'handle'

Kind regards,
Petr

Quoted 37 lines

This patch series contains the changes needed to validate the new FAN_REPORT_FID flag and directory modification event functionality within the fanotify API.

Changes since version 4:

	* Fixed problems with unbalanced file descriptor close.
	* Reorded functions in the test files fanotify13, fanotify14 and
	  fanotify15 so that they all follow a basic template i.e.

	  test()
	  ...
	  do_setup()
	  do_cleanup()

Thank you Amir for your feedback.

Amir Goldstein (1):
syscalls/fanotify13: add test coverage for fsid cache bug

Matthew Bobrowski (3):
syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality syscalls/fanotify14: new test to validate FAN_REPORT_FID interface
return values
syscalls/fanotify15: verify fid for dirent events

 configure.ac                                    |   1 +
 runtest/syscalls                                |   3 +
 testcases/kernel/syscalls/fanotify/.gitignore   |   3 +
 testcases/kernel/syscalls/fanotify/fanotify.h   |  81 +++++-
 testcases/kernel/syscalls/fanotify/fanotify05.c |   1 +
 testcases/kernel/syscalls/fanotify/fanotify13.c | 328 ++++++++++++++++++++++++
 testcases/kernel/syscalls/fanotify/fanotify14.c | 176 +++++++++++++
 testcases/kernel/syscalls/fanotify/fanotify15.c | 246 ++++++++++++++++++
 8 files changed, 836 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify13.c
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify14.c
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify15.c
#10 lore raw

v5 cover syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

Quoted 4 lines · Petr Vorel

Hi Amir, Matthew,

LGTM. Just one of this commits fails on centos 6

Hi Petr,

Can you please try attached patch.

Thanks,
Amir.
-------------- next part --------------
From 7d0feb7d7d9677cf348643bddf10507d2d1f0c3a Mon Sep 17 00:00:00 2001
From: Amir Goldstein <[email protected]>
Date: Thu, 20 Jun 2019 16:53:46 +0300
Subject: [PATCH] syscalls/fanotify: fix build errors on centos 6

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 22 +++++++++++--------
 .../kernel/syscalls/fanotify/fanotify13.c     |  2 +-
 .../kernel/syscalls/fanotify/fanotify15.c     |  2 +-
 3 files changed, 15 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +13 -9
index f9803c1cc..05b4d9f2c 100644
@@ -125,21 +125,25 @@ struct fanotify_event_info_header {
 	uint16_t len;
 };
 
+typedef struct {
+        int     val[2];
+} ltp_fsid_t;
+
 struct fanotify_event_info_fid {
 	struct fanotify_event_info_header hdr;
-	__kernel_fsid_t fsid;
+	ltp_fsid_t fsid;
 	unsigned char handle[0];
 };
 
 #endif
 
+#ifdef HAVE_NAME_TO_HANDLE_AT
 /*
- * Helper function used to obtain __kernel_fsid_t and file_handle objects
- * for a given path. Used by test files correlated to FAN_REPORT_FID
- * functionality.
+ * Helper function used to obtain fsid and file_handle for a given path.
+ * Used by test files correlated to FAN_REPORT_FID functionality.
  */
-static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid,
-			struct file_handle *handle)
+static inline void fanotify_get_fid(const char *path, ltp_fsid_t *fsid,
+				    struct file_handle *handle)
 {
 	int mount_id;
 	struct statfs stats;
@@ -149,7 +153,6 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid,
 			"statfs(%s, ...) failed", path);
 	memcpy(fsid, &stats.f_fsid, sizeof(stats.f_fsid));
 
-#ifdef HAVE_NAME_TO_HANDLE_AT
 	if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, 0) == -1) {
 		if (errno == EOPNOTSUPP) {
 			tst_brk(TCONF,
@@ -159,10 +162,11 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid,
 		tst_brk(TBROK | TERRNO,
 			"name_to_handle_at(AT_FDCWD, %s, ...) failed", path);
 	}
+}
 #else
-	tst_brk(TCONF, "name_to_handle_at() is not implmented");
+#define fanotify_get_fid(path, fsid, handle) \
+	tst_brk(TCONF, "System does not have required name_to_handle_at() support")
 #endif /* HAVE_NAME_TO_HANDLE_AT */
-}
 
 #define INIT_FANOTIFY_MARK_TYPE(t) \
 	{ FAN_MARK_ ## t, "FAN_MARK_" #t }
testcases/kernel/syscalls/fanotify/fanotify13.c +1 -1
index 8f9baacfa..f79322fd0 100644
@@ -40,7 +40,7 @@
 
 struct event_t {
 	unsigned long long expected_mask;
-	__kernel_fsid_t fsid;
+	ltp_fsid_t fsid;
 	struct file_handle handle;
 	char buf[MAX_HANDLE_SZ];
 };
testcases/kernel/syscalls/fanotify/fanotify15.c +1 -1
index 6981b7891..3be913ba4 100644
@@ -37,7 +37,7 @@
 
 struct event_t {
 	unsigned long long mask;
-	__kernel_fsid_t fsid;
+	ltp_fsid_t fsid;
 	struct file_handle handle;
 	char buf[MAX_HANDLE_SZ];
 };
Signature · 1 line
2.17.1
#11 lore raw

v5 cover syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

Quoted 11 lines · Amir Goldstein
Quoted 4 lines · Petr Vorel

Hi Amir, Matthew,

LGTM. Just one of this commits fails on centos 6

Hi Petr,

Can you please try attached patch.

Wait, it's not enough.
I'll post a new patch.

Thanks,
Amir.