Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fsnotify: Do not generate events for O_PATH file descriptors

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>

authored by

Jan Kara and committed by
Christian Brauner
702eb71f 2ae4db56

+7 -1
+7 -1
include/linux/fsnotify.h
··· 112 112 { 113 113 const struct path *path; 114 114 115 - if (file->f_mode & FMODE_NONOTIFY) 115 + /* 116 + * FMODE_NONOTIFY are fds generated by fanotify itself which should not 117 + * generate new events. We also don't want to generate events for 118 + * FMODE_PATH fds (involves open & close events) as they are just 119 + * handle creation / destruction events and not "real" file events. 120 + */ 121 + if (file->f_mode & (FMODE_NONOTIFY | FMODE_PATH)) 116 122 return 0; 117 123 118 124 path = &file->f_path;