Skip to contentSkip to conversation

syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

PATCH Superseded Matthew Bobrowski 2 participants 7 messages Jun 17, 2019 – Jun 19, 2019

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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 3:
* Added missing _GNU_SOURCE feature macro from syscalls/fanotify05.
* Moved fanotify_get_fid() in fanotify.h outside #ifndef FAN_REPORT_FID to accommodate for the situation where LTP is built on a system that has newer (5.1 >) kernel headers installed.

Thanks for your help Amir and Jan.

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 ++++-
 .../kernel/syscalls/fanotify/fanotify05.c     |   1 +
 .../kernel/syscalls/fanotify/fanotify13.c     | 313 ++++++++++++++++++
 .../kernel/syscalls/fanotify/fanotify14.c     | 171 ++++++++++
 .../kernel/syscalls/fanotify/fanotify15.c     | 245 ++++++++++++++
 8 files changed, 815 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.21.0


-- 
Matthew Bobrowski
#1 lore raw

PATCH v4 1/3 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 +++-
 .../kernel/syscalls/fanotify/fanotify05.c     |   1 +
 .../kernel/syscalls/fanotify/fanotify13.c     | 313 ++++++++++++++++++
 6 files changed, 370 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 +313 -0

313 lines not on this page · raw message

Signature · 5 lines
2.21.0


-- 
Matthew Bobrowski
#2 lore raw

PATCH v4 1/3 syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality

