Skip to contentSkip to conversation

syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

PATCH Superseded Matthew Bobrowski 2 participants 6 messages May 19, 2019 – Jun 16, 2019

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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 2:
* Added an ifdef statement within fanotify_get_fid() to check for name_to_handle_at() support.

Matthew Bobrowski (3):
syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality syscalls/fanotify14: new test to validate FAN_REPORT_FID interface 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/fanotify13.c     | 313 ++++++++++++++++++
 .../kernel/syscalls/fanotify/fanotify14.c     | 171 ++++++++++
 .../kernel/syscalls/fanotify/fanotify15.c     | 245 ++++++++++++++
 7 files changed, 814 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 · 4 lines
2.21.0

-- 
Matthew Bobrowski
#1 lore raw

PATCH v3 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.

---
 configure.ac                                  |   1 +
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/fanotify/.gitignore |   1 +
 testcases/kernel/syscalls/fanotify/fanotify.h |  56 +++-
 .../kernel/syscalls/fanotify/fanotify13.c     | 313 ++++++++++++++++++
 5 files changed, 369 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify13.c
configure.ac +1 -0
index 53ad784d7..ac4d85b0e 100644
@@ -68,6 +68,7 @@ AC_CHECK_FUNCS([ \
     kcmp \
     mkdirat \
     mknodat \
+    name_to_handle_at \
     openat \
     preadv \
     preadv2 \
runtest/syscalls +1 -0
index 2b8ca719b..dfdc6cbf9 100644
@@ -537,6 +537,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/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 v3 1/3 syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality

Quoted 11 lines · Matthew Bobrowski

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.

Quoted 3 lines

---

Matthew,

Sorry for the delay, I've found some build warning/errors that need fixing.

Quoted 95 lines
 configure.ac                                  |   1 +
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/fanotify/.gitignore |   1 +
 testcases/kernel/syscalls/fanotify/fanotify.h |  56 +++-
 .../kernel/syscalls/fanotify/fanotify13.c     | 313 ++++++++++++++++++
 5 files changed, 369 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify13.c
configure.ac +1 -0
index 53ad784d7..ac4d85b0e 100644
@@ -68,6 +68,7 @@ AC_CHECK_FUNCS([ \
     kcmp \
     mkdirat \
     mknodat \
+    name_to_handle_at \
     openat \
     preadv \
     preadv2 \
runtest/syscalls +1 -0
index 2b8ca719b..dfdc6cbf9 100644
@@ -537,6 +537,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 +28 -3
index 14654b7c7..d6e259002 100644
@@ -29,6 +29,11 @@
 #define        __FANOTIFY_H__
 
 #include "config.h"
+#include <sys/statfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
 
 #if defined(HAVE_SYS_FANOTIFY_H)
 
@@ -57,9 +62,6 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
 #ifndef FAN_REPORT_TID
 #define FAN_REPORT_TID         0x00000100
 #endif
-#ifndef FAN_REPORT_FID
-#define FAN_REPORT_FID         0x00000200
-#endif
 
 #ifndef FAN_MARK_INODE
 #define FAN_MARK_INODE         0
@@ -89,6 +91,54 @@ struct fanotify_mark_type {
        const char * name;
 };
 
+#ifndef FAN_REPORT_FID
+#define FAN_REPORT_FID         0x00000200
+
+struct fanotify_event_info_header {
+       uint8_t info_type;
+       uint8_t pad;
+       uint16_t len;
+};
+
+struct fanotify_event_info_fid {
+       struct fanotify_event_info_header hdr;
+       __kernel_fsid_t fsid;
+       unsigned char handle[0];
+};
+
+/*
+ * 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.
+ */
+static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid,
+                       struct file_handle *handle)
+{

testcases/kernel/syscalls/fanotify/fanotify.h struct fanotify_mark_type { · line 126

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify.h +10 -0
+       int mount_id;
+       struct statfs stats;
+
+       if (statfs(path, &stats) == -1)
+               tst_brk(TBROK | TERRNO,
+                       "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) {

name_to_handle_at requires #define _GNU_SOURCE, which are missing in fanotify05.c and fanotify14.c. Please add the missing define to those tests
before any includes.

Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify.h +4 -0
+               if (errno == EOPNOTSUPP) {
+                       tst_brk(TCONF,
+                               "filesystem %s does not support file handles",
+                               tst_device->fs_type);

testcases/kernel/syscalls/fanotify/fanotify.h struct fanotify_mark_type { · line 140

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify.h +10 -0
+               }
+               tst_brk(TBROK | TERRNO,
+                       "name_to_handle_at(AT_FDCWD, %s, ...) failed", path);
+       }
+#else
+       tst_brk(TCONF, "name_to_handle_at() is not implmented");
+#endif /* HAVE_NAME_TO_HANDLE_AT */
+}
+
+#endif

The definition of fanotify_get_fid() should be outside #ifndef FAN_REPORT_FID

Because if new kernel (5.1) headers are installed
fanotify_get_fid() still needs to be defined.

Please fix rebase and re-post the series or ask me to do it if you are too busy.

Thanks,
Amir.

#3 lore raw

PATCH v3 2/3 syscalls/fanotify14: new test to validate FAN_REPORT_FID 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 dfdc6cbf9..5c62895b0 100644
@@ -538,6 +538,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 d6e259002..92fc78dcc 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
#4 lore raw

PATCH v3 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 added. A new line entry within the runtest/syscalls file has been also added to support this new test file.

---
 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 5c62895b0..2f9f14736 100644
@@ -539,6 +539,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
#5 lore raw

v3 cover syscalls/fanotify: FAN_REPORT_FID and Directory Modification Events

In reply to Matthew Bobrowski
Quoted 27 lines · Matthew Bobrowski

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 2:
* Added an ifdef statement within fanotify_get_fid() to check for name_to_handle_at() support.

Matthew Bobrowski (3):
syscalls/fanotify13: new test to verify FAN_REPORT_FID functionality syscalls/fanotify14: new test to validate FAN_REPORT_FID interface 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/fanotify13.c     | 313 ++++++++++++++++++
 .../kernel/syscalls/fanotify/fanotify14.c     | 171 ++++++++++
 .../kernel/syscalls/fanotify/fanotify15.c     | 245 ++++++++++++++
 7 files changed, 814 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
Quoted 1 line

--

Hi Cyril,

Just wanted to make sure there was nothing blocking this patch set (apart from your limited review time)

Thanks,
Amir.