Thread (19 messages) 19 messages, 6 authors, 2025-02-13

Re: [PATCH v5 2/3] fanotify: notify on mount attach and detach

From: Miklos Szeredi <miklos@szeredi.hu>
Date: 2025-02-13 12:00:07
Also in: linux-fsdevel, selinux

On Tue, 11 Feb 2025 at 16:50, Jan Kara [off-list ref] wrote:
On Wed 29-01-25 17:58:00, Miklos Szeredi wrote:
quoted
      fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
-     if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_EVENT_FLAGS) &&
+     if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_MOUNT_EVENTS|FANOTIFY_EVENT_FLAGS) &&
I understand why you need this but the condition is really hard to
understand now and the comment above it becomes out of date. Perhaps I'd
move this and the following two checks for FAN_RENAME and
FANOTIFY_PRE_CONTENT_EVENTS into !FAN_GROUP_FLAG(group, FAN_REPORT_MNT)
branch to make things more obvious?
Okay.  git diff -w below.

Thanks,
Miklos
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -1936,6 +1936,8 @@ static int do_fanotify_mark(int fanotify_fd,
unsigned int flags, __u64 mask,
             mark_type != FAN_MARK_INODE)
                return -EINVAL;

+       /* The following checks are not relevant to mount events */
+       if (!FAN_GROUP_FLAG(group, FAN_REPORT_MNT)) {
                /*
                 * Events that do not carry enough information to report
                 * event->fd require a group that supports reporting fid.  Those
@@ -1944,21 +1946,25 @@ static int do_fanotify_mark(int fanotify_fd,
unsigned int flags, __u64 mask,
                 * point.
                 */
                fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
-       if (mask &
~(FANOTIFY_FD_EVENTS|FANOTIFY_MOUNT_EVENTS|FANOTIFY_EVENT_FLAGS) &&
+               if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_EVENT_FLAGS) &&
                    (!fid_mode || mark_type == FAN_MARK_MOUNT))
                        return -EINVAL;

                /*
-        * FAN_RENAME uses special info type records to report the old and
-        * new parent+name.  Reporting only old and new parent id is less
-        * useful and was not implemented.
+                * FAN_RENAME uses special info type records to report the old
+                * and new parent+name.  Reporting only old and new parent id is
+                * less useful and was not implemented.
                 */
                if (mask & FAN_RENAME && !(fid_mode & FAN_REPORT_NAME))
                        return -EINVAL;

-       /* Pre-content events are not currently generated for directories. */
+               /*
+                * Pre-content events are not currently generated for
+                * directories.
+                */
                if (mask & FANOTIFY_PRE_CONTENT_EVENTS && mask & FAN_ONDIR)
                        return -EINVAL;
+       }

        if (mark_cmd == FAN_MARK_FLUSH) {
                if (mark_type == FAN_MARK_MOUNT)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help