1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/fanotify.h>
3 #include <linux/fcntl.h>
4 #include <linux/file.h>
6 #include <linux/anon_inodes.h>
7 #include <linux/fsnotify_backend.h>
8 #include <linux/init.h>
9 #include <linux/mount.h>
10 #include <linux/namei.h>
11 #include <linux/poll.h>
12 #include <linux/security.h>
13 #include <linux/syscalls.h>
14 #include <linux/slab.h>
15 #include <linux/types.h>
16 #include <linux/uaccess.h>
17 #include <linux/compat.h>
18 #include <linux/sched/signal.h>
19 #include <linux/memcontrol.h>
21 #include <asm/ioctls.h>
23 #include "../../mount.h"
24 #include "../fdinfo.h"
27 #define FANOTIFY_DEFAULT_MAX_EVENTS 16384
28 #define FANOTIFY_DEFAULT_MAX_MARKS 8192
29 #define FANOTIFY_DEFAULT_MAX_LISTENERS 128
32 * All flags that may be specified in parameter event_f_flags of fanotify_init.
34 * Internal and external open flags are stored together in field f_flags of
35 * struct file. Only external open flags shall be allowed in event_f_flags.
36 * Internal flags like FMODE_NONOTIFY, FMODE_EXEC, FMODE_NOCMTIME shall be
39 #define FANOTIFY_INIT_ALL_EVENT_F_BITS ( \
40 O_ACCMODE | O_APPEND | O_NONBLOCK | \
41 __O_SYNC | O_DSYNC | O_CLOEXEC | \
42 O_LARGEFILE | O_NOATIME )
44 extern const struct fsnotify_ops fanotify_fsnotify_ops;
46 struct kmem_cache *fanotify_mark_cache __read_mostly;
47 struct kmem_cache *fanotify_event_cachep __read_mostly;
48 struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
51 * Get an fsnotify notification event if one exists and is small
52 * enough to fit in "count". Return an error pointer if the count
53 * is not large enough.
55 * Called with the group->notification_lock held.
57 static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
60 assert_spin_locked(&group->notification_lock);
62 pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
64 if (fsnotify_notify_queue_is_empty(group))
67 if (FAN_EVENT_METADATA_LEN > count)
68 return ERR_PTR(-EINVAL);
70 /* held the notification_lock the whole time, so this is the
71 * same event we peeked above */
72 return fsnotify_remove_first_event(group);
75 static int create_fd(struct fsnotify_group *group,
76 struct fanotify_event_info *event,
80 struct file *new_file;
82 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
84 client_fd = get_unused_fd_flags(group->fanotify_data.f_flags);
89 * we need a new file handle for the userspace program so it can read even if it was
90 * originally opened O_WRONLY.
92 /* it's possible this event was an overflow event. in that case dentry and mnt
93 * are NULL; That's fine, just don't call dentry open */
94 if (event->path.dentry && event->path.mnt)
95 new_file = dentry_open(&event->path,
96 group->fanotify_data.f_flags | FMODE_NONOTIFY,
99 new_file = ERR_PTR(-EOVERFLOW);
100 if (IS_ERR(new_file)) {
102 * we still send an event even if we can't open the file. this
103 * can happen when say tasks are gone and we try to open their
104 * /proc files or we try to open a WRONLY file like in sysfs
105 * we just send the errno to userspace since there isn't much
108 put_unused_fd(client_fd);
109 client_fd = PTR_ERR(new_file);
117 static int fill_event_metadata(struct fsnotify_group *group,
118 struct fanotify_event_metadata *metadata,
119 struct fsnotify_event *fsn_event,
123 struct fanotify_event_info *event;
125 pr_debug("%s: group=%p metadata=%p event=%p\n", __func__,
126 group, metadata, fsn_event);
129 event = container_of(fsn_event, struct fanotify_event_info, fse);
130 metadata->event_len = FAN_EVENT_METADATA_LEN;
131 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
132 metadata->vers = FANOTIFY_METADATA_VERSION;
133 metadata->reserved = 0;
134 metadata->mask = fsn_event->mask & FANOTIFY_OUTGOING_EVENTS;
135 metadata->pid = pid_vnr(event->tgid);
136 if (unlikely(fsn_event->mask & FAN_Q_OVERFLOW))
137 metadata->fd = FAN_NOFD;
139 metadata->fd = create_fd(group, event, file);
140 if (metadata->fd < 0)
147 static struct fanotify_perm_event_info *dequeue_event(
148 struct fsnotify_group *group, int fd)
150 struct fanotify_perm_event_info *event, *return_e = NULL;
152 spin_lock(&group->notification_lock);
153 list_for_each_entry(event, &group->fanotify_data.access_list,
158 list_del_init(&event->fae.fse.list);
162 spin_unlock(&group->notification_lock);
164 pr_debug("%s: found return_re=%p\n", __func__, return_e);
169 static int process_access_response(struct fsnotify_group *group,
170 struct fanotify_response *response_struct)
172 struct fanotify_perm_event_info *event;
173 int fd = response_struct->fd;
174 int response = response_struct->response;
176 pr_debug("%s: group=%p fd=%d response=%d\n", __func__, group,
179 * make sure the response is valid, if invalid we do nothing and either
180 * userspace can send a valid response or we will clean it up after the
183 switch (response & ~FAN_AUDIT) {
194 if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT))
197 event = dequeue_event(group, fd);
201 event->response = response;
202 wake_up(&group->fanotify_data.access_waitq);
207 static ssize_t copy_event_to_user(struct fsnotify_group *group,
208 struct fsnotify_event *event,
211 struct fanotify_event_metadata fanotify_event_metadata;
215 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
217 ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
221 fd = fanotify_event_metadata.fd;
223 if (copy_to_user(buf, &fanotify_event_metadata,
224 fanotify_event_metadata.event_len))
227 if (fanotify_is_perm_event(event->mask))
228 FANOTIFY_PE(event)->fd = fd;
232 return fanotify_event_metadata.event_len;
235 if (fd != FAN_NOFD) {
242 /* intofiy userspace file descriptor functions */
243 static __poll_t fanotify_poll(struct file *file, poll_table *wait)
245 struct fsnotify_group *group = file->private_data;
248 poll_wait(file, &group->notification_waitq, wait);
249 spin_lock(&group->notification_lock);
250 if (!fsnotify_notify_queue_is_empty(group))
251 ret = EPOLLIN | EPOLLRDNORM;
252 spin_unlock(&group->notification_lock);
257 static ssize_t fanotify_read(struct file *file, char __user *buf,
258 size_t count, loff_t *pos)
260 struct fsnotify_group *group;
261 struct fsnotify_event *kevent;
264 DEFINE_WAIT_FUNC(wait, woken_wake_function);
267 group = file->private_data;
269 pr_debug("%s: group=%p\n", __func__, group);
271 add_wait_queue(&group->notification_waitq, &wait);
273 spin_lock(&group->notification_lock);
274 kevent = get_one_event(group, count);
275 spin_unlock(&group->notification_lock);
277 if (IS_ERR(kevent)) {
278 ret = PTR_ERR(kevent);
284 if (file->f_flags & O_NONBLOCK)
288 if (signal_pending(current))
294 wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
298 ret = copy_event_to_user(group, kevent, buf);
299 if (unlikely(ret == -EOPENSTALE)) {
301 * We cannot report events with stale fd so drop it.
302 * Setting ret to 0 will continue the event loop and
303 * do the right thing if there are no more events to
304 * read (i.e. return bytes read, -EAGAIN or wait).
310 * Permission events get queued to wait for response. Other
311 * events can be destroyed now.
313 if (!fanotify_is_perm_event(kevent->mask)) {
314 fsnotify_destroy_event(group, kevent);
317 FANOTIFY_PE(kevent)->response = FAN_DENY;
318 wake_up(&group->fanotify_data.access_waitq);
320 spin_lock(&group->notification_lock);
321 list_add_tail(&kevent->list,
322 &group->fanotify_data.access_list);
323 spin_unlock(&group->notification_lock);
331 remove_wait_queue(&group->notification_waitq, &wait);
333 if (start != buf && ret != -EFAULT)
338 static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
340 struct fanotify_response response = { .fd = -1, .response = -1 };
341 struct fsnotify_group *group;
344 if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
347 group = file->private_data;
349 if (count > sizeof(response))
350 count = sizeof(response);
352 pr_debug("%s: group=%p count=%zu\n", __func__, group, count);
354 if (copy_from_user(&response, buf, count))
357 ret = process_access_response(group, &response);
364 static int fanotify_release(struct inode *ignored, struct file *file)
366 struct fsnotify_group *group = file->private_data;
367 struct fanotify_perm_event_info *event, *next;
368 struct fsnotify_event *fsn_event;
371 * Stop new events from arriving in the notification queue. since
372 * userspace cannot use fanotify fd anymore, no event can enter or
373 * leave access_list by now either.
375 fsnotify_group_stop_queueing(group);
378 * Process all permission events on access_list and notification queue
379 * and simulate reply from userspace.
381 spin_lock(&group->notification_lock);
382 list_for_each_entry_safe(event, next, &group->fanotify_data.access_list,
384 pr_debug("%s: found group=%p event=%p\n", __func__, group,
387 list_del_init(&event->fae.fse.list);
388 event->response = FAN_ALLOW;
392 * Destroy all non-permission events. For permission events just
393 * dequeue them and set the response. They will be freed once the
394 * response is consumed and fanotify_get_response() returns.
396 while (!fsnotify_notify_queue_is_empty(group)) {
397 fsn_event = fsnotify_remove_first_event(group);
398 if (!(fsn_event->mask & FANOTIFY_PERM_EVENTS)) {
399 spin_unlock(&group->notification_lock);
400 fsnotify_destroy_event(group, fsn_event);
401 spin_lock(&group->notification_lock);
403 FANOTIFY_PE(fsn_event)->response = FAN_ALLOW;
406 spin_unlock(&group->notification_lock);
408 /* Response for all permission events it set, wakeup waiters */
409 wake_up(&group->fanotify_data.access_waitq);
411 /* matches the fanotify_init->fsnotify_alloc_group */
412 fsnotify_destroy_group(group);
417 static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
419 struct fsnotify_group *group;
420 struct fsnotify_event *fsn_event;
425 group = file->private_data;
427 p = (void __user *) arg;
431 spin_lock(&group->notification_lock);
432 list_for_each_entry(fsn_event, &group->notification_list, list)
433 send_len += FAN_EVENT_METADATA_LEN;
434 spin_unlock(&group->notification_lock);
435 ret = put_user(send_len, (int __user *) p);
442 static const struct file_operations fanotify_fops = {
443 .show_fdinfo = fanotify_show_fdinfo,
444 .poll = fanotify_poll,
445 .read = fanotify_read,
446 .write = fanotify_write,
448 .release = fanotify_release,
449 .unlocked_ioctl = fanotify_ioctl,
450 .compat_ioctl = fanotify_ioctl,
451 .llseek = noop_llseek,
454 static int fanotify_find_path(int dfd, const char __user *filename,
455 struct path *path, unsigned int flags)
459 pr_debug("%s: dfd=%d filename=%p flags=%x\n", __func__,
460 dfd, filename, flags);
462 if (filename == NULL) {
463 struct fd f = fdget(dfd);
470 if ((flags & FAN_MARK_ONLYDIR) &&
471 !(S_ISDIR(file_inode(f.file)->i_mode))) {
476 *path = f.file->f_path;
480 unsigned int lookup_flags = 0;
482 if (!(flags & FAN_MARK_DONT_FOLLOW))
483 lookup_flags |= LOOKUP_FOLLOW;
484 if (flags & FAN_MARK_ONLYDIR)
485 lookup_flags |= LOOKUP_DIRECTORY;
487 ret = user_path_at(dfd, filename, lookup_flags, path);
492 /* you can only watch an inode if you have read permissions on it */
493 ret = inode_permission(path->dentry->d_inode, MAY_READ);
500 static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark,
507 spin_lock(&fsn_mark->lock);
508 if (!(flags & FAN_MARK_IGNORED_MASK)) {
509 oldmask = fsn_mark->mask;
510 fsn_mark->mask &= ~mask;
512 fsn_mark->ignored_mask &= ~mask;
514 *destroy = !(fsn_mark->mask | fsn_mark->ignored_mask);
515 spin_unlock(&fsn_mark->lock);
517 return mask & oldmask;
520 static int fanotify_remove_mark(struct fsnotify_group *group,
521 fsnotify_connp_t *connp, __u32 mask,
524 struct fsnotify_mark *fsn_mark = NULL;
528 mutex_lock(&group->mark_mutex);
529 fsn_mark = fsnotify_find_mark(connp, group);
531 mutex_unlock(&group->mark_mutex);
535 removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
537 if (removed & fsnotify_conn_mask(fsn_mark->connector))
538 fsnotify_recalc_mask(fsn_mark->connector);
540 fsnotify_detach_mark(fsn_mark);
541 mutex_unlock(&group->mark_mutex);
543 fsnotify_free_mark(fsn_mark);
545 /* matches the fsnotify_find_mark() */
546 fsnotify_put_mark(fsn_mark);
550 static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
551 struct vfsmount *mnt, __u32 mask,
554 return fanotify_remove_mark(group, &real_mount(mnt)->mnt_fsnotify_marks,
558 static int fanotify_remove_sb_mark(struct fsnotify_group *group,
559 struct super_block *sb, __u32 mask,
562 return fanotify_remove_mark(group, &sb->s_fsnotify_marks, mask, flags);
565 static int fanotify_remove_inode_mark(struct fsnotify_group *group,
566 struct inode *inode, __u32 mask,
569 return fanotify_remove_mark(group, &inode->i_fsnotify_marks, mask,
573 static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
579 spin_lock(&fsn_mark->lock);
580 if (!(flags & FAN_MARK_IGNORED_MASK)) {
581 oldmask = fsn_mark->mask;
582 fsn_mark->mask |= mask;
584 fsn_mark->ignored_mask |= mask;
585 if (flags & FAN_MARK_IGNORED_SURV_MODIFY)
586 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY;
588 spin_unlock(&fsn_mark->lock);
590 return mask & ~oldmask;
593 static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
594 fsnotify_connp_t *connp,
597 struct fsnotify_mark *mark;
600 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
601 return ERR_PTR(-ENOSPC);
603 mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
605 return ERR_PTR(-ENOMEM);
607 fsnotify_init_mark(mark, group);
608 ret = fsnotify_add_mark_locked(mark, connp, type, 0);
610 fsnotify_put_mark(mark);
618 static int fanotify_add_mark(struct fsnotify_group *group,
619 fsnotify_connp_t *connp, unsigned int type,
620 __u32 mask, unsigned int flags)
622 struct fsnotify_mark *fsn_mark;
625 mutex_lock(&group->mark_mutex);
626 fsn_mark = fsnotify_find_mark(connp, group);
628 fsn_mark = fanotify_add_new_mark(group, connp, type);
629 if (IS_ERR(fsn_mark)) {
630 mutex_unlock(&group->mark_mutex);
631 return PTR_ERR(fsn_mark);
634 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
635 if (added & ~fsnotify_conn_mask(fsn_mark->connector))
636 fsnotify_recalc_mask(fsn_mark->connector);
637 mutex_unlock(&group->mark_mutex);
639 fsnotify_put_mark(fsn_mark);
643 static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
644 struct vfsmount *mnt, __u32 mask,
647 return fanotify_add_mark(group, &real_mount(mnt)->mnt_fsnotify_marks,
648 FSNOTIFY_OBJ_TYPE_VFSMOUNT, mask, flags);
651 static int fanotify_add_sb_mark(struct fsnotify_group *group,
652 struct super_block *sb, __u32 mask,
655 return fanotify_add_mark(group, &sb->s_fsnotify_marks,
656 FSNOTIFY_OBJ_TYPE_SB, mask, flags);
659 static int fanotify_add_inode_mark(struct fsnotify_group *group,
660 struct inode *inode, __u32 mask,
663 pr_debug("%s: group=%p inode=%p\n", __func__, group, inode);
666 * If some other task has this inode open for write we should not add
667 * an ignored mark, unless that ignored mark is supposed to survive
668 * modification changes anyway.
670 if ((flags & FAN_MARK_IGNORED_MASK) &&
671 !(flags & FAN_MARK_IGNORED_SURV_MODIFY) &&
672 (atomic_read(&inode->i_writecount) > 0))
675 return fanotify_add_mark(group, &inode->i_fsnotify_marks,
676 FSNOTIFY_OBJ_TYPE_INODE, mask, flags);
679 /* fanotify syscalls */
680 SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
682 struct fsnotify_group *group;
684 struct user_struct *user;
685 struct fanotify_event_info *oevent;
687 pr_debug("%s: flags=%x event_f_flags=%x\n",
688 __func__, flags, event_f_flags);
690 if (!capable(CAP_SYS_ADMIN))
693 #ifdef CONFIG_AUDITSYSCALL
694 if (flags & ~(FANOTIFY_INIT_FLAGS | FAN_ENABLE_AUDIT))
696 if (flags & ~FANOTIFY_INIT_FLAGS)
700 if (event_f_flags & ~FANOTIFY_INIT_ALL_EVENT_F_BITS)
703 switch (event_f_flags & O_ACCMODE) {
712 user = get_current_user();
713 if (atomic_read(&user->fanotify_listeners) > FANOTIFY_DEFAULT_MAX_LISTENERS) {
718 f_flags = O_RDWR | FMODE_NONOTIFY;
719 if (flags & FAN_CLOEXEC)
720 f_flags |= O_CLOEXEC;
721 if (flags & FAN_NONBLOCK)
722 f_flags |= O_NONBLOCK;
724 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
725 group = fsnotify_alloc_group(&fanotify_fsnotify_ops);
728 return PTR_ERR(group);
731 group->fanotify_data.user = user;
732 group->fanotify_data.flags = flags;
733 atomic_inc(&user->fanotify_listeners);
734 group->memcg = get_mem_cgroup_from_mm(current->mm);
736 oevent = fanotify_alloc_event(group, NULL, FS_Q_OVERFLOW, NULL);
737 if (unlikely(!oevent)) {
739 goto out_destroy_group;
741 group->overflow_event = &oevent->fse;
743 if (force_o_largefile())
744 event_f_flags |= O_LARGEFILE;
745 group->fanotify_data.f_flags = event_f_flags;
746 init_waitqueue_head(&group->fanotify_data.access_waitq);
747 INIT_LIST_HEAD(&group->fanotify_data.access_list);
748 switch (flags & FANOTIFY_CLASS_BITS) {
749 case FAN_CLASS_NOTIF:
750 group->priority = FS_PRIO_0;
752 case FAN_CLASS_CONTENT:
753 group->priority = FS_PRIO_1;
755 case FAN_CLASS_PRE_CONTENT:
756 group->priority = FS_PRIO_2;
760 goto out_destroy_group;
763 if (flags & FAN_UNLIMITED_QUEUE) {
765 if (!capable(CAP_SYS_ADMIN))
766 goto out_destroy_group;
767 group->max_events = UINT_MAX;
769 group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS;
772 if (flags & FAN_UNLIMITED_MARKS) {
774 if (!capable(CAP_SYS_ADMIN))
775 goto out_destroy_group;
776 group->fanotify_data.max_marks = UINT_MAX;
778 group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS;
781 if (flags & FAN_ENABLE_AUDIT) {
783 if (!capable(CAP_AUDIT_WRITE))
784 goto out_destroy_group;
787 fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
789 goto out_destroy_group;
794 fsnotify_destroy_group(group);
798 static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
799 int dfd, const char __user *pathname)
801 struct inode *inode = NULL;
802 struct vfsmount *mnt = NULL;
803 struct fsnotify_group *group;
806 u32 valid_mask = FANOTIFY_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR;
807 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS;
810 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
811 __func__, fanotify_fd, flags, dfd, pathname, mask);
813 /* we only use the lower 32 bits as of right now. */
814 if (mask & ((__u64)0xffffffff << 32))
817 if (flags & ~FANOTIFY_MARK_FLAGS)
823 case FAN_MARK_FILESYSTEM:
829 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) {
830 case FAN_MARK_ADD: /* fallthrough */
831 case FAN_MARK_REMOVE:
836 if (flags & ~(FANOTIFY_MARK_TYPE_BITS | FAN_MARK_FLUSH))
843 if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
844 valid_mask |= FANOTIFY_PERM_EVENTS;
846 if (mask & ~valid_mask)
849 f = fdget(fanotify_fd);
850 if (unlikely(!f.file))
853 /* verify that this is indeed an fanotify instance */
855 if (unlikely(f.file->f_op != &fanotify_fops))
857 group = f.file->private_data;
860 * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not
861 * allowed to set permissions events.
864 if (mask & FANOTIFY_PERM_EVENTS &&
865 group->priority == FS_PRIO_0)
868 if (flags & FAN_MARK_FLUSH) {
870 if (mark_type == FAN_MARK_MOUNT)
871 fsnotify_clear_vfsmount_marks_by_group(group);
872 else if (mark_type == FAN_MARK_FILESYSTEM)
873 fsnotify_clear_sb_marks_by_group(group);
875 fsnotify_clear_inode_marks_by_group(group);
879 ret = fanotify_find_path(dfd, pathname, &path, flags);
883 /* inode held in place by reference to path; group by fget on fd */
884 if (mark_type == FAN_MARK_INODE)
885 inode = path.dentry->d_inode;
889 /* create/update an inode mark */
890 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) {
892 if (mark_type == FAN_MARK_MOUNT)
893 ret = fanotify_add_vfsmount_mark(group, mnt, mask, flags);
894 else if (mark_type == FAN_MARK_FILESYSTEM)
895 ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask, flags);
897 ret = fanotify_add_inode_mark(group, inode, mask, flags);
899 case FAN_MARK_REMOVE:
900 if (mark_type == FAN_MARK_MOUNT)
901 ret = fanotify_remove_vfsmount_mark(group, mnt, mask, flags);
902 else if (mark_type == FAN_MARK_FILESYSTEM)
903 ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask, flags);
905 ret = fanotify_remove_inode_mark(group, inode, mask, flags);
917 SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
918 __u64, mask, int, dfd,
919 const char __user *, pathname)
921 return do_fanotify_mark(fanotify_fd, flags, mask, dfd, pathname);
925 COMPAT_SYSCALL_DEFINE6(fanotify_mark,
926 int, fanotify_fd, unsigned int, flags,
927 __u32, mask0, __u32, mask1, int, dfd,
928 const char __user *, pathname)
930 return do_fanotify_mark(fanotify_fd, flags,
932 ((__u64)mask0 << 32) | mask1,
934 ((__u64)mask1 << 32) | mask0,
941 * fanotify_user_setup - Our initialization function. Note that we cannot return
942 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
943 * must result in panic().
945 static int __init fanotify_user_setup(void)
947 fanotify_mark_cache = KMEM_CACHE(fsnotify_mark,
948 SLAB_PANIC|SLAB_ACCOUNT);
949 fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC);
950 if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
951 fanotify_perm_event_cachep =
952 KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC);
957 device_initcall(fanotify_user_setup);