Test support for new fanotify FAN_REPORT_PIDFD feature
v2 cover Test support for new fanotify FAN_REPORT_PIDFD feature
Hi,
This patch series introduces LTP tests for the new fanotify FAN_REPORT_PIDFD feature which has been merged as part of the v5.15 release.
I've addressed the minor nits that came out of the first round of review, which can be found here [0].
[0] https://lore.kernel.org/ltp/[email protected]/
Matthew Bobrowski (2):
syscalls/fanotify20: add new test for FAN_REPORT_PIDFD syscalls/fanotify21: add new test checking the returned pidfd from
fanotify in FAN_REPORT_PIDFD mode
configure.ac | 2 +- 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 ++++++++++++++++++ 5 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify20.c create mode 100644 testcases/kernel/syscalls/fanotify/fanotify21.c
Signature · 6 lines
2.33.1.1089.g2158813163f-goog /M -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 syscalls/fanotify20: add new test for FAN_REPORT_PIDFD
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.
---
Changes since v1:
- Introduced a new macro REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL() that is responsible for testing whether the supplied initialization flags are supported by the underlying kernel. This is used from do_setup(). Using this is less ambiguous then using something like REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS().
configure.ac | 2 +- testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 26 ++++ .../kernel/syscalls/fanotify/fanotify20.c | 128 ++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify20.c
configure.ac +1 -1
@@ -159,7 +159,7 @@ AC_CHECK_MEMBERS([struct utsname.domainname],,,[ 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_header],,,[#include <sys/fanotify.h>]) +AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>]) AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>]) AC_CHECK_TYPES([struct file_handle],,,[
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
@@ -17,4 +17,5 @@ /fanotify17 /fanotify18 /fanotify19 +/fanotify20 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +26 -0
@@ -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])
@@ -352,6 +373,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;
testcases/kernel/syscalls/fanotify/fanotify20.c new file +128 -0
128 lines not on this page · raw message
Signature · 6 lines
2.33.1.1089.g2158813163f-goog /M -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] syscalls/fanotify20: add new test for FAN_REPORT_PIDFD
Quoted 13 lines · Matthew Bobrowski
This test ensures that the fanotify API returns the expected error status code
-EINVALwhen an invalid flag is supplied alongside the newFAN_REPORT_PIDFDinitialization flag. Currently,FAN_REPORT_TIDis the only initialization flag that is not permitted in conjunction withFAN_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.
Signed-off-by Matthew Bobrowski <[email protected]>Reviewed-by Amir Goldstein <[email protected]>
Quoted 8 lines
---
Changes since v1:
- Introduced a new macroREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL()that is responsible for testing whether the supplied initialization flags are supported by the underlying kernel. This is used fromdo_setup(). Using this is less ambiguous then using something likeREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS().
Not like this.
Please start your branch with the first two prep patches from Gabriel's LTP post (including my reviewed-by tag) preserving Gabriel's authorship and signed-of-by and adding your own signed-off-by.
Your LTP tests are expected to be merged before Gabriel's test because your tests are for a 5.15 feature.
Once your tests are merge, Gabriel would be able to rebase on master and drop his prep patches.
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] syscalls/fanotify20: add new test for FAN_REPORT_PIDFD
Quoted 29 lines · Amir Goldstein
Quoted 13 lines · Matthew Bobrowski
This test ensures that the fanotify API returns the expected error status code
-EINVALwhen an invalid flag is supplied alongside the newFAN_REPORT_PIDFDinitialization flag. Currently,FAN_REPORT_TIDis the only initialization flag that is not permitted in conjunction withFAN_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.
Signed-off-by Matthew Bobrowski <[email protected]>Reviewed-by Amir Goldstein <[email protected]>Quoted 8 lines
---
Changes since v1:
- Introduced a new macroREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL()that is responsible for testing whether the supplied initialization flags are supported by the underlying kernel. This is used fromdo_setup(). Using this is less ambiguous then using something likeREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS().Not like this.
Please start your branch with the first two prep patches from Gabriel's LTP post (including my reviewed-by tag) preserving Gabriel's authorship and signed-of-by and adding your own signed-off-by.
Quoted 4 lines
Your LTP tests are expected to be merged before Gabriel's test because your tests are for a 5.15 feature.
Once your tests are merge, Gabriel would be able to rebase on master and drop his prep patches.
Am I reading all the words, or only some of the words?
AFAICT, the macro that I've defined here is different to that of what has been implemented in Gabriel's series.
/M
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] syscalls/fanotify20: add new test for FAN_REPORT_PIDFD
Quoted 36 lines · Matthew Bobrowski
Quoted 29 lines · Amir Goldstein
Quoted 13 lines · Matthew Bobrowski
This test ensures that the fanotify API returns the expected error status code
-EINVALwhen an invalid flag is supplied alongside the newFAN_REPORT_PIDFDinitialization flag. Currently,FAN_REPORT_TIDis the only initialization flag that is not permitted in conjunction withFAN_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.
Signed-off-by Matthew Bobrowski <[email protected]>Reviewed-by Amir Goldstein <[email protected]>Quoted 8 lines
---
Changes since v1:
- Introduced a new macroREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL()that is responsible for testing whether the supplied initialization flags are supported by the underlying kernel. This is used fromdo_setup(). Using this is less ambiguous then using something likeREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS().Not like this.
Please start your branch with the first two prep patches from Gabriel's LTP post (including my reviewed-by tag) preserving Gabriel's authorship and signed-of-by and adding your own signed-off-by.Quoted 4 lines
Your LTP tests are expected to be merged before Gabriel's test because your tests are for a 5.15 feature.
Once your tests are merge, Gabriel would be able to rebase on master and drop his prep patches.
Quoted 5 lines
Am I reading all the words, or only some of the words?
AFAICT, the macro that I've defined here is different to that of what has been implemented in Gabriel's series.
My bad.
I wasn't paying attention to the difference.
It wouldn't hurt to split the macro patch anyway.
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] syscalls/fanotify20: add new test for FAN_REPORT_PIDFD
Quoted 39 lines · Amir Goldstein
Quoted 38 lines · Matthew Bobrowski
Quoted 29 lines · Amir Goldstein
Quoted 13 lines · Matthew Bobrowski
This test ensures that the fanotify API returns the expected error status code
-EINVALwhen an invalid flag is supplied alongside the newFAN_REPORT_PIDFDinitialization flag. Currently,FAN_REPORT_TIDis the only initialization flag that is not permitted in conjunction withFAN_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.
Signed-off-by Matthew Bobrowski <[email protected]>Reviewed-by Amir Goldstein <[email protected]>Quoted 8 lines
---
Changes since v1:
- Introduced a new macroREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL()that is responsible for testing whether the supplied initialization flags are supported by the underlying kernel. This is used fromdo_setup(). Using this is less ambiguous then using something likeREQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS().Not like this.
Please start your branch with the first two prep patches from Gabriel's LTP post (including my reviewed-by tag) preserving Gabriel's authorship and signed-of-by and adding your own signed-off-by.Quoted 4 lines
Your LTP tests are expected to be merged before Gabriel's test because your tests are for a 5.15 feature.
Once your tests are merge, Gabriel would be able to rebase on master and drop his prep patches.Am I reading all the words, or only some of the words?
Quoted 7 lines
Quoted 3 lines
AFAICT, the macro that I've defined here is different to that of what has been implemented in Gabriel's series.
My bad.
I wasn't paying attention to the difference.
It wouldn't hurt to split the macro patch anyway.
Right, I'll split and repost the series.
Thanks for the review!
/M
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 syscalls/fanotify21: add new test checking the returned pidfd from fanotify in FAN_REPORT_PIDFD mode
In reply to Matthew Bobrowski via ltpA new test that performs verification on the values returned within the struct fanotify_event_info_pidfd record when the notification group has been intialized in FAN_REPORT_PIDFD mode.
---
Changes since v1:
- Adapted do_setup() to make use of the REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL() rather than open coding it.
- For parsing procfs information, rather than reimplementing parsing utility functions, make use of the existing SAFE_FILE_LINES_SCANF() library function.
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
@@ -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.33.1.1089.g2158813163f-goog /M -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] syscalls/fanotify21: add new test checking the returned pidfd from fanotify in FAN_REPORT_PIDFD mode
testcases/kernel/syscalls/fanotify/fanotify21.c line 280
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +10
-0+next_event: + i += event->event_len; +if (event->fd >=0 ) +SAFE_CLOSE (event->fd); + +if (info && info->pidfd >=0 ) +SAFE_CLOSE (info->pidfd); + +if (event_pidfd_fdinfo) +free (event_pidfd_fdinfo);
Need to reset event_pidfd_fdinfo = NULL
to avoid double free in do_cleanup
testcases/kernel/syscalls/fanotify/fanotify21.c line 292
Quoted 12 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +12
-0+ } +} + +static void do_cleanup (void ) +{ +if (fanotify_fd >=0 ) +SAFE_CLOSE (fanotify_fd); + +if (self_pidfd_fdinfo) +free (self_pidfd_fdinfo); +} +
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] syscalls/fanotify21: add new test checking the returned pidfd from fanotify in FAN_REPORT_PIDFD mode
Quoted 5 lines · Amir Goldstein
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +5
-0+next_event: + i += event->event_len; +if (event->fd >=0 ) +SAFE_CLOSE (event->fd); +
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify21.c line 280
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +5
-0+if (info && info->pidfd >=0 ) +SAFE_CLOSE (info->pidfd); + +if (event_pidfd_fdinfo) +free (event_pidfd_fdinfo);Need to reset
event_pidfd_fdinfo= NULL
to avoid double free indo_cleanup
But, the variable event_pidfd_fdinfo is not referenced nor is visible outside the scope of the do_test() function and therefore no double free would occur, right?
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c line 290
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +10
-0+ } +} + +static void do_cleanup (void ) +{ +if (fanotify_fd >=0 ) +SAFE_CLOSE (fanotify_fd); + +if (self_pidfd_fdinfo) +free (self_pidfd_fdinfo);
Variables self_pidfd_fdinfo do_cleanup() and event_pidfd_fdinfo do_test() are different.
/M
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] syscalls/fanotify21: add new test checking the returned pidfd from fanotify in FAN_REPORT_PIDFD mode
Quoted 20 lines · Matthew Bobrowski
Quoted 5 lines · Amir Goldstein
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +5
-0+next_event: + i += event->event_len; +if (event->fd >=0 ) +SAFE_CLOSE (event->fd); +Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify21.c line 280
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +5
-0+if (info && info->pidfd >=0 ) +SAFE_CLOSE (info->pidfd); + +if (event_pidfd_fdinfo) +free (event_pidfd_fdinfo);Need to reset
event_pidfd_fdinfo= NULL
to avoid double free indo_cleanupBut, the variable
event_pidfd_fdinfois not referenced nor is visible outside the scope of thedo_test()function and therefore no double free would occur, right?
Quoted 14 lines
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c line 290
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c new file +10
-0+ } +} + +static void do_cleanup (void ) +{ +if (fanotify_fd >=0 ) +SAFE_CLOSE (fanotify_fd); + +if (self_pidfd_fdinfo) +free (self_pidfd_fdinfo);Variables
self_pidfd_fdinfodo_cleanup()andevent_pidfd_fdinfodo_test()are different.
Right. my bad :)
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp