Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_FANOTIFY_H
0003 #define _LINUX_FANOTIFY_H
0004 
0005 #include <linux/sysctl.h>
0006 #include <uapi/linux/fanotify.h>
0007 
0008 #define FAN_GROUP_FLAG(group, flag) \
0009     ((group)->fanotify_data.flags & (flag))
0010 
0011 /*
0012  * Flags allowed to be passed from/to userspace.
0013  *
0014  * We intentionally do not add new bits to the old FAN_ALL_* constants, because
0015  * they are uapi exposed constants. If there are programs out there using
0016  * these constant, the programs may break if re-compiled with new uapi headers
0017  * and then run on an old kernel.
0018  */
0019 
0020 /* Group classes where permission events are allowed */
0021 #define FANOTIFY_PERM_CLASSES   (FAN_CLASS_CONTENT | \
0022                  FAN_CLASS_PRE_CONTENT)
0023 
0024 #define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FANOTIFY_PERM_CLASSES)
0025 
0026 #define FANOTIFY_FID_BITS   (FAN_REPORT_DFID_NAME_TARGET)
0027 
0028 #define FANOTIFY_INFO_MODES (FANOTIFY_FID_BITS | FAN_REPORT_PIDFD)
0029 
0030 /*
0031  * fanotify_init() flags that require CAP_SYS_ADMIN.
0032  * We do not allow unprivileged groups to request permission events.
0033  * We do not allow unprivileged groups to get other process pid in events.
0034  * We do not allow unprivileged groups to use unlimited resources.
0035  */
0036 #define FANOTIFY_ADMIN_INIT_FLAGS   (FANOTIFY_PERM_CLASSES | \
0037                      FAN_REPORT_TID | \
0038                      FAN_REPORT_PIDFD | \
0039                      FAN_UNLIMITED_QUEUE | \
0040                      FAN_UNLIMITED_MARKS)
0041 
0042 /*
0043  * fanotify_init() flags that are allowed for user without CAP_SYS_ADMIN.
0044  * FAN_CLASS_NOTIF is the only class we allow for unprivileged group.
0045  * We do not allow unprivileged groups to get file descriptors in events,
0046  * so one of the flags for reporting file handles is required.
0047  */
0048 #define FANOTIFY_USER_INIT_FLAGS    (FAN_CLASS_NOTIF | \
0049                      FANOTIFY_FID_BITS | \
0050                      FAN_CLOEXEC | FAN_NONBLOCK)
0051 
0052 #define FANOTIFY_INIT_FLAGS (FANOTIFY_ADMIN_INIT_FLAGS | \
0053                  FANOTIFY_USER_INIT_FLAGS)
0054 
0055 /* Internal group flags */
0056 #define FANOTIFY_UNPRIV     0x80000000
0057 #define FANOTIFY_INTERNAL_GROUP_FLAGS   (FANOTIFY_UNPRIV)
0058 
0059 #define FANOTIFY_MARK_TYPE_BITS (FAN_MARK_INODE | FAN_MARK_MOUNT | \
0060                  FAN_MARK_FILESYSTEM)
0061 
0062 #define FANOTIFY_MARK_CMD_BITS  (FAN_MARK_ADD | FAN_MARK_REMOVE | \
0063                  FAN_MARK_FLUSH)
0064 
0065 #define FANOTIFY_MARK_IGNORE_BITS (FAN_MARK_IGNORED_MASK | \
0066                    FAN_MARK_IGNORE)
0067 
0068 #define FANOTIFY_MARK_FLAGS (FANOTIFY_MARK_TYPE_BITS | \
0069                  FANOTIFY_MARK_CMD_BITS | \
0070                  FANOTIFY_MARK_IGNORE_BITS | \
0071                  FAN_MARK_DONT_FOLLOW | \
0072                  FAN_MARK_ONLYDIR | \
0073                  FAN_MARK_IGNORED_SURV_MODIFY | \
0074                  FAN_MARK_EVICTABLE)
0075 
0076 /*
0077  * Events that can be reported with data type FSNOTIFY_EVENT_PATH.
0078  * Note that FAN_MODIFY can also be reported with data type
0079  * FSNOTIFY_EVENT_INODE.
0080  */
0081 #define FANOTIFY_PATH_EVENTS    (FAN_ACCESS | FAN_MODIFY | \
0082                  FAN_CLOSE | FAN_OPEN | FAN_OPEN_EXEC)
0083 
0084 /*
0085  * Directory entry modification events - reported only to directory
0086  * where entry is modified and not to a watching parent.
0087  */
0088 #define FANOTIFY_DIRENT_EVENTS  (FAN_MOVE | FAN_CREATE | FAN_DELETE | \
0089                  FAN_RENAME)
0090 
0091 /* Events that can be reported with event->fd */
0092 #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS)
0093 
0094 /* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */
0095 #define FANOTIFY_INODE_EVENTS   (FANOTIFY_DIRENT_EVENTS | \
0096                  FAN_ATTRIB | FAN_MOVE_SELF | FAN_DELETE_SELF)
0097 
0098 /* Events that can only be reported with data type FSNOTIFY_EVENT_ERROR */
0099 #define FANOTIFY_ERROR_EVENTS   (FAN_FS_ERROR)
0100 
0101 /* Events that user can request to be notified on */
0102 #define FANOTIFY_EVENTS     (FANOTIFY_PATH_EVENTS | \
0103                  FANOTIFY_INODE_EVENTS | \
0104                  FANOTIFY_ERROR_EVENTS)
0105 
0106 /* Events that require a permission response from user */
0107 #define FANOTIFY_PERM_EVENTS    (FAN_OPEN_PERM | FAN_ACCESS_PERM | \
0108                  FAN_OPEN_EXEC_PERM)
0109 
0110 /* Extra flags that may be reported with event or control handling of events */
0111 #define FANOTIFY_EVENT_FLAGS    (FAN_EVENT_ON_CHILD | FAN_ONDIR)
0112 
0113 /* Events that may be reported to user */
0114 #define FANOTIFY_OUTGOING_EVENTS    (FANOTIFY_EVENTS | \
0115                      FANOTIFY_PERM_EVENTS | \
0116                      FAN_Q_OVERFLOW | FAN_ONDIR)
0117 
0118 /* Events and flags relevant only for directories */
0119 #define FANOTIFY_DIRONLY_EVENT_BITS (FANOTIFY_DIRENT_EVENTS | \
0120                      FAN_EVENT_ON_CHILD | FAN_ONDIR)
0121 
0122 #define ALL_FANOTIFY_EVENT_BITS     (FANOTIFY_OUTGOING_EVENTS | \
0123                      FANOTIFY_EVENT_FLAGS)
0124 
0125 /* Do not use these old uapi constants internally */
0126 #undef FAN_ALL_CLASS_BITS
0127 #undef FAN_ALL_INIT_FLAGS
0128 #undef FAN_ALL_MARK_FLAGS
0129 #undef FAN_ALL_EVENTS
0130 #undef FAN_ALL_PERM_EVENTS
0131 #undef FAN_ALL_OUTGOING_EVENTS
0132 
0133 #endif /* _LINUX_FANOTIFY_H */