New tests for fanotify pre-content events
cover New tests for fanotify pre-content events
Petr,
These are the tests used for the development of the fanotify pre-content (a.k.a HSM) events feature that was merged to v6.14-rc1.
Because this is a new test for a new feature, which is skipped on old kernels, I am posting it early, so that others could run the tests.
Following the request to split out large fanotify LTP tests, I resisted the temptation to add a pre-content events variant to the existing fanotify03 test and I forked it to a new test.
I did however add one test case to fanotify14, because as I wrote before, I find it useful to keep the test matrix of allowed flag combinations within the same test.
I also added two test cases to fanotify03 before forking it for cases that were regressed during the 6.14 devlopment cycle and did not have proper test converage.
The number of test cases in fanotify is still below 10, so I was hoping this addition is still acceptable.
Thanks,
Amir.
Amir Goldstein (4):
fanotify14: Test invalid init flags with permission and pre-content
events
fanotify03: Add test cases for permission events on children
fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
fanotify24: Test open for write of executable files with pre-content
watch
include/lapi/fanotify.h | 12 + runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 3 + .../kernel/syscalls/fanotify/fanotify03.c | 47 +- .../kernel/syscalls/fanotify/fanotify14.c | 20 + .../kernel/syscalls/fanotify/fanotify24.c | 472 ++++++++++++++++++ 7 files changed, 550 insertions(+), 6 deletions(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify24.c
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/4 fanotify14: Test invalid init flags with permission and pre-content events
Those events require an high priority fanotify group.
--- include/lapi/fanotify.h | 5 +++++ .../kernel/syscalls/fanotify/fanotify14.c | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+)
include/lapi/fanotify.h +5 -0
@@ -109,6 +109,9 @@#ifndef FAN_FS_ERROR #define FAN_FS_ERROR 0x00008000#endif +#ifndef FAN_PRE_ACCESS +#define FAN_PRE_ACCESS 0x00100000 +#endif #ifndef FAN_RENAME #define FAN_RENAME 0x10000000#endif
@@ -134,6 +137,8 @@#define LTP_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ FAN_ACCESS_PERM) +#define LTP_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) +struct fanotify_group_type {unsigned int flag;const char *name;
testcases/kernel/syscalls/fanotify/fanotify14.c +20 -0
@@ -239,6 +239,26 @@ static struct test_case_t { .pfd = pipes, .expected_errno = EINVAL, }, +/* permission events in mask with priority < FAN_CLASS_CONTENT are not valid */ + { + .init = FLAGS_DESC(FAN_CLASS_NOTIF), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_ALL_PERM_EVENTS), + .expected_errno = EINVAL, + }, + /* pre-content events in mask with priority < FAN_CLASS_PRE_CONTENT are not valid */ + { + .init = FLAGS_DESC(FAN_CLASS_NOTIF), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_PRE_CONTENT_EVENTS), + .expected_errno = EINVAL, + }, + { + .init = FLAGS_DESC(FAN_CLASS_CONTENT), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_PRE_CONTENT_EVENTS), + .expected_errno = EINVAL, + }, }; static void do_test(unsigned int number)
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/4] fanotify14: Test invalid init flags with permission and pre-content events
Quoted 3 lines · Amir Goldstein
Those events require an high priority fanotify group.
Signed-off-by Amir Goldstein <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 62 lines
--- include/lapi/fanotify.h | 5 +++++ .../kernel/syscalls/fanotify/fanotify14.c | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+)include/lapi/fanotify.h +5
-0@@ -109,6 +109,9 @@#ifndef FAN_FS_ERROR #define FAN_FS_ERROR 0x00008000#endif +#ifndef FAN_PRE_ACCESS +#define FAN_PRE_ACCESS 0x00100000 +#endif #ifndef FAN_RENAME #define FAN_RENAME 0x10000000#endif @@ -134,6 +137,8 @@#define LTP_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ FAN_ACCESS_PERM) +#define LTP_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) +struct fanotify_group_type {unsigned int flag;const char *name;testcases/kernel/syscalls/fanotify/fanotify14.c +20
-0@@ -239,6 +239,26 @@ static struct test_case_t { .pfd = pipes, .expected_errno = EINVAL, }, +/* permission events in mask with priority < FAN_CLASS_CONTENT are not valid */ + { + .init = FLAGS_DESC(FAN_CLASS_NOTIF), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_ALL_PERM_EVENTS), + .expected_errno = EINVAL, + }, + /* pre-content events in mask with priority < FAN_CLASS_PRE_CONTENT are not valid */ + { + .init = FLAGS_DESC(FAN_CLASS_NOTIF), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_PRE_CONTENT_EVENTS), + .expected_errno = EINVAL, + }, + { + .init = FLAGS_DESC(FAN_CLASS_CONTENT), + .mark = FLAGS_DESC(FAN_MARK_INODE), + .mask = FLAGS_DESC(LTP_PRE_CONTENT_EVENTS), + .expected_errno = EINVAL, + }, }; static void do_test(unsigned int number)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
Re: [LTP] [PATCH 1/4] fanotify14: Test invalid init flags with permission and pre-content events
Hi Amir, Jan,
FYI this patch merged.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/4 fanotify03: Add test cases for permission events on children
In reply to Amir GoldsteinVerify that permission events are delivered iff parent is watching children.
--- .../kernel/syscalls/fanotify/fanotify03.c | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify03.c +41 -6
@@ -121,12 +121,29 @@ static struct tcase { {FAN_OPEN_EXEC_PERM, FAN_DENY} } }, + { +"parent watching children, FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM events" , +INIT_FANOTIFY_MARK_TYPE (PARENT ), +FAN_ACCESS_PERM |FAN_OPEN_EXEC_PERM |FAN_EVENT_ON_CHILD ,2 , + { + {FAN_ACCESS_PERM, FAN_DENY}, + {FAN_OPEN_EXEC_PERM, FAN_DENY} + } + }, + { +"parent not watching children, FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM events" , +INIT_FANOTIFY_MARK_TYPE (PARENT ), + FAN_ACCESS_PERM | FAN_OPEN_EXEC_PERM, 0, + { + } + }, }; -static void generate_events (void ) +static void generate_events (struct tcase *tc) {int fd;char *const argv[] = {FILE_EXEC_PATH ,NULL }; +int exp_ret, exp_errno = tc->event_count ?EPERM :0 ;/* * Generate sequence of events
@@ -136,13 +153,25 @@ static void generate_events(void)SAFE_WRITE (SAFE_WRITE_ANY , fd, fname,1 );SAFE_LSEEK (fd,0 ,SEEK_SET ); -if (read (fd, buf,BUF_SIZE ) !=-1 ) + exp_ret = exp_errno ?-1 :1 ; + 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);exit (3 ); + }else if (errno == exp_errno) { +tst_res (TINFO ,"read() got errno %d as expected" , errno); + }SAFE_CLOSE (fd); -if (execve (FILE_EXEC_PATH , argv, environ) !=-1 ) + exp_ret = exp_errno ?-1 :0 ; + errno =0 ; +if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) { +tst_res (TFAIL ,"execve() got errno %d (expected %d)" , errno, exp_errno);exit (5 ); + }else if (errno == exp_errno) { +tst_res (TINFO ,"execve() got errno %d as expected" , errno); + } }static void child_handler (int tmp)
@@ -156,7 +185,7 @@ static void child_handler(int tmp) fd_notify =-1 ; } -static void run_child (void ) +static void run_child (struct tcase *tc) {struct sigaction child_action;
@@ -174,7 +203,7 @@ static void run_child(void)if (child_pid ==0 ) {/* Child will generate events now */ SAFE_CLOSE (fd_notify); -generate_events (); +generate_events (tc);exit (0 ); } }
@@ -220,6 +249,12 @@ static int setup_mark(unsigned int n) fd_notify =SAFE_FANOTIFY_INIT (FAN_CLASS_CONTENT ,O_RDONLY ); +if (mark->flag ==FAN_MARK_PARENT ) { +SAFE_FANOTIFY_MARK (fd_notify,FAN_MARK_ADD | mark->flag, + tc->mask,AT_FDCWD ,MOUNT_PATH ); +return 0 ; + } +for (; i <ARRAY_SIZE (files); i++) {SAFE_FANOTIFY_MARK (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask,AT_FDCWD , files[i]);
@@ -237,7 +272,7 @@ static void test_fanotify(unsigned int n)if (setup_mark (n) !=0 )return ; -run_child (); +run_child (tc);/* * Process events
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] fanotify03: Add test cases for permission events on children
Quoted 4 lines · Amir Goldstein
Verify that permission events are delivered iff parent is watching children.
Signed-off-by Amir Goldstein <[email protected]>
Overall looks ok but:
testcases/kernel/syscalls/fanotify/fanotify03.c static void generate_events(void) · line 161
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +5
-1-if (read (fd, buf,BUF_SIZE ) !=-1 ) + exp_ret = exp_errno ?-1 :1 ; + 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);exit (3 ); + }else if (errno == exp_errno) {
^^ Why is this condition needed? It is always true AFAICT.
testcases/kernel/syscalls/fanotify/fanotify03.c static void generate_events(void) · line 172
Quoted 12 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +7
-1+tst_res (TINFO ,"read() got errno %d as expected" , errno); + }SAFE_CLOSE (fd); -if (execve (FILE_EXEC_PATH , argv, environ) !=-1 ) + exp_ret = exp_errno ?-1 :0 ; + errno =0 ; +if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) { +tst_res (TFAIL ,"execve() got errno %d (expected %d)" , errno, exp_errno);exit (5 ); + }else if (errno == exp_errno) {
^^^ and here as well...
testcases/kernel/syscalls/fanotify/fanotify03.c static void generate_events(void) · line 175
Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +2
-0+tst_res (TINFO ,"execve() got errno %d as expected" , errno); + } }
Honza
Signature · 5 lines
Jan Kara <[email protected]> SUSE Labs, CR -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] fanotify03: Add test cases for permission events on children
Quoted 23 lines · Jan Kara
Quoted 4 lines · Amir Goldstein
Verify that permission events are delivered iff parent is watching children.
Signed-off-by Amir Goldstein <[email protected]>Overall looks ok but:
testcases/kernel/syscalls/fanotify/fanotify03.c static void generate_events(void) · line 161
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +5
-1-if (read (fd, buf,BUF_SIZE ) !=-1 ) + exp_ret = exp_errno ?-1 :1 ; + 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);exit (3 ); + }else if (errno == exp_errno) {^^ Why is this condition needed? It is always true AFAICT.
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +2
-0+tst_res (TINFO ,"read() got errno %d as expected" , errno); + }SAFE_CLOSE (fd);
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify03.c static void generate_events(void) · line 172
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify03.c +5
-1-if (execve (FILE_EXEC_PATH , argv, environ) !=-1 ) + exp_ret = exp_errno ?-1 :0 ; + errno =0 ; +if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) { +tst_res (TFAIL ,"execve() got errno %d (expected %d)" , errno, exp_errno);exit (5 ); + }else if (errno == exp_errno) {^^^ and here as well...Quoted 1 line
+
tst_res(TINFO, "execve() got errno %d as expected", errno);
You are right.
I was "backported" from the pre-content test. The two else statements can be removed in this patch.
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] fanotify03: Add test cases for permission events on children
Hi Amir, Jan,
Quoted 31 lines · Jan Kara
Quoted 30 lines · Amir Goldstein
Quoted 4 lines
Verify that permission events are delivered iff parent is watching children.
Signed-off-by Amir Goldstein <[email protected]>Overall looks ok but:
Review
Quoted 7 lines
(quoted diff) +5
-1- if (read(fd, buf, BUF_SIZE) != -1) + exp_ret = exp_errno ? -1 : 1; + 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); exit(3); + } else if (errno == exp_errno) {^^ Why is this condition needed? It is always true AFAICT.
Quoted 12 lines
(quoted diff) +7
-1+ tst_res(TINFO, "read() got errno %d as expected", errno); + } SAFE_CLOSE(fd); - if (execve(FILE_EXEC_PATH, argv, environ) != -1) + exp_ret = exp_errno ? -1 : 0; + errno = 0; + if (execve(FILE_EXEC_PATH, argv, environ) != exp_ret || errno != exp_errno) { + tst_res(TFAIL, "execve() got errno %d (expected %d)", errno, exp_errno); exit(5); + } else if (errno == exp_errno) {
Quoted 7 lines
Quoted 3 lines
^^^ and here as well...Quoted 1 line
+
tst_res(TINFO, "execve() got errno %d as expected", errno);You are right.
I was "backported" from the pre-content test. The two else statements can be removed in this patch.
FYI I'm going to merge with the diff below (discussed change).
Jan, may I add your RBT?
Kind regards,
Petr
Quoted 2 lines
Thanks,
Amir.
kernel/syscalls/fanotify/fanotify03.c +0 -4
@@ -158,8 +158,6 @@ static void generate_events(struct tcase *tc)if (read (fd, buf,BUF_SIZE ) != exp_ret || errno != exp_errno) {tst_res (TFAIL ,"read() got errno %d (expected %d)" , errno, exp_errno);exit (3 ); - }else if (errno == exp_errno) { -tst_res (TINFO ,"read() got errno %d as expected" , errno); }SAFE_CLOSE (fd);
@@ -169,8 +167,6 @@ static void generate_events(struct tcase *tc)if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) {tst_res (TFAIL ,"execve() got errno %d (expected %d)" , errno, exp_errno);exit (5 ); - }else if (errno == exp_errno) { -tst_res (TINFO ,"execve() got errno %d as expected" , errno); } }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Jan Kara
Reviewed-byRe: [LTP] [PATCH 2/4] fanotify03: Add test cases for permission events on children
Quoted 37 lines · Petr Vorel
Hi Amir, Jan,
Quoted 34 lines · Jan Kara
Quoted 33 lines · Amir Goldstein
Quoted 4 lines
Verify that permission events are delivered iff parent is watching children.
Signed-off-by Amir Goldstein <[email protected]>Overall looks ok but:
Review
Quoted 7 lines
(quoted diff) +5
-1- if (read(fd, buf, BUF_SIZE) != -1) + exp_ret = exp_errno ? -1 : 1; + 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); exit(3); + } else if (errno == exp_errno) {^^ Why is this condition needed? It is always true AFAICT.
Review
Quoted 12 lines
(quoted diff) +7
-1+ tst_res(TINFO, "read() got errno %d as expected", errno); + } SAFE_CLOSE(fd); - if (execve(FILE_EXEC_PATH, argv, environ) != -1) + exp_ret = exp_errno ? -1 : 0; + errno = 0; + if (execve(FILE_EXEC_PATH, argv, environ) != exp_ret || errno != exp_errno) { + tst_res(TFAIL, "execve() got errno %d (expected %d)", errno, exp_errno); exit(5); + } else if (errno == exp_errno) {^^^ and here as well...Quoted 1 line
+
tst_res(TINFO, "execve() got errno %d as expected", errno);
Quoted 7 lines
Quoted 3 lines
You are right.
I was "backported" from the pre-content test. The two else statements can be removed in this patch.FYI I'm going to merge with the diff below (discussed change).
Jan, may I add your RBT?
Yes. Feel free to add:
Honza
Signature · 5 lines
Jan Kara <[email protected]> SUSE Labs, CR -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] fanotify03: Add test cases for permission events on children
Hi Amir, Jan,
...
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
You are right.
I was "backported" from the pre-content test. The two else statements can be removed in this patch.FYI I'm going to merge with the diff below (discussed change).
Jan, may I add your RBT?
Yes. Feel free to add:
Reviewed-by Jan Kara <[email protected]>
Thanks, merged with the change above.
Kind regards,
Petr
Quoted 1 line
Honza
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/4 fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
In reply to Amir GoldsteinFork the test fanotify24 from test fanotify03, replacing the permission event FAN_ACCESS_PERM with the new pre-content event FAN_PRE_ACCESS.
The test is changed to use class FAN_CLASS_PRE_CONTENT, which is required for FAN_PRE_ACCESS and this class also enabled the response with cutomer error code FAN_DENY_ERRNO.
Unlike FAN_ACCESS_PERM, FAN_PRE_ACCESS is also created on write() system call. The test case expected results are adjusted to respond with the default error (EPERM) to open() and write() and to respond with custom errors (EIO, EBUSY) to read() and execve().
Not all fs support pre-content events, so run on all filesystems to excercise FAN_PRE_ACCESS on all supported filesystems.
--- include/lapi/fanotify.h | 7 + runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 3 + .../kernel/syscalls/fanotify/fanotify24.c | 433 ++++++++++++++++++ 5 files changed, 445 insertions(+) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify24.c
include/lapi/fanotify.h +7 -0
@@ -124,6 +124,13 @@#define FAN_EPIDFD -2#endif +/* errno other than EPERM can specified in upper byte of deny response */ +#ifndef FAN_DENY_ERRNO +#define FAN_ERRNO (err) (((((__u32)(err)) & 0xff) << 24)) +#define FAN_DENY_ERRNO (err) (FAN_DENY | FAN_ERRNO(err)) +#define FAN_RESPONSE_ERRNO (res) ((int)((res) >> 24)) +#endif +/* Flags required for unprivileged user group */ #define FANOTIFY_REQUIRED_USER_INIT_FLAGS (FAN_REPORT_FID)
runtest/syscalls +1 -0
@@ -649,6 +649,7 @@ fanotify20 fanotify20 fanotify21 fanotify21 fanotify22 fanotify22 fanotify23 fanotify23 +fanotify24 fanotify24 ioperm01 ioperm01 ioperm02 ioperm02
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
@@ -21,4 +21,5 @@ /fanotify21 /fanotify22 /fanotify23 +/fanotify24 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +3 -0
@@ -277,6 +277,9 @@ static inline void fanotify_flags_err_msg(const char *flags_str,#define FANOTIFY_MARK_FLAGS_ERR_MSG (mark, fail) \ fanotify_flags_err_msg((mark)->name, __FILE__, __LINE__, tst_res_, (fail)) +#define FANOTIFY_EVENTS_ERR_MSG (event, fail) \ + fanotify_flags_err_msg(#event, __FILE__, __LINE__, tst_res_, (fail)) +#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS (flags, fname) \ fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \ fanotify_init_flags_supported_on_fs(flags, fname))
testcases/kernel/syscalls/fanotify/fanotify24.c new file +433 -0
433 lines not on this page · raw message
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 13 lines · Amir Goldstein
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().
Quoted 4 lines
Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>
Looks good to me. I was just wondering whether some bits like generate_events(), mark setup, child setup, main test loop could not be factored out into a helper functions used by both old and new tests?
Honza
Signature · 5 lines
Jan Kara <[email protected]> SUSE Labs, CR -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 15 lines · Jan Kara
Quoted 13 lines · Amir Goldstein
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().
Quoted 8 lines
Quoted 4 lines
Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>Looks good to me. I was just wondering whether some bits like
generate_events(), mark setup, child setup, main test loop could not be factored out into a helper functions used by both old and new tests?
Yes, I agree that forking the tests is bad and that we need much more common helpers.
IIUC, LTP developers are going to try to come up with some proposals for refactoring helpers to split some large fanotify tests [1][2].
My opinion is that factoring out helpers that are useful only for fanotify03,fanotify24 is suboptimal and we need to see if we can create much more generic helpers that could be shared by more tests.
BTW, if you look closer, you will see that generate_events() is quite different between fanotify03 and fanotify24, although it is true that fanotify24 has a more generalized version that follows the expected events more closely.
I did start with extending fanotify03 before I forked it and before the fork generate_events() was even more hard to follow because of the difference in expected events for write() between permission and pre-content events.
Thanks,
Amir.
[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://lore.kernel.org/ltp/20250131164217.GA1135694@pevik/
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 40 lines · Jan Kara
Quoted 15 lines · Amir Goldstein
Quoted 12 lines
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().Quoted 8 lines
Quoted 4 lines
Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>Looks good to me. I was just wondering whether some bits like
generate_events(), mark setup, child setup, main test loop could not be factored out into a helper functions used by both old and new tests?Yes, I agree that forking the tests is bad and that we need much more common helpers.
IIUC, LTP developers are going to try to come up with some proposals for refactoring helpers to split some large fanotify tests [1][2].
My opinion is that factoring out helpers that are useful only for fanotify03,fanotify24 is suboptimal and we need to see if we can create much more generic helpers that could be shared by more tests.
BTW, if you look closer, you will see that
generate_events()is quite different between fanotify03 and fanotify24, although it is true that fanotify24 has a more generalized version that follows the expected events more closely.
Quoted 4 lines
I did start with extending fanotify03 before I forked it and before the fork
generate_events()was even more hard to follow because of the difference in expected events forwrite()between permission and pre-content events.
I'm not happy that tests are nearly identical, but agree that merging them would make readability even harder. Also if there is really no value to run FAN_ACCESS_PERM (fanotify03.c) on all filesystems it would prolong testing.
The only downside of not factoring out common code is that fix in one test will not appear in the other test (it looks to me from what you wrote that you improved generate_events() for fanotify24.c but not for fanotify03.c. Also now is for me to remember remove else if (errno == exp_errno) [1] also for fanotify24.c). We have long history of this in LTP. But I'm also not sure if it's worth factoring out code just for 2 tests. We might reconsider factoring out, but unless Martin or Cyril objects I would keep it for now.
I was looking briefly for code which could be turned into more generic helpers, but so far I haven't found anything. Maybe you have better idea.
FYI there is not only test code and test output readability, but also ability to filter out certain fix. If particular fix is not backported to enterprise kernel (WONTFIX). With one of many tests fails we have no way to distinguish it in the current code (tst_kvercmp2() does not always help). Therefore we prefer to have regression tests in separate files (don't mix them with tests for basic functionality). But that would probably lead to even more code duplicity.
I was thinking whether we could try allow to run only subset of struct tcase items, based on getopt parameter. E.g. run only "inode" marks (first two items), or mount marks (3rd and 4th), ... runtest/syscalls would get more items of particular test. It would prolong testing (for all_filesystems quite significantly) but besides better test output readability + allow to filter out fixes.
Kind regards,
Petr
[1] https://lore.kernel.org/ltp/CAOQ4uxgu16dOsU4uuq66CGqXw6wY8c8jK7sL1QheB8kTPU=X+g@mail.gmail.com/
Quoted 5 lines
Thanks,
Amir.[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://lore.kernel.org/ltp/20250131164217.GA1135694@pevik/
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 50 lines · Petr Vorel
Quoted 41 lines · Jan Kara
Quoted 15 lines · Amir Goldstein
Quoted 12 lines
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().Quoted 8 lines
Quoted 4 lines
Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>Looks good to me. I was just wondering whether some bits like
generate_events(), mark setup, child setup, main test loop could not be factored out into a helper functions used by both old and new tests?Yes, I agree that forking the tests is bad and that we need much more common helpers.
IIUC, LTP developers are going to try to come up with some proposals for refactoring helpers to split some large fanotify tests [1][2].
My opinion is that factoring out helpers that are useful only for fanotify03,fanotify24 is suboptimal and we need to see if we can create much more generic helpers that could be shared by more tests.
BTW, if you look closer, you will see that
generate_events()is quite different between fanotify03 and fanotify24, although it is true that fanotify24 has a more generalized version that follows the expected events more closely.Quoted 4 lines
I did start with extending fanotify03 before I forked it and before the fork
generate_events()was even more hard to follow because of the difference in expected events forwrite()between permission and pre-content events.I'm not happy that tests are nearly identical, but agree that merging them would make readability even harder. Also if there is really no value to run
FAN_ACCESS_PERM(fanotify03.c) on all filesystems it would prolong testing.
Quoted 5 lines
The only downside of not factoring out common code is that fix in one test will not appear in the other test (it looks to me from what you wrote that you improved
generate_events()forfanotify24.cbut not forfanotify03.c. Also now is for me to remember remove else if (errno ==exp_errno) [1] also forfanotify24.c).
Please don't remove these else from fanotify24.
I meant that the else in fanotify03.c are not needed because they came
from the generic generate_events() of fanotify24.c which supports different expected errno values (FAN_DENY_ERRNO(xxx)). fanotify03 does not have FAN_DENY_ERRNO(xxx), so comparing exp_errno is not needed in fanbotify03. It is needed in fanotify24.
Quoted 7 lines
We have long history of this in LTP. But I'm also not sure if it's worth factoring out code just for 2 tests. We might reconsider factoring out, but unless Martin or Cyril objects I would keep it for now.
I was looking briefly for code which could be turned into more generic helpers, but so far I haven't found anything. Maybe you have better idea.
I do not have a better idea.
fanotify03 and fanotify24 are sufficiently similar to dup a lot of code and sufficiently different to make common code hard or more complex.
IMO, the code that is relatively common to many fanotify tests is the event read and process loop.
I think it should be doable to make these loops use common helpers for reading and verifying the expected events, but it is not a small job to make those helpers generic enough to cater all the different tests that check different event formats.
Thanks,
Amir.
Quoted 23 lines
FYI there is not only test code and test output readability, but also ability to filter out certain fix. If particular fix is not backported to enterprise kernel (WONTFIX). With one of many tests fails we have no way to distinguish it in the current code (
tst_kvercmp2()does not always help). Therefore we prefer to have regression tests in separate files (don't mix them with tests for basic functionality). But that would probably lead to even more code duplicity.I was thinking whether we could try allow to run only subset of struct tcase items, based on getopt parameter. E.g. run only "inode" marks (first two items), or mount marks (3rd and 4th), ... runtest/syscalls would get more items of particular test. It would prolong testing (for
all_filesystemsquite significantly) but besides better test output readability + allow to filter out fixes.Kind regards,
Petr[1] https://lore.kernel.org/ltp/CAOQ4uxgu16dOsU4uuq66CGqXw6wY8c8jK7sL1QheB8kTPU=X+g@mail.gmail.com/
Quoted 5 lines
Thanks,
Amir.[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://lore.kernel.org/ltp/20250131164217.GA1135694@pevik/
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 57 lines · Petr Vorel
Quoted 50 lines
Quoted 41 lines · Jan Kara
Quoted 15 lines · Amir Goldstein
Quoted 12 lines
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().Quoted 8 lines
Quoted 4 lines
Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>Looks good to me. I was just wondering whether some bits like
generate_events(), mark setup, child setup, main test loop could not be factored out into a helper functions used by both old and new tests?Yes, I agree that forking the tests is bad and that we need much more common helpers.
IIUC, LTP developers are going to try to come up with some proposals for refactoring helpers to split some large fanotify tests [1][2].
My opinion is that factoring out helpers that are useful only for fanotify03,fanotify24 is suboptimal and we need to see if we can create much more generic helpers that could be shared by more tests.
BTW, if you look closer, you will see that
generate_events()is quite different between fanotify03 and fanotify24, although it is true that fanotify24 has a more generalized version that follows the expected events more closely.Quoted 4 lines
I did start with extending fanotify03 before I forked it and before the fork
generate_events()was even more hard to follow because of the difference in expected events forwrite()between permission and pre-content events.I'm not happy that tests are nearly identical, but agree that merging them would make readability even harder. Also if there is really no value to run
FAN_ACCESS_PERM(fanotify03.c) on all filesystems it would prolong testing.Quoted 5 lines
The only downside of not factoring out common code is that fix in one test will not appear in the other test (it looks to me from what you wrote that you improved
generate_events()forfanotify24.cbut not forfanotify03.c. Also now is for me to remember remove else if (errno ==exp_errno) [1] also forfanotify24.c).
Quoted 7 lines
Please don't remove these else from fanotify24.
I meant that the else infanotify03.care not needed because they camefrom the generic
generate_events()offanotify24.cwhich supports different expected errno values (FAN_DENY_ERRNO(xxx)). fanotify03 does not haveFAN_DENY_ERRNO(xxx), so comparingexp_errnois not needed in fanbotify03. It is needed in fanotify24.
Ah, sure, I'll keep them.
Quoted 13 lines
Quoted 6 lines
We have long history of this in LTP. But I'm also not sure if it's worth factoring out code just for 2 tests. We might reconsider factoring out, but unless Martin or Cyril objects I would keep it for now.
I was looking briefly for code which could be turned into more generic helpers, but so far I haven't found anything. Maybe you have better idea.
I do not have a better idea.
fanotify03 and fanotify24 are sufficiently similar to dup a lot of code and sufficiently different to make common code hard or more complex.
Quoted 7 lines
IMO, the code that is relatively common to many fanotify tests is the event read and process loop.
I think it should be doable to make these loops use common helpers for reading and verifying the expected events, but it is not a small job to make those helpers generic enough to cater all the different tests that check different event formats.
Thanks for a hint. I'll see if I find a time and come up with something useful.
We briefly talk with Cyril about this and agree that we don't want to block this. I'll wait little longer if Cyril wants to add something and merge during tomorrow. Again, thanks a lot for updating fanotify testcases in LTP.
Kind regards,
Petr
Quoted 26 lines
Thanks,
Amir.Quoted 23 lines
FYI there is not only test code and test output readability, but also ability to filter out certain fix. If particular fix is not backported to enterprise kernel (WONTFIX). With one of many tests fails we have no way to distinguish it in the current code (
tst_kvercmp2()does not always help). Therefore we prefer to have regression tests in separate files (don't mix them with tests for basic functionality). But that would probably lead to even more code duplicity.I was thinking whether we could try allow to run only subset of struct tcase items, based on getopt parameter. E.g. run only "inode" marks (first two items), or mount marks (3rd and 4th), ... runtest/syscalls would get more items of particular test. It would prolong testing (for
all_filesystemsquite significantly) but besides better test output readability + allow to filter out fixes.Kind regards,
Petr[1] https://lore.kernel.org/ltp/CAOQ4uxgu16dOsU4uuq66CGqXw6wY8c8jK7sL1QheB8kTPU=X+g@mail.gmail.com/
Quoted 5 lines
Thanks,
Amir.[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://lore.kernel.org/ltp/20250131164217.GA1135694@pevik/
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Hi all,
FYI remaining 3rd and 4th patch merged.
Thanks to all!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Quoted 5 lines · Petr Vorel
Hi all,
FYI remaining 3rd and 4th patch merged.
Thanks to all!
Thank !you!
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
In reply to Amir GoldsteinQuoted 31 lines · Amir Goldstein
Fork the test fanotify24 from test fanotify03, replacing the permission event
FAN_ACCESS_PERMwith the new pre-content eventFAN_PRE_ACCESS.The test is changed to use class
FAN_CLASS_PRE_CONTENT, which is required forFAN_PRE_ACCESSand this class also enabled the response with cutomer error codeFAN_DENY_ERRNO.Unlike
FAN_ACCESS_PERM,FAN_PRE_ACCESSis also created onwrite()system call. The test case expected results are adjusted to respond with the default error (EPERM) toopen()andwrite()and to respond with custom errors (EIO, EBUSY) toread()andexecve().Not all fs support pre-content events, so run on all filesystems to excercise
FAN_PRE_ACCESSon all supported filesystems.Signed-off-by Amir Goldstein <[email protected]>--- include/lapi/fanotify.h | 7 + runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 3 + .../kernel/syscalls/fanotify/fanotify24.c | 433 ++++++++++++++++++ 5 files changed, 445 insertions(+) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify24.cinclude/lapi/fanotify.h +0
-0
include/lapi/fanotify.h line 133
Quoted 10 lines
include/lapi/fanotify.h +7
-0@@ -124,6 +124,13 @@#define FAN_EPIDFD -2#endif +/* errno other than EPERM can specified in upper byte of deny response */ +#ifndef FAN_DENY_ERRNO +#define FAN_ERRNO (err) (((((__u32)(err)) & 0xff) << 24)) +#define FAN_DENY_ERRNO (err) (FAN_DENY | FAN_ERRNO(err)) +#define FAN_RESPONSE_ERRNO (res) ((int)((res) >> 24)) +#endif +
This does not work with latest+greatest kernel headers since there FAN_DENY_ERRNO is defined but FAN_RESPONSE_ERRNO is not. Therefore this ends up in a compile error:
fanotify24.c: In function ‘expected_errno’:
fanotify24.c:166:24: error: implicit declaration of function ‘FAN_RESPONSE_ERRNO’; did you mean ‘FAN_DENY_ERRNO’? [-Wimplicit-function-declaration]
166 | return FAN_RESPONSE_ERRNO(response);
| ^~~~~~~~~~~~~~~~~~
| FAN_DENY_ERRNOFWIW, converting the above to:
/* errno other than EPERM can specified in upper byte of deny response */ #ifndef FAN_DENY_ERRNO
#define FAN_ERRNO(err) (((((__u32)(err)) & 0xff) << 24)) #define FAN_DENY_ERRNO(err) (FAN_DENY | FAN_ERRNO(err)) #endif
#ifndef FAN_RESPONSE_ERRNO
#define FAN_RESPONSE_ERRNO(res) ((int)((res) >> 24)) #endif
works for me.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/4 fanotify24: Test open for write of executable files with pre-content watch
In reply to Amir GoldsteinWatching pre-content events should allow opening an executable file for write and executing a file that is open for write.
We have an existing test where the exectable file is not watched by pre-content events.
We add a new test case, where the executable file is watched for FAN_PRE_ACCESS pre-content event and access is allowed.
In the former case (not watched), execution should fail with ETXTBSY and in the latter case (per-content watched) execution should succeed.
When allowing access events, we allow for multiple events, because read() may generate more than a single access event.
--- .../kernel/syscalls/fanotify/fanotify24.c | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify24.c +41 -2
@@ -144,6 +144,15 @@ static struct tcase { { } }, + { +"inode mark, FAN_PRE_ACCESS event allowed" , +INIT_FANOTIFY_MARK_TYPE (INODE ), +FAN_PRE_ACCESS ,1 , + { + /* This allows multiple FAN_PRE_ACCESS events */ + {FAN_PRE_ACCESS, FAN_ALLOW}, + } + }, };static int expected_errno (unsigned int response)
@@ -206,6 +215,21 @@ static void generate_events(struct tcase *tc) exp_errno =expected_errno (event->response); event++; +/* +* If execve() is allowed by permission events, check if executing a +* file that open for write is allowed. +* HSM needs to be able to write to file during pre-content event, so it +* requires that a file being executed can be open for write, which also +* means that a file open for write can be executed. +* Therefore, ETXTBSY is to be expected when file is not being watched +* at all or being watched but not with pre-content events in mask. +*/ +if (!exp_errno) { + fd =SAFE_OPEN (FILE_EXEC_PATH ,O_RDWR ); +if (!tc->event_count) + exp_errno =ETXTBSY ; + } + exp_ret = exp_errno ?-1 :0 ; errno =0 ;if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) {
@@ -214,6 +238,9 @@ static void generate_events(struct tcase *tc) }else if (errno == exp_errno) {tst_res (TINFO ,"execve() got errno %d as expected" , errno); } + +if (fd >=0 ) +SAFE_CLOSE (fd); }static void child_handler (int tmp)
@@ -309,8 +336,8 @@ static void test_fanotify(unsigned int n)/* * Process events * -* tc->count + 1 is to accommodate for checking the child process -* return value +* tc->count + 1 is to let read() wait for child process to exit +* and to accomodate for extra access events */ while (test_num < tc->event_count +1 && fd_notify !=-1 ) {struct fanotify_event_metadata *event;
@@ -319,6 +346,7 @@ static void test_fanotify(unsigned int n)/* Get more events */ ret =read (fd_notify, event_buf + len,EVENT_BUF_LEN - len); +/* Received SIGCHLD */ if (fd_notify ==-1 )break ;if (ret <0 ) {
@@ -329,6 +357,17 @@ static void test_fanotify(unsigned int n) len += ret; } +/* +* If we got an event after the last event and the last event was +* allowed then assume this is another event of the same type. +* This is to accomodate for the fact that a single read() may +* generate an unknown number of access permission events if they +* are allowed. +*/ +if (test_num >0 && test_num == tc->event_count && + event_set[test_num-1 ].response ==FAN_ALLOW ) + test_num--; + event = (struct fanotify_event_metadata *)&event_buf[i];/* Permission events cannot be merged, so the event mask * reported should exactly match the event mask within the
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] fanotify24: Test open for write of executable files with pre-content watch
Quoted 9 lines · Amir Goldstein
Watching pre-content events should allow opening an executable file for write and executing a file that is open for write.
We have an existing test where the exectable file is not watched by pre-content events.
We add a new test case, where the executable file is watched for
FAN_PRE_ACCESSpre-content event and access is allowed.
Quoted 7 lines
In the former case (not watched), execution should fail with ETXTBSY and in the latter case (per-content watched) execution should succeed.
When allowing access events, we allow for multiple events, because
read()may generate more than a single access event.Signed-off-by Amir Goldstein <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 96 lines
--- .../kernel/syscalls/fanotify/fanotify24.c | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-)testcases/kernel/syscalls/fanotify/fanotify24.c +41
-2@@ -144,6 +144,15 @@ static struct tcase { { } }, + { +"inode mark, FAN_PRE_ACCESS event allowed" , +INIT_FANOTIFY_MARK_TYPE (INODE ), +FAN_PRE_ACCESS ,1 , + { + /* This allows multiple FAN_PRE_ACCESS events */ + {FAN_PRE_ACCESS, FAN_ALLOW}, + } + }, };static int expected_errno (unsigned int response)@@ -206,6 +215,21 @@ static void generate_events(struct tcase *tc) exp_errno =expected_errno (event->response); event++; +/* +* If execve() is allowed by permission events, check if executing a +* file that open for write is allowed. +* HSM needs to be able to write to file during pre-content event, so it +* requires that a file being executed can be open for write, which also +* means that a file open for write can be executed. +* Therefore, ETXTBSY is to be expected when file is not being watched +* at all or being watched but not with pre-content events in mask. +*/ +if (!exp_errno) { + fd =SAFE_OPEN (FILE_EXEC_PATH ,O_RDWR ); +if (!tc->event_count) + exp_errno =ETXTBSY ; + } + exp_ret = exp_errno ?-1 :0 ; errno =0 ;if (execve (FILE_EXEC_PATH , argv, environ) != exp_ret || errno != exp_errno) {@@ -214,6 +238,9 @@ static void generate_events(struct tcase *tc) }else if (errno == exp_errno) {tst_res (TINFO ,"execve() got errno %d as expected" , errno); } + +if (fd >=0 ) +SAFE_CLOSE (fd); }static void child_handler (int tmp)@@ -309,8 +336,8 @@ static void test_fanotify(unsigned int n)/* * Process events * -* tc->count + 1 is to accommodate for checking the child process -* return value +* tc->count + 1 is to let read() wait for child process to exit +* and to accomodate for extra access events */ while (test_num < tc->event_count +1 && fd_notify !=-1 ) {struct fanotify_event_metadata *event;@@ -319,6 +346,7 @@ static void test_fanotify(unsigned int n)/* Get more events */ ret =read (fd_notify, event_buf + len,EVENT_BUF_LEN - len); +/* Received SIGCHLD */ if (fd_notify ==-1 )break ;if (ret <0 ) {@@ -329,6 +357,17 @@ static void test_fanotify(unsigned int n) len += ret; } +/* +* If we got an event after the last event and the last event was +* allowed then assume this is another event of the same type. +* This is to accomodate for the fact that a single read() may +* generate an unknown number of access permission events if they +* are allowed. +*/ +if (test_num >0 && test_num == tc->event_count && + event_set[test_num-1 ].response ==FAN_ALLOW ) + test_num--; + event = (struct fanotify_event_metadata *)&event_buf[i];/* Permission events cannot be merged, so the event mask * reported should exactly match the event mask within the 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