linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] fanotify fixes for v6.15-rc3
@ 2025-04-18 19:39 Amir Goldstein
  2025-04-18 19:39 ` [PATCH 1/2] fanotify: fix flush of mntns marks Amir Goldstein
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Amir Goldstein @ 2025-04-18 19:39 UTC (permalink / raw)
  To: Jan Kara; +Cc: Miklos Szeredi, Christian Brauner, linux-fsdevel

Jan,

I was working on adding support for FAN_MARK_MNTNS inside user ns
and ran into this bug.

Unfortunately, this is Easter weekend and on Sunday I am going for
two weeks vacation, so I won't be able to handle review comments on
these patches until at least rc5.

If you are ok with the bug fix, you may fast track it and if the test
needs fixing, I can do that when I get back, or feel free to fix it as
you see fit.

Thanks,
Amir.

Amir Goldstein (2):
  fanotify: fix flush of mntns marks
  selftests/fs/mount-notify: test also remove/flush of mntns marks

 fs/notify/fanotify/fanotify_user.c            |  7 +--
 include/linux/fsnotify_backend.h              | 15 -----
 .../mount-notify/mount-notify_test.c          | 57 +++++++++++++++----
 3 files changed, 47 insertions(+), 32 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] fanotify: fix flush of mntns marks
  2025-04-18 19:39 [PATCH 0/2] fanotify fixes for v6.15-rc3 Amir Goldstein
@ 2025-04-18 19:39 ` Amir Goldstein
  2025-04-18 19:39 ` [PATCH 2/2] selftests/fs/mount-notify: test also remove/flush " Amir Goldstein
  2025-04-24 11:16 ` [PATCH 0/2] fanotify fixes for v6.15-rc3 Jan Kara
  2 siblings, 0 replies; 4+ messages in thread
From: Amir Goldstein @ 2025-04-18 19:39 UTC (permalink / raw)
  To: Jan Kara; +Cc: Miklos Szeredi, Christian Brauner, linux-fsdevel

fanotify_mark(fd, FAN_MARK_FLUSH | FAN_MARK_MNTNS, ...)
was incorrectly implemented and causes flush of mount marks.

Fixes: ("0f46d81f2bce fanotify: notify on mount attach and detach")
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/notify/fanotify/fanotify_user.c |  7 +------
 include/linux/fsnotify_backend.h   | 15 ---------------
 2 files changed, 1 insertion(+), 21 deletions(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index f2d840ae4ded..87f861e9004f 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -1961,12 +1961,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
 		return -EINVAL;
 
 	if (mark_cmd == FAN_MARK_FLUSH) {
-		if (mark_type == FAN_MARK_MOUNT)
-			fsnotify_clear_vfsmount_marks_by_group(group);
-		else if (mark_type == FAN_MARK_FILESYSTEM)
-			fsnotify_clear_sb_marks_by_group(group);
-		else
-			fsnotify_clear_inode_marks_by_group(group);
+		fsnotify_clear_marks_by_group(group, obj_type);
 		return 0;
 	}
 
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 6cd8d1d28b8b..fc27b53c58c2 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -907,21 +907,6 @@ extern void fsnotify_wait_marks_destroyed(void);
 /* Clear all of the marks of a group attached to a given object type */
 extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
 					  unsigned int obj_type);