Quoted 23 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +23 -0
+static void do_test(unsigned int number)
+{
+       unsigned int i;
+       int len, fds[ARRAY_SIZE(objects)];
+
+       struct file_handle *event_file_handle;
+       struct fanotify_event_metadata *metadata;
+       struct fanotify_event_info_fid *event_fid;
+       struct test_case_t *tc = &test_cases[number];
+       struct fanotify_mark_type *mark = &tc->mark;
+
+       tst_res(TINFO,
+               "Test #%d: FAN_REPORT_FID with mark flag: %s",
+               number, mark->name);
+
+       fanotify_fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
+       if (fanotify_fd == -1) {
+               if (errno == EINVAL) {
+                       tst_res(TCONF,
+                               "FAN_REPORT_FID not supported by kernel");
+                       return;
+               }
+               tst_brk(TBROK | TERRNO,

testcases/kernel/syscalls/fanotify/fanotify13.c line 198

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +10 -0
+                       "fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, "
+                       "O_RDONLY) failed");
+       }
+
+       /* Place marks on a set of objects and setup the expected masks
+        * for each event that is expected to be generated
+        */
+       if (setup_marks(fanotify_fd, tc) != 0)
+               return;
+

Sorry, just notices a test bug.
fanotify_fd needs to be closed before returning from this function, because next test case is going to overwrite fanotify_fd. do_cleanup() is called only at end of entire test or on tst_brk().

This needs to be fixed for fanotify14 and fanotify15 as well.

Also, please see my fanotify_dentry branch on github for an extra patch to fanotify13 to cover a bug reported by syzbot:

https://lore.kernel.org/linux-fsdevel/CAOQ4uxhsnOXXVCuOT4p4c_koBMFfprWwdtCPGNGhzprFaJZwRA@mail.gmail.com/T/#t

Please include this extra patch in your next series posting.

Thanks,
Amir.

#3 lore raw

PATCH v4 1/3 syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality

Quoted 39 lines · Amir Goldstein
Quoted 23 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +23 -0
+static void do_test(unsigned int number)
+{
+       unsigned int i;
+       int len, fds[ARRAY_SIZE(objects)];
+
+       struct file_handle *event_file_handle;
+       struct fanotify_event_metadata *metadata;
+       struct fanotify_event_info_fid *event_fid;
+       struct test_case_t *tc = &test_cases[number];
+       struct fanotify_mark_type *mark = &tc->mark;
+
+       tst_res(TINFO,
+               "Test #%d: FAN_REPORT_FID with mark flag: %s",
+               number, mark->name);
+
+       fanotify_fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
+       if (fanotify_fd == -1) {
+               if (errno == EINVAL) {
+                       tst_res(TCONF,
+                               "FAN_REPORT_FID not supported by kernel");
+                       return;
+               }
+               tst_brk(TBROK | TERRNO,

testcases/kernel/syscalls/fanotify/fanotify13.c line 198

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +10 -0
+                       "fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, "
+                       "O_RDONLY) failed");
+       }
+
+       /* Place marks on a set of objects and setup the expected masks
+        * for each event that is expected to be generated
+        */
+       if (setup_marks(fanotify_fd, tc) != 0)
+               return;
+

Sorry, just notices a test bug.
fanotify_fd needs to be closed before returning from this function, because next test case is going to overwrite fanotify_fd. do_cleanup() is called only at end of entire test or on tst_brk().

Quoted 1 line

This needs to be fixed for fanotify14 and fanotify15 as well.

Ah, yes. Thank you Amir and good spotting. I've also updated TST_TEST_CONF() to TST_TEST_TCONF(). The branch containing these updates can be found here:
- https://github.com/matthewbobrowski/ltp/commits/fanotify_dirent

Please check.

Quoted 6 lines

Also, please see my fanotify_dentry branch on github for an extra patch to fanotify13 to cover a bug reported by syzbot:

https://lore.kernel.org/linux-fsdevel/CAOQ4uxhsnOXXVCuOT4p4c_koBMFfprWwdtCPGNGhzprFaJZwRA@mail.gmail.com/T/#t

Please include this extra patch in your next series posting.

No problem. Applied on top of my fanotify_dirent branch (above).

Signature · 1 line
Matthew Bobrowski
#4 lore raw

PATCH v4 1/3 syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality

Quoted 41 lines · Matthew Bobrowski
Quoted 39 lines · Amir Goldstein
Quoted 23 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +23 -0
+static void do_test(unsigned int number)
+{
+       unsigned int i;
+       int len, fds[ARRAY_SIZE(objects)];
+
+       struct file_handle *event_file_handle;
+       struct fanotify_event_metadata *metadata;
+       struct fanotify_event_info_fid *event_fid;
+       struct test_case_t *tc = &test_cases[number];
+       struct fanotify_mark_type *mark = &tc->mark;
+
+       tst_res(TINFO,
+               "Test #%d: FAN_REPORT_FID with mark flag: %s",
+               number, mark->name);
+
+       fanotify_fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
+       if (fanotify_fd == -1) {
+               if (errno == EINVAL) {
+                       tst_res(TCONF,
+                               "FAN_REPORT_FID not supported by kernel");
+                       return;
+               }
+               tst_brk(TBROK | TERRNO,

testcases/kernel/syscalls/fanotify/fanotify13.c line 198

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify13.c new file +10 -0
+                       "fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, "
+                       "O_RDONLY) failed");
+       }
+
+       /* Place marks on a set of objects and setup the expected masks
+        * for each event that is expected to be generated
+        */
+       if (setup_marks(fanotify_fd, tc) != 0)
+               return;
+

Sorry, just notices a test bug.
fanotify_fd needs to be closed before returning from this function, because next test case is going to overwrite fanotify_fd. do_cleanup() is called only at end of entire test or on tst_brk().

Quoted 8 lines
Quoted 1 line

This needs to be fixed for fanotify14 and fanotify15 as well.

Ah, yes. Thank you Amir and good spotting. I've also updated TST_TEST_CONF() to TST_TEST_TCONF(). The branch containing these updates can be found here:
- https://github.com/matthewbobrowski/ltp/commits/fanotify_dirent

Please check.

There were still problems with unbalanced close.
I fixes them up and pushed to my branch.

Most ltp tests are written like this:
do_test()
...
do_setup()
do_cleanup()

and for a good reason so it is easy to pair up full test resource setup with full test resource cleanup.
This includes resources that are allocated not per test case and not per test loop
(e.g. ./fanotify13 -i 2)

I reordered the tests code to match this pattern.
Please hold off with posting v5, because I want to see that after we fix the fsid cache bug, the new test will pass.

Thanks,
Amir.

#5 lore raw

PATCH v4 2/3 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 +++
 .../kernel/syscalls/fanotify/fanotify14.c     | 171 ++++++++++++++++++
 4 files changed, 198 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 +171 -0

171 lines not on this page · raw message

Signature · 5 lines
2.21.0


-- 
Matthew Bobrowski
#6 lore raw

PATCH v4 3/3 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 +
 .../kernel/syscalls/fanotify/fanotify15.c     | 245 ++++++++++++++++++
 3 files changed, 247 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 +245 -0

245 lines not on this page · raw message

Signature · 5 lines
2.21.0


-- 
Matthew Bobrowski