Re: [PATCH v5 2/3] fanotify: notify on mount attach and detach
Miklos Szeredi <[email protected]> Thu, 13 Feb 2025 12:59:55 +0100
| Newsgroups | org.kernel.vger.selinux-refpolicy,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-security-module,org.kernel.vger.selinux |
|---|---|
| Message-ID | <CAJfpegs2qoZHG4P+WiopDo92MxHQ_0QrZi0qMz7niannGFiPDQ@mail.gmail.com> |
On Tue, 11 Feb 2025 at 16:50, Jan Kara <[email protected]> wrote: > > On Wed 29-01-25 17:58:00, Miklos Szeredi wrote: > > 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)