16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2607ca46eSDavid Howells #ifndef _UAPI_LINUX_FANOTIFY_H 3607ca46eSDavid Howells #define _UAPI_LINUX_FANOTIFY_H 4607ca46eSDavid Howells 5607ca46eSDavid Howells #include <linux/types.h> 6607ca46eSDavid Howells 7607ca46eSDavid Howells /* the following events that user-space can register for */ 8607ca46eSDavid Howells #define FAN_ACCESS 0x00000001 /* File was accessed */ 9607ca46eSDavid Howells #define FAN_MODIFY 0x00000002 /* File was modified */ 10235328d1SAmir Goldstein #define FAN_ATTRIB 0x00000004 /* Metadata changed */ 11*8c2c2549SVicki Pfau #define FAN_CLOSE_WRITE 0x00000008 /* Writable file closed */ 12*8c2c2549SVicki Pfau #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwritable file closed */ 13607ca46eSDavid Howells #define FAN_OPEN 0x00000020 /* File was opened */ 14235328d1SAmir Goldstein #define FAN_MOVED_FROM 0x00000040 /* File was moved from X */ 15235328d1SAmir Goldstein #define FAN_MOVED_TO 0x00000080 /* File was moved to Y */ 16235328d1SAmir Goldstein #define FAN_CREATE 0x00000100 /* Subfile was created */ 17235328d1SAmir Goldstein #define FAN_DELETE 0x00000200 /* Subfile was deleted */ 18235328d1SAmir Goldstein #define FAN_DELETE_SELF 0x00000400 /* Self was deleted */ 19235328d1SAmir Goldstein #define FAN_MOVE_SELF 0x00000800 /* Self was moved */ 209b076f1cSMatthew Bobrowski #define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */ 21607ca46eSDavid Howells 22607ca46eSDavid Howells #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ 238d11a4f4SGabriel Krisman Bertazi #define FAN_FS_ERROR 0x00008000 /* Filesystem error */ 24607ca46eSDavid Howells 25607ca46eSDavid Howells #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ 26607ca46eSDavid Howells #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ 2766917a31SMatthew Bobrowski #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ 28607ca46eSDavid Howells 296473ea76SAmir Goldstein #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ 30607ca46eSDavid Howells 313982534bSAmir Goldstein #define FAN_RENAME 0x10000000 /* File was renamed */ 323982534bSAmir Goldstein 336473ea76SAmir Goldstein #define FAN_ONDIR 0x40000000 /* Event occurred against dir */ 34607ca46eSDavid Howells 35607ca46eSDavid Howells /* helper events */ 36607ca46eSDavid Howells #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 37235328d1SAmir Goldstein #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ 38607ca46eSDavid Howells 39607ca46eSDavid Howells /* flags used for fanotify_init() */ 40607ca46eSDavid Howells #define FAN_CLOEXEC 0x00000001 41607ca46eSDavid Howells #define FAN_NONBLOCK 0x00000002 42607ca46eSDavid Howells 43d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits are used together. */ 44607ca46eSDavid Howells #define FAN_CLASS_NOTIF 0x00000000 45607ca46eSDavid Howells #define FAN_CLASS_CONTENT 0x00000004 46607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT 0x00000008 4723c9deebSAmir Goldstein 4823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 49607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 50607ca46eSDavid Howells FAN_CLASS_PRE_CONTENT) 51607ca46eSDavid Howells 52607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE 0x00000010 53607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS 0x00000020 54de8cd83eSSteve Grubb #define FAN_ENABLE_AUDIT 0x00000040 55607ca46eSDavid Howells 56d0a6a87eSAmir Goldstein /* Flags to determine fanotify event format */ 57af579bebSMatthew Bobrowski #define FAN_REPORT_PIDFD 0x00000080 /* Report pidfd for event->pid */ 58d0a6a87eSAmir Goldstein #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 59e9e0c890SAmir Goldstein #define FAN_REPORT_FID 0x00000200 /* Report unique file id */ 6083b7a598SAmir Goldstein #define FAN_REPORT_DIR_FID 0x00000400 /* Report unique directory id */ 61929943b3SAmir Goldstein #define FAN_REPORT_NAME 0x00000800 /* Report events with name */ 62d61fd650SAmir Goldstein #define FAN_REPORT_TARGET_FID 0x00001000 /* Report dirent target id */ 63929943b3SAmir Goldstein 64929943b3SAmir Goldstein /* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */ 65929943b3SAmir Goldstein #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) 66d61fd650SAmir Goldstein /* Convenience macro - FAN_REPORT_TARGET_FID requires all other FID flags */ 67d61fd650SAmir Goldstein #define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \ 68d61fd650SAmir Goldstein FAN_REPORT_FID | FAN_REPORT_TARGET_FID) 69d0a6a87eSAmir Goldstein 7023c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 71607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 72607ca46eSDavid Howells FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 73607ca46eSDavid Howells FAN_UNLIMITED_MARKS) 74607ca46eSDavid Howells 75607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */ 76607ca46eSDavid Howells #define FAN_MARK_ADD 0x00000001 77607ca46eSDavid Howells #define FAN_MARK_REMOVE 0x00000002 78607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW 0x00000004 79607ca46eSDavid Howells #define FAN_MARK_ONLYDIR 0x00000008 80d54f4fbaSAmir Goldstein /* FAN_MARK_MOUNT is 0x00000010 */ 81607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK 0x00000020 82607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 83607ca46eSDavid Howells #define FAN_MARK_FLUSH 0x00000080 84d54f4fbaSAmir Goldstein /* FAN_MARK_FILESYSTEM is 0x00000100 */ 857d5e005dSAmir Goldstein #define FAN_MARK_EVICTABLE 0x00000200 86e252f2edSAmir Goldstein /* This bit is mutually exclusive with FAN_MARK_IGNORED_MASK bit */ 87e252f2edSAmir Goldstein #define FAN_MARK_IGNORE 0x00000400 88d54f4fbaSAmir Goldstein 89d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits can be used togther. */ 90d54f4fbaSAmir Goldstein #define FAN_MARK_INODE 0x00000000 91d54f4fbaSAmir Goldstein #define FAN_MARK_MOUNT 0x00000010 92d54f4fbaSAmir Goldstein #define FAN_MARK_FILESYSTEM 0x00000100 93607ca46eSDavid Howells 94e252f2edSAmir Goldstein /* 95e252f2edSAmir Goldstein * Convenience macro - FAN_MARK_IGNORE requires FAN_MARK_IGNORED_SURV_MODIFY 96e252f2edSAmir Goldstein * for non-inode mark types. 97e252f2edSAmir Goldstein */ 98e252f2edSAmir Goldstein #define FAN_MARK_IGNORE_SURV (FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY) 99e252f2edSAmir Goldstein 10023c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 101607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 102607ca46eSDavid Howells FAN_MARK_REMOVE |\ 103607ca46eSDavid Howells FAN_MARK_DONT_FOLLOW |\ 104607ca46eSDavid Howells FAN_MARK_ONLYDIR |\ 10523c9deebSAmir Goldstein FAN_MARK_MOUNT |\ 106607ca46eSDavid Howells FAN_MARK_IGNORED_MASK |\ 107607ca46eSDavid Howells FAN_MARK_IGNORED_SURV_MODIFY |\ 10823c9deebSAmir Goldstein FAN_MARK_FLUSH) 109607ca46eSDavid Howells 11023c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 111607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\ 112607ca46eSDavid Howells FAN_MODIFY |\ 113607ca46eSDavid Howells FAN_CLOSE |\ 114607ca46eSDavid Howells FAN_OPEN) 115607ca46eSDavid Howells 116607ca46eSDavid Howells /* 117607ca46eSDavid Howells * All events which require a permission response from userspace 118607ca46eSDavid Howells */ 11923c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 120607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 121607ca46eSDavid Howells FAN_ACCESS_PERM) 122607ca46eSDavid Howells 12323c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 124607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 125607ca46eSDavid Howells FAN_ALL_PERM_EVENTS |\ 126607ca46eSDavid Howells FAN_Q_OVERFLOW) 127607ca46eSDavid Howells 128607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION 3 129607ca46eSDavid Howells 130607ca46eSDavid Howells struct fanotify_event_metadata { 131607ca46eSDavid Howells __u32 event_len; 132607ca46eSDavid Howells __u8 vers; 133607ca46eSDavid Howells __u8 reserved; 134607ca46eSDavid Howells __u16 metadata_len; 135607ca46eSDavid Howells __aligned_u64 mask; 136607ca46eSDavid Howells __s32 fd; 137607ca46eSDavid Howells __s32 pid; 138607ca46eSDavid Howells }; 139607ca46eSDavid Howells 1405e469c83SAmir Goldstein #define FAN_EVENT_INFO_TYPE_FID 1 14144d705b0SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 14283b7a598SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID 3 143af579bebSMatthew Bobrowski #define FAN_EVENT_INFO_TYPE_PIDFD 4 144130a3c74SGabriel Krisman Bertazi #define FAN_EVENT_INFO_TYPE_ERROR 5 1455e469c83SAmir Goldstein 1467326e382SAmir Goldstein /* Special info types for FAN_RENAME */ 1477326e382SAmir Goldstein #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 1487326e382SAmir Goldstein /* Reserved for FAN_EVENT_INFO_TYPE_OLD_DFID 11 */ 1497326e382SAmir Goldstein #define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12 1507326e382SAmir Goldstein /* Reserved for FAN_EVENT_INFO_TYPE_NEW_DFID 13 */ 1517326e382SAmir Goldstein 1525e469c83SAmir Goldstein /* Variable length info record following event metadata */ 1535e469c83SAmir Goldstein struct fanotify_event_info_header { 1545e469c83SAmir Goldstein __u8 info_type; 1555e469c83SAmir Goldstein __u8 pad; 1565e469c83SAmir Goldstein __u16 len; 1575e469c83SAmir Goldstein }; 1585e469c83SAmir Goldstein 15944d705b0SAmir Goldstein /* 16083b7a598SAmir Goldstein * Unique file identifier info record. 16183b7a598SAmir Goldstein * This structure is used for records of types FAN_EVENT_INFO_TYPE_FID, 16283b7a598SAmir Goldstein * FAN_EVENT_INFO_TYPE_DFID and FAN_EVENT_INFO_TYPE_DFID_NAME. 16383b7a598SAmir Goldstein * For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null terminated 16483b7a598SAmir Goldstein * name immediately after the file handle. 16544d705b0SAmir Goldstein */ 1665e469c83SAmir Goldstein struct fanotify_event_info_fid { 1675e469c83SAmir Goldstein struct fanotify_event_info_header hdr; 1685e469c83SAmir Goldstein __kernel_fsid_t fsid; 1695e469c83SAmir Goldstein /* 1705e469c83SAmir Goldstein * Following is an opaque struct file_handle that can be passed as 1715e469c83SAmir Goldstein * an argument to open_by_handle_at(2). 1725e469c83SAmir Goldstein */ 17394dfc73eSGustavo A. R. Silva unsigned char handle[]; 1745e469c83SAmir Goldstein }; 1755e469c83SAmir Goldstein 176af579bebSMatthew Bobrowski /* 177af579bebSMatthew Bobrowski * This structure is used for info records of type FAN_EVENT_INFO_TYPE_PIDFD. 178af579bebSMatthew Bobrowski * It holds a pidfd for the pid that was responsible for generating an event. 179af579bebSMatthew Bobrowski */ 180af579bebSMatthew Bobrowski struct fanotify_event_info_pidfd { 181af579bebSMatthew Bobrowski struct fanotify_event_info_header hdr; 182af579bebSMatthew Bobrowski __s32 pidfd; 183af579bebSMatthew Bobrowski }; 184af579bebSMatthew Bobrowski 185130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_error { 186130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_header hdr; 187130a3c74SGabriel Krisman Bertazi __s32 error; 188130a3c74SGabriel Krisman Bertazi __u32 error_count; 189130a3c74SGabriel Krisman Bertazi }; 190130a3c74SGabriel Krisman Bertazi 19170529a19SRichard Guy Briggs /* 19270529a19SRichard Guy Briggs * User space may need to record additional information about its decision. 19370529a19SRichard Guy Briggs * The extra information type records what kind of information is included. 19470529a19SRichard Guy Briggs * The default is none. We also define an extra information buffer whose 19570529a19SRichard Guy Briggs * size is determined by the extra information type. 19670529a19SRichard Guy Briggs * 19770529a19SRichard Guy Briggs * If the information type is Audit Rule, then the information following 19870529a19SRichard Guy Briggs * is the rule number that triggered the user space decision that 19970529a19SRichard Guy Briggs * requires auditing. 20070529a19SRichard Guy Briggs */ 20170529a19SRichard Guy Briggs 20270529a19SRichard Guy Briggs #define FAN_RESPONSE_INFO_NONE 0 20370529a19SRichard Guy Briggs #define FAN_RESPONSE_INFO_AUDIT_RULE 1 20470529a19SRichard Guy Briggs 205607ca46eSDavid Howells struct fanotify_response { 206607ca46eSDavid Howells __s32 fd; 207607ca46eSDavid Howells __u32 response; 208607ca46eSDavid Howells }; 209607ca46eSDavid Howells 21070529a19SRichard Guy Briggs struct fanotify_response_info_header { 21170529a19SRichard Guy Briggs __u8 type; 21270529a19SRichard Guy Briggs __u8 pad; 21370529a19SRichard Guy Briggs __u16 len; 21470529a19SRichard Guy Briggs }; 21570529a19SRichard Guy Briggs 21670529a19SRichard Guy Briggs struct fanotify_response_info_audit_rule { 21770529a19SRichard Guy Briggs struct fanotify_response_info_header hdr; 21870529a19SRichard Guy Briggs __u32 rule_number; 21970529a19SRichard Guy Briggs __u32 subj_trust; 22070529a19SRichard Guy Briggs __u32 obj_trust; 22170529a19SRichard Guy Briggs }; 22270529a19SRichard Guy Briggs 223607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */ 224607ca46eSDavid Howells #define FAN_ALLOW 0x01 225607ca46eSDavid Howells #define FAN_DENY 0x02 226de8cd83eSSteve Grubb #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ 22770529a19SRichard Guy Briggs #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ 228de8cd83eSSteve Grubb 229607ca46eSDavid Howells /* No fd set in event */ 230607ca46eSDavid Howells #define FAN_NOFD -1 231af579bebSMatthew Bobrowski #define FAN_NOPIDFD FAN_NOFD 232af579bebSMatthew Bobrowski #define FAN_EPIDFD -2 233607ca46eSDavid Howells 234607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */ 235607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 236607ca46eSDavid Howells 237607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 238607ca46eSDavid Howells (struct fanotify_event_metadata*)(((char *)(meta)) + \ 239607ca46eSDavid Howells (meta)->event_len)) 240607ca46eSDavid Howells 241607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 242607ca46eSDavid Howells (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 243607ca46eSDavid Howells (long)(meta)->event_len <= (long)(len)) 244607ca46eSDavid Howells 245607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */ 246