fs/notify/fanotify/fanotify_user.c
Source file repositories/reference/linux-study-clean/fs/notify/fanotify/fanotify_user.c
File Facts
- System
- Linux kernel
- Corpus path
fs/notify/fanotify/fanotify_user.c- Extension
.c- Size
- 59839 bytes
- Lines
- 2198
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fanotify.hlinux/fcntl.hlinux/file.hlinux/fs.hlinux/anon_inodes.hlinux/fsnotify_backend.hlinux/init.hlinux/mount.hlinux/namei.hlinux/poll.hlinux/security.hlinux/syscalls.hlinux/slab.hlinux/types.hlinux/uaccess.hlinux/compat.hlinux/sched/signal.hlinux/memcontrol.hlinux/statfs.hlinux/exportfs.hlinux/pidfd.hasm/ioctls.h../fsnotify.h../fdinfo.hfanotify.hlinux/sysctl.h
Detected Declarations
syscall fanotify_initsyscall fanotify_markstruct fan_fsidfunction fanotify_sysctls_initfunction perm_group_watchdog_schedulefunction perm_group_watchdogfunction list_for_each_entryfunction list_for_each_entryfunction fanotify_perm_watchdog_group_removefunction fanotify_perm_watchdog_group_addfunction fanotify_fid_info_lenfunction fanotify_dir_name_info_lenfunction fanotify_event_lenfunction fanotify_unhash_eventfunction create_fdfunction process_access_response_infofunction finish_permission_eventfunction process_access_responsefunction openfunction copy_mnt_info_to_userfunction copy_error_info_to_userfunction copy_fid_info_to_userfunction copy_pidfd_info_to_userfunction copy_range_info_to_userfunction copy_info_records_to_userfunction copy_event_to_userfunction fanotify_pollfunction fanotify_readfunction fanotify_writefunction fanotify_releasefunction fanotify_get_responsefunction fanotify_ioctlfunction fanotify_find_pathfunction fanotify_mark_remove_from_maskfunction fanotify_remove_markfunction fanotify_mark_update_flagsfunction fanotify_mark_add_to_maskfunction fanotify_set_mark_fsidfunction fanotify_group_init_error_poolfunction fanotify_may_update_existing_markfunction fanotify_add_markfunction neededfunction fanotify_test_fsidfunction fanotify_test_fidfunction fanotify_events_supportedfunction do_fanotify_markfunction flagsfunction SC_ARG64
Annotated Snippet
SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
{
struct user_namespace *user_ns = current_user_ns();
int f_flags, fd;
unsigned int fid_mode = flags & FANOTIFY_FID_BITS;
unsigned int class = flags & FANOTIFY_CLASS_BITS;
unsigned int internal_flags = 0;
pr_debug("%s: flags=%x event_f_flags=%x\n",
__func__, flags, event_f_flags);
/*
* An unprivileged user can setup an fanotify group with limited
* functionality - an unprivileged group is limited to notification
* events with file handles or mount ids and it cannot use unlimited
* queue/marks.
*/
if (((flags & FANOTIFY_ADMIN_INIT_FLAGS) ||
!(flags & (FANOTIFY_FID_BITS | FAN_REPORT_MNT))) &&
!capable(CAP_SYS_ADMIN))
return -EPERM;
if (!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN)) {
/*
* Setting the internal flag FANOTIFY_UNPRIV on the group
* prevents setting mount/filesystem marks on this group and
* prevents reporting pid and open fd in events.
*/
internal_flags |= FANOTIFY_UNPRIV;
}
#ifdef CONFIG_AUDITSYSCALL
if (flags & ~(FANOTIFY_INIT_FLAGS | FAN_ENABLE_AUDIT))
#else
if (flags & ~FANOTIFY_INIT_FLAGS)
#endif
return -EINVAL;
/* Don't allow mixing mnt events with inode events for now */
if (flags & FAN_REPORT_MNT) {
if (class != FAN_CLASS_NOTIF)
return -EINVAL;
if (flags & (FANOTIFY_FID_BITS | FAN_REPORT_FD_ERROR))
return -EINVAL;
}
if (event_f_flags & ~FANOTIFY_INIT_ALL_EVENT_F_BITS)
return -EINVAL;
switch (event_f_flags & O_ACCMODE) {
case O_RDONLY:
case O_RDWR:
case O_WRONLY:
break;
default:
return -EINVAL;
}
if (fid_mode && class != FAN_CLASS_NOTIF)
return -EINVAL;
/*
* Child name is reported with parent fid so requires dir fid.
* We can report both child fid and dir fid with or without name.
*/
if ((fid_mode & FAN_REPORT_NAME) && !(fid_mode & FAN_REPORT_DIR_FID))
return -EINVAL;
/*
* FAN_REPORT_TARGET_FID requires FAN_REPORT_NAME and FAN_REPORT_FID
* and is used as an indication to report both dir and child fid on all
* dirent events.
*/
if ((fid_mode & FAN_REPORT_TARGET_FID) &&
(!(fid_mode & FAN_REPORT_NAME) || !(fid_mode & FAN_REPORT_FID)))
return -EINVAL;
f_flags = O_RDWR;
if (flags & FAN_CLOEXEC)
f_flags |= O_CLOEXEC;
if (flags & FAN_NONBLOCK)
f_flags |= O_NONBLOCK;
CLASS(fsnotify_group, group)(&fanotify_fsnotify_ops,
FSNOTIFY_GROUP_USER);
/* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
if (IS_ERR(group))
return PTR_ERR(group);
/* Enforce groups limits per user in all containing user ns */
Annotation
- Immediate include surface: `linux/fanotify.h`, `linux/fcntl.h`, `linux/file.h`, `linux/fs.h`, `linux/anon_inodes.h`, `linux/fsnotify_backend.h`, `linux/init.h`, `linux/mount.h`.
- Detected declarations: `syscall fanotify_init`, `syscall fanotify_mark`, `struct fan_fsid`, `function fanotify_sysctls_init`, `function perm_group_watchdog_schedule`, `function perm_group_watchdog`, `function list_for_each_entry`, `function list_for_each_entry`, `function fanotify_perm_watchdog_group_remove`, `function fanotify_perm_watchdog_group_add`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.