fanotify.h 4.4 KB

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