[LTP] [PATCH 4/5] fanotify21: Test reporting event with RDWR fd on RO mount

Petr Vorel pvorel@suse.cz
Fri Jan 24 09:01:21 CET 2025


Hi Amir, all,

> When event_f_flags request to open O_RDWR files for event->fd, the
> event listener should not get events with fd on a read-only mount.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
LGTM.

> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  .../kernel/syscalls/fanotify/fanotify21.c     | 34 +++++++++++++++++--
>  1 file changed, 32 insertions(+), 2 deletions(-)

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index d54930f05..4324019fa 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -21,6 +21,7 @@
>  #include <ctype.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <sys/mount.h>
>  #include "tst_test.h"
>  #include "tst_safe_stdio.h"
>  #include "tst_safe_macros.h"
> @@ -45,16 +46,25 @@ static struct test_case_t {
>  	char *name;
>  	int fork;
>  	int want_pidfd_err;
> +	int remount_ro;
>  } test_cases[] = {
>  	{
>  		"return a valid pidfd for event created by self",
>  		0,
>  		0,
> +		0,
nit: given how many parameters fanotify tests get over time I would use
designated initializers. I can do it after the release.


>  	},
>  	{
>  		"return invalid pidfd for event created by terminated child",
>  		1,
>  		FAN_NOPIDFD,
> +		0,
> +	},
> +	{
> +		"fail to open rw fd for event created on read-only mount",
> +		0,
> +		0,
> +		1,
>  	},
>  };

> @@ -122,7 +132,7 @@ static void do_setup(void)
>  	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
>  						    TEST_FILE);

> -	fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_PIDFD, O_RDONLY);
> +	fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_PIDFD, O_RDWR);
>  	SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
>  			   TEST_FILE);

> @@ -143,6 +153,16 @@ static void do_test(unsigned int num)

>  	tst_res(TINFO, "Test #%d: %s", num, tc->name);

> +	if (tc->remount_ro) {
> +		/* SAFE_MOUNT fails to remount FUSE */
> +		if (mount(tst_device->dev, MOUNT_PATH, tst_device->fs_type,
> +			  MS_REMOUNT|MS_RDONLY, NULL) != 0) {
> +			tst_brk(TFAIL,
> +				"filesystem %s failed to remount readonly",
> +				tst_device->fs_type);
> +		}
> +	}
nit: I would join two if into single one.

Kind regards,
Petr


More information about the ltp mailing list