]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fsnotify: Do not generate events for O_PATH file descriptors
authorJan Kara <jack@suse.cz>
Mon, 17 Jun 2024 16:23:00 +0000 (18:23 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 18 Jun 2024 14:25:50 +0000 (16:25 +0200)
Currently we will not generate FS_OPEN events for O_PATH file
descriptors but we will generate FS_CLOSE events for them. This is
asymmetry is confusing. Arguably no fsnotify events should be generated
for O_PATH file descriptors as they cannot be used to access or modify
file content, they are just convenient handles to file objects like
paths. So fix the asymmetry by stopping to generate FS_CLOSE for O_PATH
file descriptors.

Cc: <stable@vger.kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240617162303.1596-1-jack@suse.cz
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/fsnotify.h

index 4da80e92f804f931f82e01ec8f8e5b959c76097c..278620e063ab2239f996069458c0adbb97a3c36b 100644 (file)
@@ -112,7 +112,13 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
 {
        const struct path *path;
 
-       if (file->f_mode & FMODE_NONOTIFY)
+       /*
+        * FMODE_NONOTIFY are fds generated by fanotify itself which should not
+        * generate new events. We also don't want to generate events for
+        * FMODE_PATH fds (involves open & close events) as they are just
+        * handle creation / destruction events and not "real" file events.
+        */
+       if (file->f_mode & (FMODE_NONOTIFY | FMODE_PATH))
                return 0;
 
        path = &file->f_path;