-/* run all the marks in a group, and clear all of the vfsmount marks */
-static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
-{
-	fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
-}
-/* run all the marks in a group, and clear all of the inode marks */
-static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
-{
-	fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE);
-}
-/* run all the marks in a group, and clear all of the sn marks */
-static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group)
-{
-	fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB);
-}
 extern void fsnotify_get_mark(struct fsnotify_mark *mark);
 extern void fsnotify_put_mark(struct fsnotify_mark *mark);
 extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] selftests/fs/mount-notify: test also remove/flush of mntns marks
  2025-04-18 19:39 [PATCH 0/2] fanotify fixes for v6.15-rc3 Amir Goldstein
  2025-04-18 19:39 ` [PATCH 1/2] fanotify: fix flush of mntns marks Amir Goldstein
@ 2025-04-18 19:39 ` Amir Goldstein
  2025-04-24 11:16 ` [PATCH 0/2] fanotify fixes for v6.15-rc3 Jan Kara
  2 siblings, 0 replies; 4+ messages in thread
From: Amir Goldstein @ 2025-04-18 19:39 UTC (permalink / raw)
  To: Jan Kara; +Cc: Miklos Szeredi, Christian Brauner, linux-fsdevel

Regression test for FAN_MARK_MNTFS | FAN_MARK_FLUSH bug.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../mount-notify/mount-notify_test.c          | 57 +++++++++++++++----
 1 file changed, 46 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
index 4a2d5c454fd1..59a71f22fb11 100644
--- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
+++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
@@ -48,8 +48,16 @@ static uint64_t get_mnt_id(struct __test_metadata *const _metadata,
 
 static const char root_mntpoint_templ[] = "/tmp/mount-notify_test_root.XXXXXX";
 
+static const int mark_cmds[] = {
+	FAN_MARK_ADD,
+	FAN_MARK_REMOVE,
+	FAN_MARK_FLUSH
+};
+
+#define NUM_FAN_FDS ARRAY_SIZE(mark_cmds)
+
 FIXTURE(fanotify) {
-	int fan_fd;
+	int fan_fd[NUM_FAN_FDS];
 	char buf[256];
 	unsigned int rem;
 	void *next;
@@ -61,7 +69,7 @@ FIXTURE(fanotify) {
 
 FIXTURE_SETUP(fanotify)
 {
-	int ret;
+	int i, ret;
 
 	ASSERT_EQ(unshare(CLONE_NEWNS), 0);
 
@@ -89,20 +97,34 @@ FIXTURE_SETUP(fanotify)
 	self->root_id = get_mnt_id(_metadata, "/");
 	ASSERT_NE(self->root_id, 0);
 
-	self->fan_fd = fanotify_init(FAN_REPORT_MNT, 0);
-	ASSERT_GE(self->fan_fd, 0);
-
-	ret = fanotify_mark(self->fan_fd, FAN_MARK_ADD | FAN_MARK_MNTNS,
-			    FAN_MNT_ATTACH | FAN_MNT_DETACH, self->ns_fd, NULL);
-	ASSERT_EQ(ret, 0);
+	for (i = 0; i < NUM_FAN_FDS; i++) {
+		self->fan_fd[i] = fanotify_init(FAN_REPORT_MNT | FAN_NONBLOCK,
+						0);
+		ASSERT_GE(self->fan_fd[i], 0);
+		ret = fanotify_mark(self->fan_fd[i], FAN_MARK_ADD |
+				    FAN_MARK_MNTNS,
+				    FAN_MNT_ATTACH | FAN_MNT_DETACH,
+				    self->ns_fd, NULL);
+		ASSERT_EQ(ret, 0);
+		// On fd[0] we do an extra ADD that changes nothing.
+		// On fd[1]/fd[2] we REMOVE/FLUSH which removes the mark.
+		ret = fanotify_mark(self->fan_fd[i], mark_cmds[i] |
+				    FAN_MARK_MNTNS,
+				    FAN_MNT_ATTACH | FAN_MNT_DETACH,
+				    self->ns_fd, NULL);
+		ASSERT_EQ(ret, 0);
+	}
 
 	self->rem = 0;
 }
 
 FIXTURE_TEARDOWN(fanotify)
 {
+	int i;
+
 	ASSERT_EQ(self->rem, 0);
-	close(self->fan_fd);
+	for (i = 0; i < NUM_FAN_FDS; i++)
+		close(self->fan_fd[i]);
 
 	ASSERT_EQ(fchdir(self->orig_root), 0);
 
@@ -123,8 +145,21 @@ static uint64_t expect_notify(struct __test_metadata *const _metadata,
 	unsigned int thislen;
 
 	if (!self->rem) {
-		ssize_t len = read(self->fan_fd, self->buf, sizeof(self->buf));
-		ASSERT_GT(len, 0);
+		ssize_t len;
+		int i;
+
+		for (i = NUM_FAN_FDS - 1; i >= 0; i--) {
+			len = read(self->fan_fd[i], self->buf,
+				   sizeof(self->buf));
+			if (i > 0) {
+				// Groups 1,2 should get EAGAIN
+				ASSERT_EQ(len, -1);
+				ASSERT_EQ(errno, EAGAIN);
+			} else {
+				// Group 0 should get events
+				ASSERT_GT(len, 0);
+			}
+		}
 
 		self->rem = len;
 		self->next = (void *) self->buf;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] fanotify fixes for v6.15-rc3
  2025-04-18 19:39 [PATCH 0/2] fanotify fixes for v6.15-rc3 Amir Goldstein
  2025-04-18 19:39 ` [PATCH 1/2] fanotify: fix flush of mntns marks Amir Goldstein
  2025-04-18 19:39 ` [PATCH 2/2] selftests/fs/mount-notify: test also remove/flush " Amir Goldstein
@ 2025-04-24 11:16 ` Jan Kara
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2025-04-24 11:16 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Jan Kara, Miklos Szeredi, Christian Brauner, linux-fsdevel

Hi!

On Fri 18-04-25 21:39:01, Amir Goldstein wrote:
> I was working on adding support for FAN_MARK_MNTNS inside user ns
> and ran into this bug.
> 
> Unfortunately, this is Easter weekend and on Sunday I am going for
> two weeks vacation, so I won't be able to handle review comments on
> these patches until at least rc5.
> 
> If you are ok with the bug fix, you may fast track it and if the test
> needs fixing, I can do that when I get back, or feel free to fix it as
> you see fit.

Thanks for the patches. I've picked them up in my tree.

								Honza

> 
> Thanks,
> Amir.
> 
> Amir Goldstein (2):
>   fanotify: fix flush of mntns marks
>   selftests/fs/mount-notify: test also remove/flush of mntns marks
> 
>  fs/notify/fanotify/fanotify_user.c            |  7 +--
>  include/linux/fsnotify_backend.h              | 15 -----
>  .../mount-notify/mount-notify_test.c          | 57 +++++++++++++++----
>  3 files changed, 47 insertions(+), 32 deletions(-)
> 
> -- 
> 2.34.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-24 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 19:39 [PATCH 0/2] fanotify fixes for v6.15-rc3 Amir Goldstein
2025-04-18 19:39 ` [PATCH 1/2] fanotify: fix flush of mntns marks Amir Goldstein
2025-04-18 19:39 ` [PATCH 2/2] selftests/fs/mount-notify: test also remove/flush " Amir Goldstein
2025-04-24 11:16 ` [PATCH 0/2] fanotify fixes for v6.15-rc3 Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).