Lines Matching +full:flags +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
100 * All flags that may be specified in parameter event_f_flags of fanotify_init.
102 * Internal and external open flags are stored together in field f_flags of
103 * struct file. Only external open flags shall be allowed in event_f_flags.
104 * Internal flags like FMODE_NONOTIFY, FMODE_EXEC, FMODE_NOCMTIME shall be
148 info->name_len); in fanotify_dir_name_info_len()
151 info->name2_len); in fanotify_dir_name_info_len()
166 if (fanotify_is_error_event(event->mask)) in fanotify_event_len()
172 (event->mask & FAN_ONDIR)) { in fanotify_event_len()
197 assert_spin_locked(&group->notification_lock); in fanotify_unhash_event()
202 if (WARN_ON_ONCE(hlist_unhashed(&event->merge_list))) in fanotify_unhash_event()
205 hlist_del_init(&event->merge_list); in fanotify_unhash_event()
224 spin_lock(&group->notification_lock); in get_one_event()
233 event = ERR_PTR(-EINVAL); in get_one_event()
242 if (fanotify_is_perm_event(event->mask)) in get_one_event()
243 FANOTIFY_PERM(event)->state = FAN_EVENT_REPORTED; in get_one_event()
244 if (fanotify_is_hashed_event(event->mask)) in get_one_event()
247 spin_unlock(&group->notification_lock); in get_one_event()
257 client_fd = get_unused_fd_flags(group->fanotify_data.f_flags); in create_fd()
266 group->fanotify_data.f_flags | __FMODE_NONOTIFY, in create_fd()
290 return -EINVAL; in process_access_response_info()
293 return -EFAULT; in process_access_response_info()
295 if (friar->hdr.type != FAN_RESPONSE_INFO_AUDIT_RULE) in process_access_response_info()
296 return -EINVAL; in process_access_response_info()
297 if (friar->hdr.pad != 0) in process_access_response_info()
298 return -EINVAL; in process_access_response_info()
299 if (friar->hdr.len != sizeof(*friar)) in process_access_response_info()
300 return -EINVAL; in process_access_response_info()
307 * drop group->notification_lock.
312 __releases(&group->notification_lock) in finish_permission_event()
316 assert_spin_locked(&group->notification_lock); in finish_permission_event()
317 event->response = response & ~FAN_INFO; in finish_permission_event()
319 memcpy(&event->audit_rule, friar, sizeof(*friar)); in finish_permission_event()
321 if (event->state == FAN_EVENT_CANCELED) in finish_permission_event()
324 event->state = FAN_EVENT_ANSWERED; in finish_permission_event()
325 spin_unlock(&group->notification_lock); in finish_permission_event()
327 fsnotify_destroy_event(group, &event->fae.fse); in finish_permission_event()
336 int fd = response_struct->fd; in process_access_response()
337 u32 response = response_struct->response; in process_access_response()
349 return -EINVAL; in process_access_response()
356 return -EINVAL; in process_access_response()
360 return -EINVAL; in process_access_response()
373 return -EINVAL; in process_access_response()
375 spin_lock(&group->notification_lock); in process_access_response()
376 list_for_each_entry(event, &group->fanotify_data.access_list, in process_access_response()
378 if (event->fd != fd) in process_access_response()
381 list_del_init(&event->fae.fse.list); in process_access_response()
383 wake_up(&group->fanotify_data.access_waitq); in process_access_response()
386 spin_unlock(&group->notification_lock); in process_access_response()
388 return -ENOENT; in process_access_response()
401 return -EFAULT; in copy_error_info_to_user()
403 info.error = fee->error; in copy_error_info_to_user()
404 info.error_count = fee->err_count; in copy_error_info_to_user()
407 return -EFAULT; in copy_error_info_to_user()
420 size_t fh_len = fh ? fh->len : 0; in copy_fid_info_to_user()
428 return -EFAULT; in copy_fid_info_to_user()
438 return -EFAULT; in copy_fid_info_to_user()
444 return -EFAULT; in copy_fid_info_to_user()
447 return -EFAULT; in copy_fid_info_to_user()
454 return -EFAULT; in copy_fid_info_to_user()
457 len -= sizeof(info); in copy_fid_info_to_user()
459 return -EFAULT; in copy_fid_info_to_user()
461 handle.handle_type = fh->type; in copy_fid_info_to_user()
469 return -EFAULT; in copy_fid_info_to_user()
472 len -= sizeof(handle); in copy_fid_info_to_user()
474 return -EFAULT; in copy_fid_info_to_user()
486 return -EFAULT; in copy_fid_info_to_user()
489 len -= fh_len; in copy_fid_info_to_user()
495 return -EFAULT; in copy_fid_info_to_user()
498 return -EFAULT; in copy_fid_info_to_user()
501 len -= name_len; in copy_fid_info_to_user()
507 return -EFAULT; in copy_fid_info_to_user()
520 return -EFAULT; in copy_pidfd_info_to_user()
527 return -EFAULT; in copy_pidfd_info_to_user()
548 info_type = info->name_len ? FAN_EVENT_INFO_TYPE_DFID_NAME : in copy_info_records_to_user()
552 if (event->mask & FAN_RENAME) in copy_info_records_to_user()
559 info->name_len, buf, count); in copy_info_records_to_user()
564 count -= ret; in copy_info_records_to_user()
575 info->name2_len, buf, count); in copy_info_records_to_user()
580 count -= ret; in copy_info_records_to_user()
595 (event->mask & FAN_ONDIR)) { in copy_info_records_to_user()
604 } else if ((event->mask & ALL_FSNOTIFY_DIRENT_EVENTS) || in copy_info_records_to_user()
605 (event->mask & FAN_ONDIR)) { in copy_info_records_to_user()
614 * With group flags FAN_REPORT_DIR_FID|FAN_REPORT_FID, in copy_info_records_to_user()
616 * non-directory, when there is no directory to report. in copy_info_records_to_user()
630 count -= ret; in copy_info_records_to_user()
640 count -= ret; in copy_info_records_to_user()
644 if (fanotify_is_error_event(event->mask)) { in copy_info_records_to_user()
649 count -= ret; in copy_info_records_to_user()
674 metadata.mask = event->mask & FANOTIFY_OUTGOING_EVENTS; in copy_event_to_user()
675 metadata.pid = pid_vnr(event->pid); in copy_event_to_user()
677 * For an unprivileged listener, event->pid can be used to identify the in copy_event_to_user()
682 task_tgid(current) != event->pid) in copy_event_to_user()
692 path && path->mnt && path->dentry) { in copy_event_to_user()
704 * creation of pidfds for thread-group leaders. in copy_event_to_user()
709 * The PIDTYPE_TGID check for an event->pid is performed in copy_event_to_user()
717 !pid_has_task(event->pid, PIDTYPE_TGID)) { in copy_event_to_user()
720 pidfd = pidfd_prepare(event->pid, 0, &pidfd_file); in copy_event_to_user()
726 ret = -EFAULT; in copy_event_to_user()
738 count -= FAN_EVENT_METADATA_LEN; in copy_event_to_user()
740 if (fanotify_is_perm_event(event->mask)) in copy_event_to_user()
741 FANOTIFY_PERM(event)->fd = fd; in copy_event_to_user()
775 struct fsnotify_group *group = file->private_data; in fanotify_poll()
778 poll_wait(file, &group->notification_waitq, wait); in fanotify_poll()
779 spin_lock(&group->notification_lock); in fanotify_poll()
782 spin_unlock(&group->notification_lock); in fanotify_poll()
797 group = file->private_data; in fanotify_read()
801 add_wait_queue(&group->notification_waitq, &wait); in fanotify_read()
815 ret = -EAGAIN; in fanotify_read()
816 if (file->f_flags & O_NONBLOCK) in fanotify_read()
819 ret = -ERESTARTSYS; in fanotify_read()
831 if (unlikely(ret == -EOPENSTALE)) { in fanotify_read()
836 * read (i.e. return bytes read, -EAGAIN or wait). in fanotify_read()
845 if (!fanotify_is_perm_event(event->mask)) { in fanotify_read()
846 fsnotify_destroy_event(group, &event->fse); in fanotify_read()
849 spin_lock(&group->notification_lock); in fanotify_read()
852 wake_up(&group->fanotify_data.access_waitq); in fanotify_read()
854 spin_lock(&group->notification_lock); in fanotify_read()
855 list_add_tail(&event->fse.list, in fanotify_read()
856 &group->fanotify_data.access_list); in fanotify_read()
857 spin_unlock(&group->notification_lock); in fanotify_read()
863 count -= ret; in fanotify_read()
865 remove_wait_queue(&group->notification_waitq, &wait); in fanotify_read()
867 if (start != buf && ret != -EFAULT) in fanotify_read()
868 ret = buf - start; in fanotify_read()
881 return -EINVAL; in fanotify_write()
883 group = file->private_data; in fanotify_write()
888 return -EINVAL; in fanotify_write()
891 return -EFAULT; in fanotify_write()
893 info_len = count - sizeof(response); in fanotify_write()
906 struct fsnotify_group *group = file->private_data; in fanotify_release()
920 spin_lock(&group->notification_lock); in fanotify_release()
921 while (!list_empty(&group->fanotify_data.access_list)) { in fanotify_release()
924 event = list_first_entry(&group->fanotify_data.access_list, in fanotify_release()
926 list_del_init(&event->fae.fse.list); in fanotify_release()
928 spin_lock(&group->notification_lock); in fanotify_release()
932 * Destroy all non-permission events. For permission events just in fanotify_release()
939 if (!(event->mask & FANOTIFY_PERM_EVENTS)) { in fanotify_release()
940 spin_unlock(&group->notification_lock); in fanotify_release()
946 spin_lock(&group->notification_lock); in fanotify_release()
948 spin_unlock(&group->notification_lock); in fanotify_release()
951 wake_up(&group->fanotify_data.access_waitq); in fanotify_release()
953 /* matches the fanotify_init->fsnotify_alloc_group */ in fanotify_release()
964 int ret = -ENOTTY; in fanotify_ioctl()
967 group = file->private_data; in fanotify_ioctl()
973 spin_lock(&group->notification_lock); in fanotify_ioctl()
974 list_for_each_entry(fsn_event, &group->notification_list, list) in fanotify_ioctl()
976 spin_unlock(&group->notification_lock); in fanotify_ioctl()
997 struct path *path, unsigned int flags, __u64 mask, in fanotify_find_path() argument
1002 pr_debug("%s: dfd=%d filename=%p flags=%x\n", __func__, in fanotify_find_path()
1003 dfd, filename, flags); in fanotify_find_path()
1008 ret = -EBADF; in fanotify_find_path()
1012 ret = -ENOTDIR; in fanotify_find_path()
1013 if ((flags & FAN_MARK_ONLYDIR) && in fanotify_find_path()
1014 !(S_ISDIR(file_inode(fd_file(f))->i_mode))) { in fanotify_find_path()
1019 *path = fd_file(f)->f_path; in fanotify_find_path()
1025 if (!(flags & FAN_MARK_DONT_FOLLOW)) in fanotify_find_path()
1027 if (flags & FAN_MARK_ONLYDIR) in fanotify_find_path()
1042 ret = security_path_notify(path, mask, obj_type); in fanotify_find_path()
1051 __u32 mask, unsigned int flags, in fanotify_mark_remove_from_mask() argument
1057 mask &= ~umask; in fanotify_mark_remove_from_mask()
1058 spin_lock(&fsn_mark->lock); in fanotify_mark_remove_from_mask()
1060 if (!(flags & FANOTIFY_MARK_IGNORE_BITS)) { in fanotify_mark_remove_from_mask()
1061 fsn_mark->mask &= ~mask; in fanotify_mark_remove_from_mask()
1063 fsn_mark->ignore_mask &= ~mask; in fanotify_mark_remove_from_mask()
1067 * We need to keep the mark around even if remaining mask cannot in fanotify_mark_remove_from_mask()
1068 * result in any events (e.g. mask == FAN_ONDIR) to support incremenal in fanotify_mark_remove_from_mask()
1069 * changes to the mask. in fanotify_mark_remove_from_mask()
1072 *destroy = !((fsn_mark->mask | fsn_mark->ignore_mask) & ~umask); in fanotify_mark_remove_from_mask()
1073 spin_unlock(&fsn_mark->lock); in fanotify_mark_remove_from_mask()
1079 void *obj, unsigned int obj_type, __u32 mask, in fanotify_remove_mark() argument
1080 unsigned int flags, __u32 umask) in fanotify_remove_mark() argument
1090 return -ENOENT; in fanotify_remove_mark()
1093 removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, in fanotify_remove_mark()
1095 if (removed & fsnotify_conn_mask(fsn_mark->connector)) in fanotify_remove_mark()
1096 fsnotify_recalc_mask(fsn_mark->connector); in fanotify_remove_mark()
1117 * independent event flags in ignore mask. After that, trying to in fanotify_mark_update_flags()
1118 * update the ignore mask with the old FAN_MARK_IGNORED_MASK API in fanotify_mark_update_flags()
1122 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_HAS_IGNORE_FLAGS; in fanotify_mark_update_flags()
1126 * the removal of the FS_MODIFY bit in calculated mask if it was set in fanotify_mark_update_flags()
1127 * because of an ignore mask that is now going to survive FS_MODIFY. in fanotify_mark_update_flags()
1130 !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) { in fanotify_mark_update_flags()
1131 fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; in fanotify_mark_update_flags()
1132 if (!(fsn_mark->mask & FS_MODIFY)) in fanotify_mark_update_flags()
1136 if (fsn_mark->connector->type != FSNOTIFY_OBJ_TYPE_INODE || in fanotify_mark_update_flags()
1137 want_iref == !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) in fanotify_mark_update_flags()
1145 fsn_mark->flags &= ~FSNOTIFY_MARK_FLAG_NO_IREF; in fanotify_mark_update_flags()
1151 __u32 mask, unsigned int fan_flags) in fanotify_mark_add_to_mask() argument
1155 spin_lock(&fsn_mark->lock); in fanotify_mark_add_to_mask()
1157 fsn_mark->mask |= mask; in fanotify_mark_add_to_mask()
1159 fsn_mark->ignore_mask |= mask; in fanotify_mark_add_to_mask()
1162 ~fsnotify_conn_mask(fsn_mark->connector); in fanotify_mark_add_to_mask()
1165 spin_unlock(&fsn_mark->lock); in fanotify_mark_add_to_mask()
1184 FANOTIFY_MARK(mark)->fsid = fsid->id; in fanotify_set_mark_fsid()
1185 mark->flags |= FSNOTIFY_MARK_FLAG_HAS_FSID; in fanotify_set_mark_fsid()
1186 if (fsid->weak) in fanotify_set_mark_fsid()
1187 mark->flags |= FSNOTIFY_MARK_FLAG_WEAK_FSID; in fanotify_set_mark_fsid()
1190 if (list_empty(&group->marks_list)) in fanotify_set_mark_fsid()
1194 list_for_each_entry(old, &group->marks_list, g_list) { in fanotify_set_mark_fsid()
1195 conn = READ_ONCE(old->connector); in fanotify_set_mark_fsid()
1208 if ((mark->flags ^ old->flags) & FSNOTIFY_MARK_FLAG_WEAK_FSID) in fanotify_set_mark_fsid()
1209 return -EXDEV; in fanotify_set_mark_fsid()
1212 if (!fsid->weak) in fanotify_set_mark_fsid()
1216 if (old_sb != fsid->sb) in fanotify_set_mark_fsid()
1217 return -EXDEV; in fanotify_set_mark_fsid()
1219 /* Do not allow mixing marks from different btrfs sub-volumes */ in fanotify_set_mark_fsid()
1220 if (!fanotify_fsid_equal(&FANOTIFY_MARK(old)->fsid, in fanotify_set_mark_fsid()
1221 &FANOTIFY_MARK(mark)->fsid)) in fanotify_set_mark_fsid()
1222 return -EXDEV; in fanotify_set_mark_fsid()
1233 struct ucounts *ucounts = group->fanotify_data.ucounts; in fanotify_add_new_mark()
1244 !inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS)) in fanotify_add_new_mark()
1245 return ERR_PTR(-ENOSPC); in fanotify_add_new_mark()
1249 ret = -ENOMEM; in fanotify_add_new_mark()
1253 mark = &fan_mark->fsn_mark; in fanotify_add_new_mark()
1256 mark->flags |= FSNOTIFY_MARK_FLAG_NO_IREF; in fanotify_add_new_mark()
1264 fan_mark->fsid.val[0] = fan_mark->fsid.val[1] = 0; in fanotify_add_new_mark()
1283 if (mempool_initialized(&group->fanotify_data.error_events_pool)) in fanotify_group_init_error_pool()
1286 return mempool_init_kmalloc_pool(&group->fanotify_data.error_events_pool, in fanotify_group_init_error_pool()
1298 !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) in fanotify_may_update_existing_mark()
1299 return -EEXIST; in fanotify_may_update_existing_mark()
1302 * New ignore mask semantics cannot be downgraded to old semantics. in fanotify_may_update_existing_mark()
1305 fsn_mark->flags & FSNOTIFY_MARK_FLAG_HAS_IGNORE_FLAGS) in fanotify_may_update_existing_mark()
1306 return -EEXIST; in fanotify_may_update_existing_mark()
1309 * An ignore mask that survives modify could never be downgraded to not in fanotify_may_update_existing_mark()
1311 * explicit and return an error when trying to update the ignore mask in fanotify_may_update_existing_mark()
1316 fsn_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) in fanotify_may_update_existing_mark()
1317 return -EEXIST; in fanotify_may_update_existing_mark()
1324 __u32 mask, unsigned int fan_flags, in fanotify_add_mark() argument
1343 * Check if requested mark flags conflict with an existing mark flags. in fanotify_add_mark()
1350 * Error events are pre-allocated per group, only if strictly in fanotify_add_mark()
1354 (mask & FAN_FS_ERROR)) { in fanotify_add_mark()
1360 recalc = fanotify_mark_add_to_mask(fsn_mark, mask, fan_flags); in fanotify_add_mark()
1362 fsnotify_recalc_mask(fsn_mark->connector); in fanotify_add_mark()
1380 oevent->type = FANOTIFY_EVENT_TYPE_OVERFLOW; in fanotify_alloc_overflow_event()
1382 return &oevent->fse; in fanotify_alloc_overflow_event()
1400 SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) in SYSCALL_DEFINE2() argument
1404 unsigned int fid_mode = flags & FANOTIFY_FID_BITS; in SYSCALL_DEFINE2()
1405 unsigned int class = flags & FANOTIFY_CLASS_BITS; in SYSCALL_DEFINE2()
1408 pr_debug("%s: flags=%x event_f_flags=%x\n", in SYSCALL_DEFINE2()
1409 __func__, flags, event_f_flags); in SYSCALL_DEFINE2()
1414 * limited functionality - an unprivileged group is limited to in SYSCALL_DEFINE2()
1418 if ((flags & FANOTIFY_ADMIN_INIT_FLAGS) || !fid_mode) in SYSCALL_DEFINE2()
1419 return -EPERM; in SYSCALL_DEFINE2()
1430 if (flags & ~(FANOTIFY_INIT_FLAGS | FAN_ENABLE_AUDIT)) in SYSCALL_DEFINE2()
1432 if (flags & ~FANOTIFY_INIT_FLAGS) in SYSCALL_DEFINE2()
1434 return -EINVAL; in SYSCALL_DEFINE2()
1437 * A pidfd can only be returned for a thread-group leader; thus in SYSCALL_DEFINE2()
1441 if ((flags & FAN_REPORT_PIDFD) && (flags & FAN_REPORT_TID)) in SYSCALL_DEFINE2()
1442 return -EINVAL; in SYSCALL_DEFINE2()
1445 return -EINVAL; in SYSCALL_DEFINE2()
1453 return -EINVAL; in SYSCALL_DEFINE2()
1457 return -EINVAL; in SYSCALL_DEFINE2()
1464 return -EINVAL; in SYSCALL_DEFINE2()
1473 return -EINVAL; in SYSCALL_DEFINE2()
1476 if (flags & FAN_CLOEXEC) in SYSCALL_DEFINE2()
1478 if (flags & FAN_NONBLOCK) in SYSCALL_DEFINE2()
1489 group->fanotify_data.ucounts = inc_ucount(current_user_ns(), in SYSCALL_DEFINE2()
1492 if (!group->fanotify_data.ucounts) { in SYSCALL_DEFINE2()
1493 fd = -EMFILE; in SYSCALL_DEFINE2()
1497 group->fanotify_data.flags = flags | internal_flags; in SYSCALL_DEFINE2()
1498 group->memcg = get_mem_cgroup_from_mm(current->mm); in SYSCALL_DEFINE2()
1500 group->fanotify_data.merge_hash = fanotify_alloc_merge_hash(); in SYSCALL_DEFINE2()
1501 if (!group->fanotify_data.merge_hash) { in SYSCALL_DEFINE2()
1502 fd = -ENOMEM; in SYSCALL_DEFINE2()
1506 group->overflow_event = fanotify_alloc_overflow_event(); in SYSCALL_DEFINE2()
1507 if (unlikely(!group->overflow_event)) { in SYSCALL_DEFINE2()
1508 fd = -ENOMEM; in SYSCALL_DEFINE2()
1514 group->fanotify_data.f_flags = event_f_flags; in SYSCALL_DEFINE2()
1515 init_waitqueue_head(&group->fanotify_data.access_waitq); in SYSCALL_DEFINE2()
1516 INIT_LIST_HEAD(&group->fanotify_data.access_list); in SYSCALL_DEFINE2()
1519 group->priority = FSNOTIFY_PRIO_NORMAL; in SYSCALL_DEFINE2()
1522 group->priority = FSNOTIFY_PRIO_CONTENT; in SYSCALL_DEFINE2()
1525 group->priority = FSNOTIFY_PRIO_PRE_CONTENT; in SYSCALL_DEFINE2()
1528 fd = -EINVAL; in SYSCALL_DEFINE2()
1532 if (flags & FAN_UNLIMITED_QUEUE) { in SYSCALL_DEFINE2()
1533 fd = -EPERM; in SYSCALL_DEFINE2()
1536 group->max_events = UINT_MAX; in SYSCALL_DEFINE2()
1538 group->max_events = fanotify_max_queued_events; in SYSCALL_DEFINE2()
1541 if (flags & FAN_UNLIMITED_MARKS) { in SYSCALL_DEFINE2()
1542 fd = -EPERM; in SYSCALL_DEFINE2()
1547 if (flags & FAN_ENABLE_AUDIT) { in SYSCALL_DEFINE2()
1548 fd = -EPERM; in SYSCALL_DEFINE2()
1564 static int fanotify_test_fsid(struct dentry *dentry, unsigned int flags, in fanotify_test_fsid() argument
1567 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in fanotify_test_fsid()
1574 err = vfs_get_fsid(dentry, &fsid->id); in fanotify_test_fsid()
1578 fsid->sb = dentry->d_sb; in fanotify_test_fsid()
1579 if (!fsid->id.val[0] && !fsid->id.val[1]) { in fanotify_test_fsid()
1580 err = -ENODEV; in fanotify_test_fsid()
1588 err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid); in fanotify_test_fsid()
1592 if (!fanotify_fsid_equal(&root_fsid, &fsid->id)) { in fanotify_test_fsid()
1593 err = -EXDEV; in fanotify_test_fsid()
1597 fsid->weak = false; in fanotify_test_fsid()
1602 fsid->weak = true; in fanotify_test_fsid()
1607 static int fanotify_test_fid(struct dentry *dentry, unsigned int flags) in fanotify_test_fid() argument
1609 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in fanotify_test_fid()
1610 const struct export_operations *nop = dentry->d_sb->s_export_op; in fanotify_test_fid()
1618 return -EOPNOTSUPP; in fanotify_test_fid()
1626 return -EOPNOTSUPP; in fanotify_test_fid()
1632 const struct path *path, __u64 mask, in fanotify_events_supported() argument
1633 unsigned int flags) in fanotify_events_supported() argument
1635 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in fanotify_events_supported()
1636 /* Strict validation of events in non-dir inode mask with v5.17+ APIs */ in fanotify_events_supported()
1638 (mask & FAN_RENAME) || in fanotify_events_supported()
1639 (flags & FAN_MARK_IGNORE); in fanotify_events_supported()
1644 * deadlocking the system - open done when reporting fanotify event in fanotify_events_supported()
1649 if (mask & FANOTIFY_PERM_EVENTS && in fanotify_events_supported()
1650 path->mnt->mnt_sb->s_type->fs_flags & FS_DISALLOW_NOTIFY_PERM) in fanotify_events_supported()
1651 return -EINVAL; in fanotify_events_supported()
1664 path->mnt->mnt_sb->s_flags & SB_NOUSER) in fanotify_events_supported()
1665 return -EINVAL; in fanotify_events_supported()
1669 * flags FAN_ONDIR and FAN_EVENT_ON_CHILD in mask of non-dir inode, in fanotify_events_supported()
1673 !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) in fanotify_events_supported()
1674 return -ENOTDIR; in fanotify_events_supported()
1679 static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, in do_fanotify_mark() argument
1689 unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; in do_fanotify_mark()
1690 unsigned int mark_cmd = flags & FANOTIFY_MARK_CMD_BITS; in do_fanotify_mark()
1691 unsigned int ignore = flags & FANOTIFY_MARK_IGNORE_BITS; in do_fanotify_mark()
1697 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", in do_fanotify_mark()
1698 __func__, fanotify_fd, flags, dfd, pathname, mask); in do_fanotify_mark()
1701 if (upper_32_bits(mask)) in do_fanotify_mark()
1702 return -EINVAL; in do_fanotify_mark()
1704 if (flags & ~FANOTIFY_MARK_FLAGS) in do_fanotify_mark()
1705 return -EINVAL; in do_fanotify_mark()
1718 return -EINVAL; in do_fanotify_mark()
1724 if (!mask) in do_fanotify_mark()
1725 return -EINVAL; in do_fanotify_mark()
1728 if (flags & ~(FANOTIFY_MARK_TYPE_BITS | FAN_MARK_FLUSH)) in do_fanotify_mark()
1729 return -EINVAL; in do_fanotify_mark()
1732 return -EINVAL; in do_fanotify_mark()
1738 if (mask & ~valid_mask) in do_fanotify_mark()
1739 return -EINVAL; in do_fanotify_mark()
1744 return -EINVAL; in do_fanotify_mark()
1747 * Event flags (FAN_ONDIR, FAN_EVENT_ON_CHILD) have no effect with in do_fanotify_mark()
1751 mask &= ~FANOTIFY_EVENT_FLAGS; in do_fanotify_mark()
1757 return -EBADF; in do_fanotify_mark()
1760 ret = -EINVAL; in do_fanotify_mark()
1761 if (unlikely(fd_file(f)->f_op != &fanotify_fops)) in do_fanotify_mark()
1763 group = fd_file(f)->private_data; in do_fanotify_mark()
1770 ret = -EPERM; in do_fanotify_mark()
1779 ret = -EINVAL; in do_fanotify_mark()
1780 if (mask & FANOTIFY_PERM_EVENTS && in do_fanotify_mark()
1781 group->priority < FSNOTIFY_PRIO_CONTENT) in do_fanotify_mark()
1784 if (mask & FAN_FS_ERROR && in do_fanotify_mark()
1792 if (flags & FAN_MARK_EVICTABLE && in do_fanotify_mark()
1798 * event->fd require a group that supports reporting fid. Those in do_fanotify_mark()
1804 if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_EVENT_FLAGS) && in do_fanotify_mark()
1813 if (mask & FAN_RENAME && !(fid_mode & FAN_REPORT_NAME)) in do_fanotify_mark()
1827 ret = fanotify_find_path(dfd, pathname, &path, flags, in do_fanotify_mark()
1828 (mask & ALL_FSNOTIFY_EVENTS), obj_type); in do_fanotify_mark()
1833 ret = fanotify_events_supported(group, &path, mask, flags); in do_fanotify_mark()
1839 ret = fanotify_test_fsid(path.dentry, flags, &__fsid); in do_fanotify_mark()
1843 ret = fanotify_test_fid(path.dentry, flags); in do_fanotify_mark()
1852 inode = path.dentry->d_inode; in do_fanotify_mark()
1859 obj = mnt->mnt_sb; in do_fanotify_mark()
1864 * an ignore mask, unless that ignore mask is supposed to survive in do_fanotify_mark()
1867 if (mark_cmd == FAN_MARK_ADD && (flags & FANOTIFY_MARK_IGNORE_BITS) && in do_fanotify_mark()
1868 !(flags & FAN_MARK_IGNORED_SURV_MODIFY)) { in do_fanotify_mark()
1869 ret = mnt ? -EINVAL : -EISDIR; in do_fanotify_mark()
1872 (mnt || S_ISDIR(inode->i_mode))) in do_fanotify_mark()
1880 /* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */ in do_fanotify_mark()
1881 if (mnt || !S_ISDIR(inode->i_mode)) { in do_fanotify_mark()
1882 mask &= ~FAN_EVENT_ON_CHILD; in do_fanotify_mark()
1886 * events with parent/name info for non-directory. in do_fanotify_mark()
1889 (flags & FAN_MARK_ADD) && !ignore) in do_fanotify_mark()
1890 mask |= FAN_EVENT_ON_CHILD; in do_fanotify_mark()
1896 ret = fanotify_add_mark(group, obj, obj_type, mask, flags, in do_fanotify_mark()
1900 ret = fanotify_remove_mark(group, obj, obj_type, mask, flags, in do_fanotify_mark()
1904 ret = -EINVAL; in do_fanotify_mark()
1915 SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, in SYSCALL_DEFINE5() argument
1916 __u64, mask, int, dfd, in SYSCALL_DEFINE5() argument
1919 return do_fanotify_mark(fanotify_fd, flags, mask, dfd, pathname); in SYSCALL_DEFINE5()
1925 int, fanotify_fd, unsigned int, flags, in SYSCALL32_DEFINE6() argument
1926 SC_ARG64(mask), int, dfd, in SYSCALL32_DEFINE6() argument
1929 return do_fanotify_mark(fanotify_fd, flags, SC_VAL64(__u64, mask), in SYSCALL32_DEFINE6()
1935 * fanotify_user_setup - Our initialization function. Note that we cannot return
1936 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
1951 max_marks = (((si.totalram - si.totalhigh) / 100) << PAGE_SHIFT) / in fanotify_user_setup()