#include <linux/fanotify.h>
#include <linux/fcntl.h>
#include <linux/fdtable.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/anon_inodes.h>
#include <linux/fsnotify_backend.h>
#include <linux/init.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/poll.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/uaccess.h>
#include <linux/compat.h>
#include <linux/sched/signal.h>
#include <linux/memcontrol.h>
#include <linux/statfs.h>
#include <linux/exportfs.h>
#include <asm/ioctls.h>
#include "../fsnotify.h"
#include "../fdinfo.h"
#include "fanotify.h"
#define FANOTIFY_DEFAULT_MAX_EVENTS …
#define FANOTIFY_OLD_DEFAULT_MAX_MARKS …
#define FANOTIFY_DEFAULT_MAX_GROUPS …
#define FANOTIFY_DEFAULT_FEE_POOL_SIZE …
#define FANOTIFY_DEFAULT_MAX_USER_MARKS …
#define INODE_MARK_COST …
static int fanotify_max_queued_events __read_mostly;
#ifdef CONFIG_SYSCTL
#include <linux/sysctl.h>
static long ft_zero = …;
static long ft_int_max = …;
static struct ctl_table fanotify_table[] = …;
static void __init fanotify_sysctls_init(void)
{ … }
#else
#define fanotify_sysctls_init …
#endif
#define FANOTIFY_INIT_ALL_EVENT_F_BITS …
extern const struct fsnotify_ops fanotify_fsnotify_ops;
struct kmem_cache *fanotify_mark_cache __ro_after_init;
struct kmem_cache *fanotify_fid_event_cachep __ro_after_init;
struct kmem_cache *fanotify_path_event_cachep __ro_after_init;
struct kmem_cache *fanotify_perm_event_cachep __ro_after_init;
#define FANOTIFY_EVENT_ALIGN …
#define FANOTIFY_FID_INFO_HDR_LEN …
#define FANOTIFY_PIDFD_INFO_HDR_LEN …
#define FANOTIFY_ERROR_INFO_LEN …
static int fanotify_fid_info_len(int fh_len, int name_len)
{ … }
static int fanotify_dir_name_info_len(struct fanotify_event *event)
{ … }
static size_t fanotify_event_len(unsigned int info_mode,
struct fanotify_event *event)
{ … }
static void fanotify_unhash_event(struct fsnotify_group *group,
struct fanotify_event *event)
{ … }
static struct fanotify_event *get_one_event(struct fsnotify_group *group,
size_t count)
{ … }
static int create_fd(struct fsnotify_group *group, const struct path *path,
struct file **file)
{ … }
static int process_access_response_info(const char __user *info,
size_t info_len,
struct fanotify_response_info_audit_rule *friar)
{ … }
static void finish_permission_event(struct fsnotify_group *group,
struct fanotify_perm_event *event, u32 response,
struct fanotify_response_info_audit_rule *friar)
__releases(&group->notification_lock)
{ … }
static int process_access_response(struct fsnotify_group *group,
struct fanotify_response *response_struct,
const char __user *info,
size_t info_len)
{ … }
static size_t copy_error_info_to_user(struct fanotify_event *event,
char __user *buf, int count)
{ … }
static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
int info_type, const char *name,
size_t name_len,
char __user *buf, size_t count)
{ … }
static int copy_pidfd_info_to_user(int pidfd,
char __user *buf,
size_t count)
{ … }
static int copy_info_records_to_user(struct fanotify_event *event,
struct fanotify_info *info,
unsigned int info_mode, int pidfd,
char __user *buf, size_t count)
{ … }
static ssize_t copy_event_to_user(struct fsnotify_group *group,
struct fanotify_event *event,
char __user *buf, size_t count)
{ … }
static __poll_t fanotify_poll(struct file *file, poll_table *wait)
{ … }
static ssize_t fanotify_read(struct file *file, char __user *buf,
size_t count, loff_t *pos)
{ … }
static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
{ … }
static int fanotify_release(struct inode *ignored, struct file *file)
{ … }
static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ … }
static const struct file_operations fanotify_fops = …;
static int fanotify_find_path(int dfd, const char __user *filename,
struct path *path, unsigned int flags, __u64 mask,
unsigned int obj_type)
{ … }
static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark,
__u32 mask, unsigned int flags,
__u32 umask, int *destroy)
{ … }
static int fanotify_remove_mark(struct fsnotify_group *group,
void *obj, unsigned int obj_type, __u32 mask,
unsigned int flags, __u32 umask)
{ … }
static bool fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark,
unsigned int fan_flags)
{ … }
static bool fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
__u32 mask, unsigned int fan_flags)
{ … }
struct fan_fsid { … };
static int fanotify_set_mark_fsid(struct fsnotify_group *group,
struct fsnotify_mark *mark,
struct fan_fsid *fsid)
{ … }
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
void *obj,
unsigned int obj_type,
unsigned int fan_flags,
struct fan_fsid *fsid)
{ … }
static int fanotify_group_init_error_pool(struct fsnotify_group *group)
{ … }
static int fanotify_may_update_existing_mark(struct fsnotify_mark *fsn_mark,
unsigned int fan_flags)
{ … }
static int fanotify_add_mark(struct fsnotify_group *group,
void *obj, unsigned int obj_type,
__u32 mask, unsigned int fan_flags,
struct fan_fsid *fsid)
{ … }
static struct fsnotify_event *fanotify_alloc_overflow_event(void)
{ … }
static struct hlist_head *fanotify_alloc_merge_hash(void)
{ … }
SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
{ … }
static int fanotify_test_fsid(struct dentry *dentry, unsigned int flags,
struct fan_fsid *fsid)
{ … }
static int fanotify_test_fid(struct dentry *dentry, unsigned int flags)
{ … }
static int fanotify_events_supported(struct fsnotify_group *group,
const struct path *path, __u64 mask,
unsigned int flags)
{ … }
static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
int dfd, const char __user *pathname)
{ … }
#ifndef CONFIG_ARCH_SPLIT_ARG64
SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
__u64, mask, int, dfd,
const char __user *, pathname)
{ … }
#endif
#if defined(CONFIG_ARCH_SPLIT_ARG64) || defined(CONFIG_COMPAT)
SYSCALL32_DEFINE6(fanotify_mark,
int, fanotify_fd, unsigned int, flags,
SC_ARG64(mask), int, dfd,
const char __user *, pathname)
{ … }
#endif
static int __init fanotify_user_setup(void)
{ … }
device_initcall(fanotify_user_setup);