public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Jan Kara <jack@suse.cz>, ltp@lists.linux.it
Subject: [LTP] [PATCH 4/5] fanotify21: Test reporting event with RDWR fd on RO mount
Date: Wed, 22 Jan 2025 18:24:39 +0100	[thread overview]
Message-ID: <20250122172440.506677-5-amir73il@gmail.com> (raw)
In-Reply-To: <20250122172440.506677-1-amir73il@gmail.com>

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.

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,
 	},
 	{
 		"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);
+		}
+	}
+
 	/*
 	 * Generate the event in either self or a child process. Event
 	 * generation in a child process is done so that the FAN_NOPIDFD case
@@ -157,7 +177,16 @@ static void do_test(unsigned int num)
 	 * Read all of the queued events into the provided event
 	 * buffer.
 	 */
-	len = SAFE_READ(0, fanotify_fd, event_buf, sizeof(event_buf));
+	len = read(fanotify_fd, event_buf, sizeof(event_buf));
+	if (len < 0) {
+		if (tc->remount_ro && errno == EROFS) {
+			tst_res(TPASS, "cannot read event with rw fd from a ro fs");
+			return;
+		}
+		tst_brk(TBROK | TERRNO, "reading fanotify events failed");
+	} else if (tc->remount_ro) {
+		tst_res(TFAIL, "got unexpected event with rw fd from a ro fs");
+	}
 	while (i < len) {
 		struct fanotify_event_metadata *event;
 		struct fanotify_event_info_pidfd *info;
@@ -297,6 +326,7 @@ static struct tst_test test = {
 	.cleanup = do_cleanup,
 	.all_filesystems = 1,
 	.needs_root = 1,
+	.mount_device = 1,
 	.mntpoint = MOUNT_PATH,
 	.forks_child = 1,
 };
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2025-01-22 17:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 17:24 [LTP] [PATCH 0/5] LTP fanotify tests for v6.13 Amir Goldstein
2025-01-22 17:24 ` [LTP] [PATCH 1/5] fanotify13: Verify that we did not get an extra event Amir Goldstein
2025-01-23 17:18   ` Petr Vorel
2025-01-24 10:11     ` Petr Vorel
2025-01-24 10:33       ` Amir Goldstein
2025-01-24 12:45         ` Petr Vorel
2025-01-22 17:24 ` [LTP] [PATCH 2/5] fanotify13: Add test case for FAN_DELETE_SELF Amir Goldstein
2025-01-22 17:24 ` [LTP] [PATCH 3/5] fanotify05: Test reporting overflow event with FAN_REPORT_FD_ERROR Amir Goldstein
2025-01-24  7:44   ` Petr Vorel
2025-01-22 17:24 ` Amir Goldstein [this message]
2025-01-24  8:01   ` [LTP] [PATCH 4/5] fanotify21: Test reporting event with RDWR fd on RO mount Petr Vorel
2025-01-22 17:24 ` [LTP] [PATCH 5/5] fanotify21: Test reporting fd open errors with FAN_REPORT_FD_ERROR Amir Goldstein
2025-01-24  8:09   ` Petr Vorel
2025-01-22 20:50 ` [LTP] [PATCH 0/5] LTP fanotify tests for v6.13 Petr Vorel
2025-01-23 13:09   ` Amir Goldstein
2025-01-23 13:31     ` Cyril Hrubis
2025-01-24 10:46   ` Cyril Hrubis
2025-01-24 11:32     ` Petr Vorel
2025-01-30 20:07     ` Petr Vorel
2025-01-31 14:16       ` Amir Goldstein
2025-01-31 16:42         ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250122172440.506677-5-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=jack@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox