Lines Matching +full:flags +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0
101 * All flags that may be specified in parameter event_f_flags of fanotify_init.
103 * Internal and external open flags are stored together in field f_flags of
104 * struct file. Only external open flags shall be allowed in event_f_flags.
105 * Internal flags like FMODE_NONOTIFY, FMODE_EXEC, FMODE_NOCMTIME shall be
149 info->name_len); in fanotify_dir_name_info_len()
152 info->name2_len); in fanotify_dir_name_info_len()
167 if (fanotify_is_error_event(event->mask)) in fanotify_event_len()
173 (event->mask & FAN_ONDIR)) { in fanotify_event_len()
198 assert_spin_locked(&group->notification_lock); in fanotify_unhash_event()
203 if (WARN_ON_ONCE(hlist_unhashed(&event->merge_list))) in fanotify_unhash_event()
206 hlist_del_init(&event->merge_list); in fanotify_unhash_event()
225 spin_lock(&group->notification_lock); in get_one_event()
234 event = ERR_PTR(-EINVAL); in get_one_event()
243 if (fanotify_is_perm_event(event->mask)) in get_one_event()
244 FANOTIFY_PERM(event)->state = FAN_EVENT_REPORTED; in get_one_event()
245 if (fanotify_is_hashed_event(event->mask)) in get_one_event()
248 spin_unlock(&group->notification_lock); in get_one_event()
258 client_fd = get_unused_fd_flags(group->fanotify_data.f_flags); in create_fd()
267 group->fanotify_data.f_flags | __FMODE_NONOTIFY, in create_fd()
291 return -EINVAL; in process_access_response_info()
294 return -EFAULT; in process_access_response_info()
296 if (friar->hdr.type != FAN_RESPONSE_INFO_AUDIT_RULE) in process_access_response_info()
297 return -EINVAL; in process_access_response_info()
298 if (friar->hdr.pad != 0) in process_access_response_info()
299 return -EINVAL; in process_access_response_info()
300 if (friar->hdr.len != sizeof(*friar)) in process_access_response_info()
301 return -EINVAL; in process_access_response_info()
308 * drop group->notification_lock.
313 __releases(&group->notification_lock) in finish_permission_event()
317 assert_spin_locked(&group->notification_lock); in finish_permission_event()
318 event->response = response & ~FAN_INFO; in finish_permission_event()
320 memcpy(&event->audit_rule, friar, sizeof(*friar)); in finish_permission_event()
322 if (event->state == FAN_EVENT_CANCELED) in finish_permission_event()
325 event->state = FAN_EVENT_ANSWERED; in finish_permission_event()
326 spin_unlock(&group->notification_lock); in finish_permission_event()
328 fsnotify_destroy_event(group, &event->fae.fse); in finish_permission_event()
337 int fd = response_struct->fd; in process_access_response()
338 u32 response = response_struct->response; in process_access_response()
350 return -EINVAL; in process_access_response()
357 return -EINVAL; in process_access_response()
361 return -EINVAL; in process_access_response()
374 return -EINVAL; in process_access_response()
376 spin_lock(&group->notification_lock); in process_access_response()
377 list_for_each_entry(event, &group->fanotify_data.access_list, in process_access_response()
379 if (event->fd != fd) in process_access_response()
382 list_del_init(&event->fae.fse.list); in process_access_response()
384 wake_up(&group->fanotify_data.access_waitq); in process_access_response()
387 spin_unlock(&group->notification_lock); in process_access_response()
389 return -ENOENT; in process_access_response()
402 return -EFAULT; in copy_error_info_to_user()
404 info.error = fee->error; in copy_error_info_to_user()
405 info.error_count = fee->err_count; in copy_error_info_to_user()
408 return -EFAULT; in copy_error_info_to_user()
421 size_t fh_len = fh ? fh->len : 0; in copy_fid_info_to_user()
429 return -EFAULT; in copy_fid_info_to_user()
439 return -EFAULT; in copy_fid_info_to_user()
445 return -EFAULT; in copy_fid_info_to_user()
448 return -EFAULT; in copy_fid_info_to_user()
455 return -EFAULT; in copy_fid_info_to_user()
458 len -= sizeof(info); in copy_fid_info_to_user()
460 return -EFAULT; in copy_fid_info_to_user()
462 handle.handle_type = fh->type; in copy_fid_info_to_user()
470 return -EFAULT; in copy_fid_info_to_user()
473 len -= sizeof(handle); in copy_fid_info_to_user()
475 return -EFAULT; in copy_fid_info_to_user()
487 return -EFAULT; in copy_fid_info_to_user()
490 len -= fh_len; in copy_fid_info_to_user()
496 return -EFAULT; in copy_fid_info_to_user()
499 return -EFAULT; in copy_fid_info_to_user()
502 len -= name_len; in copy_fid_info_to_user()
508 return -EFAULT; in copy_fid_info_to_user()
521 return -EFAULT; in copy_pidfd_info_to_user()
528 return -EFAULT; in copy_pidfd_info_to_user()
549 info_type = info->name_len ? FAN_EVENT_INFO_TYPE_DFID_NAME : in copy_info_records_to_user()
553 if (event->mask & FAN_RENAME) in copy_info_records_to_user()
560 info->name_len, buf, count); in copy_info_records_to_user()
565 count -= ret; in copy_info_records_to_user()
576 info->name2_len, buf, count); in copy_info_records_to_user()
581 count -= ret; in copy_info_records_to_user()
596 (event->mask & FAN_ONDIR)) { in copy_info_records_to_user()
605 } else if ((event->mask & ALL_FSNOTIFY_DIRENT_EVENTS) || in copy_info_records_to_user()
606 (event->mask & FAN_ONDIR)) { in copy_info_records_to_user()
615 * With group flags FAN_REPORT_DIR_FID|FAN_REPORT_FID, in copy_info_records_to_user()
617 * non-directory, when there is no directory to report. in copy_info_records_to_user()
631 count -= ret; in copy_info_records_to_user()
641 count -= ret; in copy_info_records_to_user()
645 if (fanotify_is_error_event(event->mask)) { in copy_info_records_to_user()
650 count -= ret; in copy_info_records_to_user()
675 metadata.mask = event->mask & FANOTIFY_OUTGOING_EVENTS; in copy_event_to_user()
676 metadata.pid = pid_vnr(event->pid); in copy_event_to_user()
678 * For an unprivileged listener, event->pid can be used to identify the in copy_event_to_user()
683 task_tgid(current) != event->pid) in copy_event_to_user()
693 path && path->mnt && path->dentry) { in copy_event_to_user()
705 * creation of pidfds for thread-group leaders. in copy_event_to_user()
710 * The PIDTYPE_TGID check for an event->pid is performed in copy_event_to_user()
718 !pid_has_task(event->pid, PIDTYPE_TGID)) { in copy_event_to_user()
721 pidfd = pidfd_prepare(event->pid, 0, &pidfd_file); in copy_event_to_user()
727 ret = -EFAULT; in copy_event_to_user()
739 count -= FAN_EVENT_METADATA_LEN; in copy_event_to_user()
741 if (fanotify_is_perm_event(event->mask)) in copy_event_to_user()
742 FANOTIFY_PERM(event)->fd = fd; in copy_event_to_user()
776 struct fsnotify_group *group = file->private_data; in fanotify_poll()
779 poll_wait(file, &group->notification_waitq, wait); in fanotify_poll()
780 spin_lock(&group->notification_lock); in fanotify_poll()
783 spin_unlock(&group->notification_lock); in fanotify_poll()
798 group = file->private_data; in fanotify_read()
802 add_wait_queue(&group->notification_waitq, &wait); in fanotify_read()
816 ret = -EAGAIN; in fanotify_read()
817 if (file->f_flags & O_NONBLOCK) in fanotify_read()
820 ret = -ERESTARTSYS; in fanotify_read()
832 if (unlikely(ret == -EOPENSTALE)) { in fanotify_read()
837 * read (i.e. return bytes read, -EAGAIN or wait). in fanotify_read()
846 if (!fanotify_is_perm_event(event->mask)) { in fanotify_read()
847 fsnotify_destroy_event(group, &event->fse); in fanotify_read()
850 spin_lock(&group->notification_lock); in fanotify_read()
853 wake_up(&group->fanotify_data.access_waitq); in fanotify_read()
855 spin_lock(&group->notification_lock); in fanotify_read()
856 list_add_tail(&event->fse.list, in fanotify_read()
857 &group->fanotify_data.access_list); in fanotify_read()
858 spin_unlock(&group->notification_lock); in fanotify_read()
864 count -= ret; in fanotify_read()
866 remove_wait_queue(&group->notification_waitq, &wait); in fanotify_read()
868 if (start != buf && ret != -EFAULT) in fanotify_read()
869 ret = buf - start; in fanotify_read()
882 return -EINVAL; in fanotify_write()
884 group = file->private_data; in fanotify_write()
889 return -EINVAL; in fanotify_write()
892 return -EFAULT; in fanotify_write()
894 info_len = count - sizeof(response); in fanotify_write()
907 struct fsnotify_group *group = file->private_data; in fanotify_release()
921 spin_lock(&group->notification_lock); in fanotify_release()
922 while (!list_empty(&group->fanotify_data.access_list)) { in fanotify_release()
925 event = list_first_entry(&group->fanotify_data.access_list, in fanotify_release()
927 list_del_init(&event->fae.fse.list); in fanotify_release()
929 spin_lock(&group->notification_lock); in fanotify_release()
933 * Destroy all non-permission events. For permission events just in fanotify_release()
940 if (!(event->mask & FANOTIFY_PERM_EVENTS)) { in fanotify_release()
941 spin_unlock(&group->notification_lock); in fanotify_release()
947 spin_lock(&group->notification_lock); in fanotify_release()
949 spin_unlock(&group->notification_lock); in fanotify_release()
952 wake_up(&group->fanotify_data.access_waitq); in fanotify_release()
954 /* matches the fanotify_init->fsnotify_alloc_group */ in fanotify_release()
965 int ret = -ENOTTY; in fanotify_ioctl()
968 group = file->private_data; in fanotify_ioctl()
974 spin_lock(&group->notification_lock); in fanotify_ioctl()
975 list_for_each_entry(fsn_event, &group->notification_list, list) in fanotify_ioctl()
977 spin_unlock(&group->notification_lock); in fanotify_ioctl()
998 struct path *path, unsigned int flags, __u64 mask, in fanotify_find_path() argument
1003 pr_debug("%s: dfd=%d filename=%p flags=%x\n", __func__, in fanotify_find_path()
1004 dfd, filename, flags); in fanotify_find_path()
1009 ret = -EBADF; in fanotify_find_path()
1013 ret = -ENOTDIR; in fanotify_find_path()
1014 if ((flags & FAN_MARK_ONLYDIR) && in fanotify_find_path()
1015 !(S_ISDIR(file_inode(f.file)->i_mode))) { in fanotify_find_path()
1020 *path = f.file->f_path; in fanotify_find_path()
1026 if (!(flags & FAN_MARK_DONT_FOLLOW)) in fanotify_find_path()
1028 if (flags & FAN_MARK_ONLYDIR) in fanotify_find_path()
1043 ret = security_path_notify(path, mask, obj_type); in fanotify_find_path()
1052 __u32 mask, unsigned int flags, in fanotify_mark_remove_from_mask() argument
1058 mask &= ~umask; in fanotify_mark_remove_from_mask()
1059 spin_lock(&fsn_mark->lock); in fanotify_mark_remove_from_mask()
1061 if (!(flags & FANOTIFY_MARK_IGNORE_BITS)) { in fanotify_mark_remove_from_mask()
1062 fsn_mark->mask &= ~mask; in fanotify_mark_remove_from_mask()
1064 fsn_mark->ignore_mask &= ~mask; in fanotify_mark_remove_from_mask()
1068 * We need to keep the mark around even if remaining mask cannot in fanotify_mark_remove_from_mask()
1069 * result in any events (e.g. mask == FAN_ONDIR) to support incremenal in fanotify_mark_remove_from_mask()
1070 * changes to the mask. in fanotify_mark_remove_from_mask()
1073 *destroy = !((fsn_mark->mask | fsn_mark->ignore_mask) & ~umask); in fanotify_mark_remove_from_mask()
1074 spin_unlock(&fsn_mark->lock); in fanotify_mark_remove_from_mask()
1080 fsnotify_connp_t *connp, __u32 mask, in fanotify_remove_mark() argument
1081 unsigned int flags, __u32 umask) in fanotify_remove_mark() argument
1091 return -ENOENT; in fanotify_remove_mark()
1094 removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, in fanotify_remove_mark()
1096 if (removed & fsnotify_conn_mask(fsn_mark->connector)) in fanotify_remove_mark()
1097 fsnotify_recalc_mask(fsn_mark->connector); in fanotify_remove_mark()
1110 struct vfsmount *mnt, __u32 mask, in fanotify_remove_vfsmount_mark() argument
1111 unsigned int flags, __u32 umask) in fanotify_remove_vfsmount_mark() argument
1113 return fanotify_remove_mark(group, &real_mount(mnt)->mnt_fsnotify_marks, in fanotify_remove_vfsmount_mark()
1114 mask, flags, umask); in fanotify_remove_vfsmount_mark()
1118 struct super_block *sb, __u32 mask, in fanotify_remove_sb_mark() argument
1119 unsigned int flags, __u32 umask) in fanotify_remove_sb_mark() argument
1121 return fanotify_remove_mark(group, &sb->s_fsnotify_marks, mask, in fanotify_remove_sb_mark()
1122 flags, umask); in fanotify_remove_sb_mark()
1126 struct inode *inode, __u32 mask, in fanotify_remove_inode_mark() argument
1127 unsigned int flags, __u32 umask) in fanotify_remove_inode_mark() argument
1129 return fanotify_remove_mark(group, &inode->i_fsnotify_marks, mask, in fanotify_remove_inode_mark()
1130 flags, umask); in fanotify_remove_inode_mark()
1142 * independent event flags in ignore mask. After that, trying to in fanotify_mark_update_flags()
1143 * update the ignore mask with the old FAN_MARK_IGNORED_MASK API in fanotify_mark_update_flags()
1147 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_HAS_IGNORE_FLAGS; in fanotify_mark_update_flags()
1151 * the removal of the FS_MODIFY bit in calculated mask if it was set in fanotify_mark_update_flags()
1152 * because of an ignore mask that is now going to survive FS_MODIFY. in fanotify_mark_update_flags()
1155 !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) { in fanotify_mark_update_flags()
1156 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; in fanotify_mark_update_flags()
1157 if (!(fsn_mark->mask & FS_MODIFY)) in fanotify_mark_update_flags()
1161 if (fsn_mark->connector->type != FSNOTIFY_OBJ_TYPE_INODE || in fanotify_mark_update_flags()
1162 want_iref == !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) in fanotify_mark_update_flags()
1170 fsn_mark->flags &= ~FSNOTIFY_MARK_FLAG_NO_IREF; in fanotify_mark_update_flags()
1176 __u32 mask, unsigned int fan_flags) in fanotify_mark_add_to_mask() argument
1180 spin_lock(&fsn_mark->lock); in fanotify_mark_add_to_mask()
1182 fsn_mark->mask |= mask; in fanotify_mark_add_to_mask()
1184 fsn_mark->ignore_mask |= mask; in fanotify_mark_add_to_mask()
1187 ~fsnotify_conn_mask(fsn_mark->connector); in fanotify_mark_add_to_mask()
1190 spin_unlock(&fsn_mark->lock); in fanotify_mark_add_to_mask()
1201 struct ucounts *ucounts = group->fanotify_data.ucounts; in fanotify_add_new_mark()
1211 !inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS)) in fanotify_add_new_mark()
1212 return ERR_PTR(-ENOSPC); in fanotify_add_new_mark()
1216 ret = -ENOMEM; in fanotify_add_new_mark()
1222 mark->flags |= FSNOTIFY_MARK_FLAG_NO_IREF; in fanotify_add_new_mark()
1240 if (mempool_initialized(&group->fanotify_data.error_events_pool)) in fanotify_group_init_error_pool()
1243 return mempool_init_kmalloc_pool(&group->fanotify_data.error_events_pool, in fanotify_group_init_error_pool()
1255 !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) in fanotify_may_update_existing_mark()
1256 return -EEXIST; in fanotify_may_update_existing_mark()
1259 * New ignore mask semantics cannot be downgraded to old semantics. in fanotify_may_update_existing_mark()
1262 fsn_mark->flags & FSNOTIFY_MARK_FLAG_HAS_IGNORE_FLAGS) in fanotify_may_update_existing_mark()
1263 return -EEXIST; in fanotify_may_update_existing_mark()
1266 * An ignore mask that survives modify could never be downgraded to not in fanotify_may_update_existing_mark()
1268 * explicit and return an error when trying to update the ignore mask in fanotify_may_update_existing_mark()
1273 fsn_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) in fanotify_may_update_existing_mark()
1274 return -EEXIST; in fanotify_may_update_existing_mark()
1281 __u32 mask, unsigned int fan_flags, in fanotify_add_mark() argument
1300 * Check if requested mark flags conflict with an existing mark flags. in fanotify_add_mark()
1307 * Error events are pre-allocated per group, only if strictly in fanotify_add_mark()
1311 (mask & FAN_FS_ERROR)) { in fanotify_add_mark()
1317 recalc = fanotify_mark_add_to_mask(fsn_mark, mask, fan_flags); in fanotify_add_mark()
1319 fsnotify_recalc_mask(fsn_mark->connector); in fanotify_add_mark()
1329 struct vfsmount *mnt, __u32 mask, in fanotify_add_vfsmount_mark() argument
1330 unsigned int flags, __kernel_fsid_t *fsid) in fanotify_add_vfsmount_mark() argument
1332 return fanotify_add_mark(group, &real_mount(mnt)->mnt_fsnotify_marks, in fanotify_add_vfsmount_mark()
1333 FSNOTIFY_OBJ_TYPE_VFSMOUNT, mask, flags, fsid); in fanotify_add_vfsmount_mark()
1337 struct super_block *sb, __u32 mask, in fanotify_add_sb_mark() argument
1338 unsigned int flags, __kernel_fsid_t *fsid) in fanotify_add_sb_mark() argument
1340 return fanotify_add_mark(group, &sb->s_fsnotify_marks, in fanotify_add_sb_mark()
1341 FSNOTIFY_OBJ_TYPE_SB, mask, flags, fsid); in fanotify_add_sb_mark()
1345 struct inode *inode, __u32 mask, in fanotify_add_inode_mark() argument
1346 unsigned int flags, __kernel_fsid_t *fsid) in fanotify_add_inode_mark() argument
1352 * an ignore mask, unless that ignore mask is supposed to survive in fanotify_add_inode_mark()
1355 if ((flags & FANOTIFY_MARK_IGNORE_BITS) && in fanotify_add_inode_mark()
1356 !(flags & FAN_MARK_IGNORED_SURV_MODIFY) && in fanotify_add_inode_mark()
1360 return fanotify_add_mark(group, &inode->i_fsnotify_marks, in fanotify_add_inode_mark()
1361 FSNOTIFY_OBJ_TYPE_INODE, mask, flags, fsid); in fanotify_add_inode_mark()
1373 oevent->type = FANOTIFY_EVENT_TYPE_OVERFLOW; in fanotify_alloc_overflow_event()
1375 return &oevent->fse; in fanotify_alloc_overflow_event()
1393 SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) in SYSCALL_DEFINE2() argument
1397 unsigned int fid_mode = flags & FANOTIFY_FID_BITS; in SYSCALL_DEFINE2()
1398 unsigned int class = flags & FANOTIFY_CLASS_BITS; in SYSCALL_DEFINE2()
1401 pr_debug("%s: flags=%x event_f_flags=%x\n", in SYSCALL_DEFINE2()
1402 __func__, flags, event_f_flags); in SYSCALL_DEFINE2()
1407 * limited functionality - an unprivileged group is limited to in SYSCALL_DEFINE2()
1411 if ((flags & FANOTIFY_ADMIN_INIT_FLAGS) || !fid_mode) in SYSCALL_DEFINE2()
1412 return -EPERM; in SYSCALL_DEFINE2()
1423 if (flags & ~(FANOTIFY_INIT_FLAGS | FAN_ENABLE_AUDIT)) in SYSCALL_DEFINE2()
1425 if (flags & ~FANOTIFY_INIT_FLAGS) in SYSCALL_DEFINE2()
1427 return -EINVAL; in SYSCALL_DEFINE2()
1430 * A pidfd can only be returned for a thread-group leader; thus in SYSCALL_DEFINE2()
1434 if ((flags & FAN_REPORT_PIDFD) && (flags & FAN_REPORT_TID)) in SYSCALL_DEFINE2()
1435 return -EINVAL; in SYSCALL_DEFINE2()
1438 return -EINVAL; in SYSCALL_DEFINE2()
1446 return -EINVAL; in SYSCALL_DEFINE2()
1450 return -EINVAL; in SYSCALL_DEFINE2()
1457 return -EINVAL; in SYSCALL_DEFINE2()
1466 return -EINVAL; in SYSCALL_DEFINE2()
1469 if (flags & FAN_CLOEXEC) in SYSCALL_DEFINE2()
1471 if (flags & FAN_NONBLOCK) in SYSCALL_DEFINE2()
1482 group->fanotify_data.ucounts = inc_ucount(current_user_ns(), in SYSCALL_DEFINE2()
1485 if (!group->fanotify_data.ucounts) { in SYSCALL_DEFINE2()
1486 fd = -EMFILE; in SYSCALL_DEFINE2()
1490 group->fanotify_data.flags = flags | internal_flags; in SYSCALL_DEFINE2()
1491 group->memcg = get_mem_cgroup_from_mm(current->mm); in SYSCALL_DEFINE2()
1493 group->fanotify_data.merge_hash = fanotify_alloc_merge_hash(); in SYSCALL_DEFINE2()
1494 if (!group->fanotify_data.merge_hash) { in SYSCALL_DEFINE2()
1495 fd = -ENOMEM; in SYSCALL_DEFINE2()
1499 group->overflow_event = fanotify_alloc_overflow_event(); in SYSCALL_DEFINE2()
1500 if (unlikely(!group->overflow_event)) { in SYSCALL_DEFINE2()
1501 fd = -ENOMEM; in SYSCALL_DEFINE2()
1507 group->fanotify_data.f_flags = event_f_flags; in SYSCALL_DEFINE2()
1508 init_waitqueue_head(&group->fanotify_data.access_waitq); in SYSCALL_DEFINE2()
1509 INIT_LIST_HEAD(&group->fanotify_data.access_list); in SYSCALL_DEFINE2()
1512 group->priority = FS_PRIO_0; in SYSCALL_DEFINE2()
1515 group->priority = FS_PRIO_1; in SYSCALL_DEFINE2()
1518 group->priority = FS_PRIO_2; in SYSCALL_DEFINE2()
1521 fd = -EINVAL; in SYSCALL_DEFINE2()
1525 if (flags & FAN_UNLIMITED_QUEUE) { in SYSCALL_DEFINE2()
1526 fd = -EPERM; in SYSCALL_DEFINE2()
1529 group->max_events = UINT_MAX; in SYSCALL_DEFINE2()
1531 group->max_events = fanotify_max_queued_events; in SYSCALL_DEFINE2()
1534 if (flags & FAN_UNLIMITED_MARKS) { in SYSCALL_DEFINE2()
1535 fd = -EPERM; in SYSCALL_DEFINE2()
1540 if (flags & FAN_ENABLE_AUDIT) { in SYSCALL_DEFINE2()
1541 fd = -EPERM; in SYSCALL_DEFINE2()
1569 if (!fsid->val[0] && !fsid->val[1]) in fanotify_test_fsid()
1570 return -ENODEV; in fanotify_test_fsid()
1576 err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid); in fanotify_test_fsid()
1580 if (root_fsid.val[0] != fsid->val[0] || in fanotify_test_fsid()
1581 root_fsid.val[1] != fsid->val[1]) in fanotify_test_fsid()
1582 return -EXDEV; in fanotify_test_fsid()
1588 static int fanotify_test_fid(struct dentry *dentry, unsigned int flags) in fanotify_test_fid() argument
1590 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in fanotify_test_fid()
1591 const struct export_operations *nop = dentry->d_sb->s_export_op; in fanotify_test_fid()
1599 return -EOPNOTSUPP; in fanotify_test_fid()
1606 if (mark_type != FAN_MARK_INODE && !nop->fh_to_dentry) in fanotify_test_fid()
1607 return -EOPNOTSUPP; in fanotify_test_fid()
1613 const struct path *path, __u64 mask, in fanotify_events_supported() argument
1614 unsigned int flags) in fanotify_events_supported() argument
1616 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in fanotify_events_supported()
1617 /* Strict validation of events in non-dir inode mask with v5.17+ APIs */ in fanotify_events_supported()
1619 (mask & FAN_RENAME) || in fanotify_events_supported()
1620 (flags & FAN_MARK_IGNORE); in fanotify_events_supported()
1625 * deadlocking the system - open done when reporting fanotify event in fanotify_events_supported()
1630 if (mask & FANOTIFY_PERM_EVENTS && in fanotify_events_supported()
1631 path->mnt->mnt_sb->s_type->fs_flags & FS_DISALLOW_NOTIFY_PERM) in fanotify_events_supported()
1632 return -EINVAL; in fanotify_events_supported()
1645 path->mnt->mnt_sb->s_flags & SB_NOUSER) in fanotify_events_supported()
1646 return -EINVAL; in fanotify_events_supported()
1650 * flags FAN_ONDIR and FAN_EVENT_ON_CHILD in mask of non-dir inode, in fanotify_events_supported()
1654 !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) in fanotify_events_supported()
1655 return -ENOTDIR; in fanotify_events_supported()
1660 static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, in do_fanotify_mark() argument
1670 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in do_fanotify_mark()
1671 unsigned int mark_cmd = flags & FANOTIFY_MARK_CMD_BITS; in do_fanotify_mark()
1672 unsigned int ignore = flags & FANOTIFY_MARK_IGNORE_BITS; in do_fanotify_mark()
1677 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", in do_fanotify_mark()
1678 __func__, fanotify_fd, flags, dfd, pathname, mask); in do_fanotify_mark()
1681 if (upper_32_bits(mask)) in do_fanotify_mark()
1682 return -EINVAL; in do_fanotify_mark()
1684 if (flags & ~FANOTIFY_MARK_FLAGS) in do_fanotify_mark()
1685 return -EINVAL; in do_fanotify_mark()
1698 return -EINVAL; in do_fanotify_mark()
1704 if (!mask) in do_fanotify_mark()
1705 return -EINVAL; in do_fanotify_mark()
1708 if (flags & ~(FANOTIFY_MARK_TYPE_BITS | FAN_MARK_FLUSH)) in do_fanotify_mark()
1709 return -EINVAL; in do_fanotify_mark()
1712 return -EINVAL; in do_fanotify_mark()
1718 if (mask & ~valid_mask) in do_fanotify_mark()
1719 return -EINVAL; in do_fanotify_mark()
1724 return -EINVAL; in do_fanotify_mark()
1727 * Event flags (FAN_ONDIR, FAN_EVENT_ON_CHILD) have no effect with in do_fanotify_mark()
1731 mask &= ~FANOTIFY_EVENT_FLAGS; in do_fanotify_mark()
1737 return -EBADF; in do_fanotify_mark()
1740 ret = -EINVAL; in do_fanotify_mark()
1741 if (unlikely(f.file->f_op != &fanotify_fops)) in do_fanotify_mark()
1743 group = f.file->private_data; in do_fanotify_mark()
1750 ret = -EPERM; in do_fanotify_mark()
1757 * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not in do_fanotify_mark()
1760 ret = -EINVAL; in do_fanotify_mark()
1761 if (mask & FANOTIFY_PERM_EVENTS && in do_fanotify_mark()
1762 group->priority == FS_PRIO_0) in do_fanotify_mark()
1765 if (mask & FAN_FS_ERROR && in do_fanotify_mark()
1773 if (flags & FAN_MARK_EVICTABLE && in do_fanotify_mark()
1779 * event->fd require a group that supports reporting fid. Those in do_fanotify_mark()
1785 if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_EVENT_FLAGS) && in do_fanotify_mark()
1794 if (mask & FAN_RENAME && !(fid_mode & FAN_REPORT_NAME)) in do_fanotify_mark()
1808 ret = fanotify_find_path(dfd, pathname, &path, flags, in do_fanotify_mark()
1809 (mask & ALL_FSNOTIFY_EVENTS), obj_type); in do_fanotify_mark()
1814 ret = fanotify_events_supported(group, &path, mask, flags); in do_fanotify_mark()
1824 ret = fanotify_test_fid(path.dentry, flags); in do_fanotify_mark()
1833 inode = path.dentry->d_inode; in do_fanotify_mark()
1837 ret = mnt ? -EINVAL : -EISDIR; in do_fanotify_mark()
1840 (mnt || S_ISDIR(inode->i_mode)) && in do_fanotify_mark()
1841 !(flags & FAN_MARK_IGNORED_SURV_MODIFY)) in do_fanotify_mark()
1844 /* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */ in do_fanotify_mark()
1845 if (mnt || !S_ISDIR(inode->i_mode)) { in do_fanotify_mark()
1846 mask &= ~FAN_EVENT_ON_CHILD; in do_fanotify_mark()
1850 * events with parent/name info for non-directory. in do_fanotify_mark()
1853 (flags & FAN_MARK_ADD) && !ignore) in do_fanotify_mark()
1854 mask |= FAN_EVENT_ON_CHILD; in do_fanotify_mark()
1861 ret = fanotify_add_vfsmount_mark(group, mnt, mask, in do_fanotify_mark()
1862 flags, fsid); in do_fanotify_mark()
1864 ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask, in do_fanotify_mark()
1865 flags, fsid); in do_fanotify_mark()
1867 ret = fanotify_add_inode_mark(group, inode, mask, in do_fanotify_mark()
1868 flags, fsid); in do_fanotify_mark()
1872 ret = fanotify_remove_vfsmount_mark(group, mnt, mask, in do_fanotify_mark()
1873 flags, umask); in do_fanotify_mark()
1875 ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask, in do_fanotify_mark()
1876 flags, umask); in do_fanotify_mark()
1878 ret = fanotify_remove_inode_mark(group, inode, mask, in do_fanotify_mark()
1879 flags, umask); in do_fanotify_mark()
1882 ret = -EINVAL; in do_fanotify_mark()
1893 SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, in SYSCALL_DEFINE5() argument
1894 __u64, mask, int, dfd, in SYSCALL_DEFINE5() argument
1897 return do_fanotify_mark(fanotify_fd, flags, mask, dfd, pathname); in SYSCALL_DEFINE5()
1903 int, fanotify_fd, unsigned int, flags, in SYSCALL32_DEFINE6() argument
1904 SC_ARG64(mask), int, dfd, in SYSCALL32_DEFINE6() argument
1907 return do_fanotify_mark(fanotify_fd, flags, SC_VAL64(__u64, mask), in SYSCALL32_DEFINE6()
1913 * fanotify_user_setup - Our initialization function. Note that we cannot return
1914 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
1929 max_marks = (((si.totalram - si.totalhigh) / 100) << PAGE_SHIFT) / in fanotify_user_setup()