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