[LTP] [PATCH 1/5] fanotify13: Verify that we did not get an extra event
Amir Goldstein
amir73il@gmail.com
Fri Jan 24 11:33:13 CET 2025
On Fri, Jan 24, 2025 at 11:11 AM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Amir, all,
> > Hi Amir, all,
>
> > > For example, verify that we did not get an event on a directory object
> > > without requesting FAN_ONDIR. Also, report a test failure if no events
> > > received at all instead of blocking on read of fanotify_fd.
>
> > > With this change, the test fails with overlayfs variants over btrfs,
> > > because the size of fid of overalyfs over btrfs is about 90 bytes and
> > > the events on the three objects do not all fit into a single 256 bytes
> > > buffer read. Increase the size of the events buffer to fix this failure.
>
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > ---
> > > .../kernel/syscalls/fanotify/fanotify13.c | 22 ++++++++++++++++---
> > > 1 file changed, 19 insertions(+), 3 deletions(-)
>
> > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c
> > > index 5cd857707..16fd99ba1 100644
> > > --- a/testcases/kernel/syscalls/fanotify/fanotify13.c
> > > +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c
> > > @@ -34,7 +34,7 @@
> > > #include "fanotify.h"
>
> > > #define PATH_LEN 128
> > > -#define BUF_SIZE 256
> > > +#define BUF_SIZE 1024
> > > #define DIR_ONE "dir_one"
> > > #define FILE_ONE "file_one"
> > > #define FILE_TWO "file_two"
> > > @@ -130,10 +130,15 @@ static int setup_marks(unsigned int fd, struct test_case_t *tc)
> > > SAFE_FANOTIFY_MARK(fd, FAN_MARK_ADD | mark->flag, tc->mask,
> > > AT_FDCWD, objects[i].path);
>
> > > - /* Setup the expected mask for each generated event */
> > > + /*
> > > + * Setup the expected mask for each generated event.
> > > + * No events are expected on directory without FAN_ONDIR.
> > > + */
> > > event_set[i].expected_mask = tc->mask;
> > > if (!objects[i].is_dir)
> > > event_set[i].expected_mask &= ~FAN_ONDIR;
> > > + else if (!(event_set[i].expected_mask & FAN_ONDIR))
> > > + event_set[i].expected_mask = 0;
> > > }
> > > return 0;
> > > }
> > > @@ -163,7 +168,8 @@ static void do_test(unsigned int number)
> > > return;
> > > }
>
> > > - fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
> > > + fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID |
> > > + FAN_NONBLOCK, O_RDONLY);
>
> > > /*
> > > * Place marks on a set of objects and setup the expected masks
> > > @@ -279,6 +285,16 @@ static void do_test(unsigned int number)
> > > FSID_VAL_MEMBER(event_fid->fsid, 1),
> > > *(unsigned long *) event_file_handle->f_handle);
> > > }
> > > +
> > > + /*
> > > + * Verify that we did not get an extra event, for example, that we did
> > > + * not get an event on directory without FAN_ONDIR.
> > > + */
> > > + if (event_set[i].expected_mask) {
> > > + tst_res(TFAIL,
> > > + "Did not get an expected event (expected: %llx)",
> > > + event_set[i].expected_mask);
>
> > I verified that on openSUSE on x86_64 test properly fails with 6.12.9:
> > fanotify13.c:282: TFAIL: handle_bytes (0) returned in event does not equal to handle_bytes (24) returned in name_to_handle_at(2)
>
> > and works with 6.12.10. So far so good.
>
> > But when testing on other archs, 6.12.10 fails on aarch64 and ppc64le:
>
> > fanotify13.c:339: TFAIL: Did not get an expected event (expected: 200)
>
> > That's a different failure than on 6.12.9.
>
> Also fanotify13.c for the same reason on s390x on various SLES (enterprise)
> kernels based on various mainline kernels (6.4, 5.3.18, ...).
>
> fanotify13.c:341: TFAIL: Did not get an expected event (expected: 3403000018)
>
> (Just a different mask than on aarch64 and ppc64le.)
>
This mask is out of bound garbage at event_set[EVENT_MAX]
> @Cyril: due the above I suggest to merge before release only fanotify05.c and
> fanotify21.c changes.
>
> Kind regards,
> Petr
>
> > Any hint what could be wrong?
That would be the simplest fix:
--- a/testcases/kernel/syscalls/fanotify/fanotify13.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify13.c
@@ -48,7 +48,7 @@
#define FILE_ONE "file_one"
#define FILE_TWO "file_two"
#define MOUNT_PATH "tstmnt"
-#define EVENT_MAX ARRAY_SIZE(objects)
+#define EVENT_MAX (ARRAY_SIZE(objects)+1)
Thanks,
Amir.
More information about the ltp
mailing list