xref: /linux-6.15/include/linux/fanotify.h (revision 0f46d81f)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2ff0b16a9SEric Paris #ifndef _LINUX_FANOTIFY_H
3ff0b16a9SEric Paris #define _LINUX_FANOTIFY_H
4ff0b16a9SEric Paris 
55b8fea65SAmir Goldstein #include <linux/sysctl.h>
6607ca46eSDavid Howells #include <uapi/linux/fanotify.h>
7ff0b16a9SEric Paris 
896a71f21SAmir Goldstein #define FAN_GROUP_FLAG(group, flag) \
996a71f21SAmir Goldstein 	((group)->fanotify_data.flags & (flag))
1096a71f21SAmir Goldstein 
1123c9deebSAmir Goldstein /*
1223c9deebSAmir Goldstein  * Flags allowed to be passed from/to userspace.
1323c9deebSAmir Goldstein  *
1423c9deebSAmir Goldstein  * We intentionally do not add new bits to the old FAN_ALL_* constants, because
1523c9deebSAmir Goldstein  * they are uapi exposed constants. If there are programs out there using
1623c9deebSAmir Goldstein  * these constant, the programs may break if re-compiled with new uapi headers
1723c9deebSAmir Goldstein  * and then run on an old kernel.
1823c9deebSAmir Goldstein  */
197cea2a3cSAmir Goldstein 
207cea2a3cSAmir Goldstein /* Group classes where permission events are allowed */
217cea2a3cSAmir Goldstein #define FANOTIFY_PERM_CLASSES	(FAN_CLASS_CONTENT | \
2223c9deebSAmir Goldstein 				 FAN_CLASS_PRE_CONTENT)
2323c9deebSAmir Goldstein 
247cea2a3cSAmir Goldstein #define FANOTIFY_CLASS_BITS	(FAN_CLASS_NOTIF | FANOTIFY_PERM_CLASSES)
257cea2a3cSAmir Goldstein 
26d61fd650SAmir Goldstein #define FANOTIFY_FID_BITS	(FAN_REPORT_DFID_NAME_TARGET)
27d809daf1SAmir Goldstein 
28*0f46d81fSMiklos Szeredi #define FANOTIFY_INFO_MODES	(FANOTIFY_FID_BITS | FAN_REPORT_PIDFD | FAN_REPORT_MNT)
290aca67bbSMatthew Bobrowski 
307cea2a3cSAmir Goldstein /*
317cea2a3cSAmir Goldstein  * fanotify_init() flags that require CAP_SYS_ADMIN.
327cea2a3cSAmir Goldstein  * We do not allow unprivileged groups to request permission events.
337cea2a3cSAmir Goldstein  * We do not allow unprivileged groups to get other process pid in events.
347cea2a3cSAmir Goldstein  * We do not allow unprivileged groups to use unlimited resources.
357cea2a3cSAmir Goldstein  */
367cea2a3cSAmir Goldstein #define FANOTIFY_ADMIN_INIT_FLAGS	(FANOTIFY_PERM_CLASSES | \
37d809daf1SAmir Goldstein 					 FAN_REPORT_TID | \
38af579bebSMatthew Bobrowski 					 FAN_REPORT_PIDFD | \
39522249f0SAmir Goldstein 					 FAN_REPORT_FD_ERROR | \
407cea2a3cSAmir Goldstein 					 FAN_UNLIMITED_QUEUE | \
41*0f46d81fSMiklos Szeredi 					 FAN_UNLIMITED_MARKS | \
42*0f46d81fSMiklos Szeredi 					 FAN_REPORT_MNT)
437cea2a3cSAmir Goldstein 
447cea2a3cSAmir Goldstein /*
457cea2a3cSAmir Goldstein  * fanotify_init() flags that are allowed for user without CAP_SYS_ADMIN.
467cea2a3cSAmir Goldstein  * FAN_CLASS_NOTIF is the only class we allow for unprivileged group.
477cea2a3cSAmir Goldstein  * We do not allow unprivileged groups to get file descriptors in events,
487cea2a3cSAmir Goldstein  * so one of the flags for reporting file handles is required.
497cea2a3cSAmir Goldstein  */
507cea2a3cSAmir Goldstein #define FANOTIFY_USER_INIT_FLAGS	(FAN_CLASS_NOTIF | \
517cea2a3cSAmir Goldstein 					 FANOTIFY_FID_BITS | \
527cea2a3cSAmir Goldstein 					 FAN_CLOEXEC | FAN_NONBLOCK)
537cea2a3cSAmir Goldstein 
547cea2a3cSAmir Goldstein #define FANOTIFY_INIT_FLAGS	(FANOTIFY_ADMIN_INIT_FLAGS | \
557cea2a3cSAmir Goldstein 				 FANOTIFY_USER_INIT_FLAGS)
5623c9deebSAmir Goldstein 
57a8b98c80SAmir Goldstein /* Internal group flags */
58a8b98c80SAmir Goldstein #define FANOTIFY_UNPRIV		0x80000000
59a8b98c80SAmir Goldstein #define FANOTIFY_INTERNAL_GROUP_FLAGS	(FANOTIFY_UNPRIV)
60a8b98c80SAmir Goldstein 
6123c9deebSAmir Goldstein #define FANOTIFY_MARK_TYPE_BITS	(FAN_MARK_INODE | FAN_MARK_MOUNT | \
62*0f46d81fSMiklos Szeredi 				 FAN_MARK_FILESYSTEM | FAN_MARK_MNTNS)
6323c9deebSAmir Goldstein 
648afd7215SAmir Goldstein #define FANOTIFY_MARK_CMD_BITS	(FAN_MARK_ADD | FAN_MARK_REMOVE | \
658afd7215SAmir Goldstein 				 FAN_MARK_FLUSH)
668afd7215SAmir Goldstein 
67e252f2edSAmir Goldstein #define FANOTIFY_MARK_IGNORE_BITS (FAN_MARK_IGNORED_MASK | \
68e252f2edSAmir Goldstein 				   FAN_MARK_IGNORE)
69e252f2edSAmir Goldstein 
7023c9deebSAmir Goldstein #define FANOTIFY_MARK_FLAGS	(FANOTIFY_MARK_TYPE_BITS | \
718afd7215SAmir Goldstein 				 FANOTIFY_MARK_CMD_BITS | \
72e252f2edSAmir Goldstein 				 FANOTIFY_MARK_IGNORE_BITS | \
7323c9deebSAmir Goldstein 				 FAN_MARK_DONT_FOLLOW | \
7423c9deebSAmir Goldstein 				 FAN_MARK_ONLYDIR | \
7523c9deebSAmir Goldstein 				 FAN_MARK_IGNORED_SURV_MODIFY | \
768afd7215SAmir Goldstein 				 FAN_MARK_EVICTABLE)
7723c9deebSAmir Goldstein 
78235328d1SAmir Goldstein /*
79235328d1SAmir Goldstein  * Events that can be reported with data type FSNOTIFY_EVENT_PATH.
80235328d1SAmir Goldstein  * Note that FAN_MODIFY can also be reported with data type
81235328d1SAmir Goldstein  * FSNOTIFY_EVENT_INODE.
82235328d1SAmir Goldstein  */
83235328d1SAmir Goldstein #define FANOTIFY_PATH_EVENTS	(FAN_ACCESS | FAN_MODIFY | \
849b076f1cSMatthew Bobrowski 				 FAN_CLOSE | FAN_OPEN | FAN_OPEN_EXEC)
8523c9deebSAmir Goldstein 
86235328d1SAmir Goldstein /*
87235328d1SAmir Goldstein  * Directory entry modification events - reported only to directory
88235328d1SAmir Goldstein  * where entry is modified and not to a watching parent.
89235328d1SAmir Goldstein  */
908cc3b1ccSAmir Goldstein #define FANOTIFY_DIRENT_EVENTS	(FAN_MOVE | FAN_CREATE | FAN_DELETE | \
918cc3b1ccSAmir Goldstein 				 FAN_RENAME)
92235328d1SAmir Goldstein 
934f8afa33SAmir Goldstein /* Content events can be used to inspect file content */
944f8afa33SAmir Goldstein #define FANOTIFY_CONTENT_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \
954f8afa33SAmir Goldstein 				      FAN_ACCESS_PERM)
964f8afa33SAmir Goldstein /* Pre-content events can be used to fill file content */
974f8afa33SAmir Goldstein #define FANOTIFY_PRE_CONTENT_EVENTS  (FAN_PRE_ACCESS)
984f8afa33SAmir Goldstein 
994f8afa33SAmir Goldstein /* Events that require a permission response from user */
1004f8afa33SAmir Goldstein #define FANOTIFY_PERM_EVENTS	(FANOTIFY_CONTENT_PERM_EVENTS | \
1014f8afa33SAmir Goldstein 				 FANOTIFY_PRE_CONTENT_EVENTS)
1024f8afa33SAmir Goldstein 
1034fe595cfSGabriel Krisman Bertazi /* Events that can be reported with event->fd */
1044fe595cfSGabriel Krisman Bertazi #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS)
1054fe595cfSGabriel Krisman Bertazi 
106235328d1SAmir Goldstein /* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */
107235328d1SAmir Goldstein #define FANOTIFY_INODE_EVENTS	(FANOTIFY_DIRENT_EVENTS | \
108235328d1SAmir Goldstein 				 FAN_ATTRIB | FAN_MOVE_SELF | FAN_DELETE_SELF)
109235328d1SAmir Goldstein 
1109709bd54SGabriel Krisman Bertazi /* Events that can only be reported with data type FSNOTIFY_EVENT_ERROR */
1119709bd54SGabriel Krisman Bertazi #define FANOTIFY_ERROR_EVENTS	(FAN_FS_ERROR)
1129709bd54SGabriel Krisman Bertazi 
113*0f46d81fSMiklos Szeredi #define FANOTIFY_MOUNT_EVENTS	(FAN_MNT_ATTACH | FAN_MNT_DETACH)
114*0f46d81fSMiklos Szeredi 
115235328d1SAmir Goldstein /* Events that user can request to be notified on */
116235328d1SAmir Goldstein #define FANOTIFY_EVENTS		(FANOTIFY_PATH_EVENTS | \
1179709bd54SGabriel Krisman Bertazi 				 FANOTIFY_INODE_EVENTS | \
118*0f46d81fSMiklos Szeredi 				 FANOTIFY_ERROR_EVENTS | \
119*0f46d81fSMiklos Szeredi 				 FANOTIFY_MOUNT_EVENTS)
120235328d1SAmir Goldstein 
121bdd5a46fSAmir Goldstein /* Extra flags that may be reported with event or control handling of events */
122bdd5a46fSAmir Goldstein #define FANOTIFY_EVENT_FLAGS	(FAN_EVENT_ON_CHILD | FAN_ONDIR)
123bdd5a46fSAmir Goldstein 
12423c9deebSAmir Goldstein /* Events that may be reported to user */
12523c9deebSAmir Goldstein #define FANOTIFY_OUTGOING_EVENTS	(FANOTIFY_EVENTS | \
12623c9deebSAmir Goldstein 					 FANOTIFY_PERM_EVENTS | \
127e7fce6d9SAmir Goldstein 					 FAN_Q_OVERFLOW | FAN_ONDIR)
12823c9deebSAmir Goldstein 
1298698e3baSAmir Goldstein /* Events and flags relevant only for directories */
1308698e3baSAmir Goldstein #define FANOTIFY_DIRONLY_EVENT_BITS	(FANOTIFY_DIRENT_EVENTS | \
1318698e3baSAmir Goldstein 					 FAN_EVENT_ON_CHILD | FAN_ONDIR)
1328698e3baSAmir Goldstein 
133bdd5a46fSAmir Goldstein #define ALL_FANOTIFY_EVENT_BITS		(FANOTIFY_OUTGOING_EVENTS | \
134bdd5a46fSAmir Goldstein 					 FANOTIFY_EVENT_FLAGS)
135bdd5a46fSAmir Goldstein 
13670529a19SRichard Guy Briggs /* These masks check for invalid bits in permission responses. */
13770529a19SRichard Guy Briggs #define FANOTIFY_RESPONSE_ACCESS (FAN_ALLOW | FAN_DENY)
13870529a19SRichard Guy Briggs #define FANOTIFY_RESPONSE_FLAGS (FAN_AUDIT | FAN_INFO)
139b4b2ff4fSAmir Goldstein #define FANOTIFY_RESPONSE_VALID_MASK \
140b4b2ff4fSAmir Goldstein 	(FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS | \
141b4b2ff4fSAmir Goldstein 	 (FAN_ERRNO_MASK << FAN_ERRNO_SHIFT))
14270529a19SRichard Guy Briggs 
14323c9deebSAmir Goldstein /* Do not use these old uapi constants internally */
14423c9deebSAmir Goldstein #undef FAN_ALL_CLASS_BITS
14523c9deebSAmir Goldstein #undef FAN_ALL_INIT_FLAGS
14623c9deebSAmir Goldstein #undef FAN_ALL_MARK_FLAGS
14723c9deebSAmir Goldstein #undef FAN_ALL_EVENTS
14823c9deebSAmir Goldstein #undef FAN_ALL_PERM_EVENTS
14923c9deebSAmir Goldstein #undef FAN_ALL_OUTGOING_EVENTS
15023c9deebSAmir Goldstein 
151ff0b16a9SEric Paris #endif /* _LINUX_FANOTIFY_H */
152