fanotify: Allow users to request FAN_FS_ERROR events
authorGabriel Krisman Bertazi <krisman@collabora.com>
Mon, 25 Oct 2021 19:27:43 +0000 (16:27 -0300)
committerJan Kara <jack@suse.cz>
Wed, 27 Oct 2021 10:53:45 +0000 (12:53 +0200)
Wire up the FAN_FS_ERROR event in the fanotify_mark syscall, allowing
user space to request the monitoring of FAN_FS_ERROR events.

These events are limited to filesystem marks, so check it is the
case in the syscall handler.

Link: https://lore.kernel.org/r/20211025192746.66445-29-krisman@collabora.com
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/fanotify/fanotify.c
fs/notify/fanotify/fanotify_user.c
include/linux/fanotify.h

index af61425e6e3bf1eb767bb11de0ace668986b781c..b6091775aa6efe3677e9e83e50cc664dfa15a0df 100644 (file)
@@ -822,7 +822,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
        BUILD_BUG_ON(FAN_OPEN_EXEC_PERM != FS_OPEN_EXEC_PERM);
        BUILD_BUG_ON(FAN_FS_ERROR != FS_ERROR);
 
-       BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 19);
+       BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 20);
 
        mask = fanotify_group_event_mask(group, iter_info, mask, data,
                                         data_type, dir);
index fb817028d0b666b4ccb58e839b566ecf0a6b1bee..559bc1e9926d6a4e41bf7265977f4cfffbba8360 100644 (file)
@@ -1520,6 +1520,10 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
            group->priority == FS_PRIO_0)
                goto fput_and_out;
 
+       if (mask & FAN_FS_ERROR &&
+           mark_type != FAN_MARK_FILESYSTEM)
+               goto fput_and_out;
+
        /*
         * Events that do not carry enough information to report
         * event->fd require a group that supports reporting fid.  Those
index 52d464802d99fb11e16e121503fbdec155113b37..616af2ea20f301067faccb5e18f2814750d8b046 100644 (file)
@@ -91,9 +91,13 @@ extern struct ctl_table fanotify_table[]; /* for sysctl */
 #define FANOTIFY_INODE_EVENTS  (FANOTIFY_DIRENT_EVENTS | \
                                 FAN_ATTRIB | FAN_MOVE_SELF | FAN_DELETE_SELF)
 
+/* Events that can only be reported with data type FSNOTIFY_EVENT_ERROR */
+#define FANOTIFY_ERROR_EVENTS  (FAN_FS_ERROR)
+
 /* Events that user can request to be notified on */
 #define FANOTIFY_EVENTS                (FANOTIFY_PATH_EVENTS | \
-                                FANOTIFY_INODE_EVENTS)
+                                FANOTIFY_INODE_EVENTS | \
+                                FANOTIFY_ERROR_EVENTS)
 
 /* Events that require a permission response from user */
 #define FANOTIFY_PERM_EVENTS   (FAN_OPEN_PERM | FAN_ACCESS_PERM | \