at v5.13 3.8 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_FANOTIFY_H 3#define _LINUX_FANOTIFY_H 4 5#include <linux/sysctl.h> 6#include <uapi/linux/fanotify.h> 7 8extern struct ctl_table fanotify_table[]; /* for sysctl */ 9 10#define FAN_GROUP_FLAG(group, flag) \ 11 ((group)->fanotify_data.flags & (flag)) 12 13/* 14 * Flags allowed to be passed from/to userspace. 15 * 16 * We intentionally do not add new bits to the old FAN_ALL_* constants, because 17 * they are uapi exposed constants. If there are programs out there using 18 * these constant, the programs may break if re-compiled with new uapi headers 19 * and then run on an old kernel. 20 */ 21 22/* Group classes where permission events are allowed */ 23#define FANOTIFY_PERM_CLASSES (FAN_CLASS_CONTENT | \ 24 FAN_CLASS_PRE_CONTENT) 25 26#define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FANOTIFY_PERM_CLASSES) 27 28#define FANOTIFY_FID_BITS (FAN_REPORT_FID | FAN_REPORT_DFID_NAME) 29 30/* 31 * fanotify_init() flags that require CAP_SYS_ADMIN. 32 * We do not allow unprivileged groups to request permission events. 33 * We do not allow unprivileged groups to get other process pid in events. 34 * We do not allow unprivileged groups to use unlimited resources. 35 */ 36#define FANOTIFY_ADMIN_INIT_FLAGS (FANOTIFY_PERM_CLASSES | \ 37 FAN_REPORT_TID | \ 38 FAN_UNLIMITED_QUEUE | \ 39 FAN_UNLIMITED_MARKS) 40 41/* 42 * fanotify_init() flags that are allowed for user without CAP_SYS_ADMIN. 43 * FAN_CLASS_NOTIF is the only class we allow for unprivileged group. 44 * We do not allow unprivileged groups to get file descriptors in events, 45 * so one of the flags for reporting file handles is required. 46 */ 47#define FANOTIFY_USER_INIT_FLAGS (FAN_CLASS_NOTIF | \ 48 FANOTIFY_FID_BITS | \ 49 FAN_CLOEXEC | FAN_NONBLOCK) 50 51#define FANOTIFY_INIT_FLAGS (FANOTIFY_ADMIN_INIT_FLAGS | \ 52 FANOTIFY_USER_INIT_FLAGS) 53 54/* Internal group flags */ 55#define FANOTIFY_UNPRIV 0x80000000 56#define FANOTIFY_INTERNAL_GROUP_FLAGS (FANOTIFY_UNPRIV) 57 58#define FANOTIFY_MARK_TYPE_BITS (FAN_MARK_INODE | FAN_MARK_MOUNT | \ 59 FAN_MARK_FILESYSTEM) 60 61#define FANOTIFY_MARK_FLAGS (FANOTIFY_MARK_TYPE_BITS | \ 62 FAN_MARK_ADD | \ 63 FAN_MARK_REMOVE | \ 64 FAN_MARK_DONT_FOLLOW | \ 65 FAN_MARK_ONLYDIR | \ 66 FAN_MARK_IGNORED_MASK | \ 67 FAN_MARK_IGNORED_SURV_MODIFY | \ 68 FAN_MARK_FLUSH) 69 70/* 71 * Events that can be reported with data type FSNOTIFY_EVENT_PATH. 72 * Note that FAN_MODIFY can also be reported with data type 73 * FSNOTIFY_EVENT_INODE. 74 */ 75#define FANOTIFY_PATH_EVENTS (FAN_ACCESS | FAN_MODIFY | \ 76 FAN_CLOSE | FAN_OPEN | FAN_OPEN_EXEC) 77 78/* 79 * Directory entry modification events - reported only to directory 80 * where entry is modified and not to a watching parent. 81 */ 82#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE) 83 84/* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */ 85#define FANOTIFY_INODE_EVENTS (FANOTIFY_DIRENT_EVENTS | \ 86 FAN_ATTRIB | FAN_MOVE_SELF | FAN_DELETE_SELF) 87 88/* Events that user can request to be notified on */ 89#define FANOTIFY_EVENTS (FANOTIFY_PATH_EVENTS | \ 90 FANOTIFY_INODE_EVENTS) 91 92/* Events that require a permission response from user */ 93#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ 94 FAN_OPEN_EXEC_PERM) 95 96/* Extra flags that may be reported with event or control handling of events */ 97#define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) 98 99/* Events that may be reported to user */ 100#define FANOTIFY_OUTGOING_EVENTS (FANOTIFY_EVENTS | \ 101 FANOTIFY_PERM_EVENTS | \ 102 FAN_Q_OVERFLOW | FAN_ONDIR) 103 104#define ALL_FANOTIFY_EVENT_BITS (FANOTIFY_OUTGOING_EVENTS | \ 105 FANOTIFY_EVENT_FLAGS) 106 107/* Do not use these old uapi constants internally */ 108#undef FAN_ALL_CLASS_BITS 109#undef FAN_ALL_INIT_FLAGS 110#undef FAN_ALL_MARK_FLAGS 111#undef FAN_ALL_EVENTS 112#undef FAN_ALL_PERM_EVENTS 113#undef FAN_ALL_OUTGOING_EVENTS 114 115#endif /* _LINUX_FANOTIFY_H */