Skip to content

Commit 59e914c

Browse files
jankaragregkh
authored andcommitted
fsnotify: Do not generate events for O_PATH file descriptors
commit 702eb71 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0ba4829 commit 59e914c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

include/linux/fsnotify.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
9999
{
100100
const struct path *path;
101101

102-
if (file->f_mode & FMODE_NONOTIFY)
102+
/*
103+
* FMODE_NONOTIFY are fds generated by fanotify itself which should not
104+
* generate new events. We also don't want to generate events for
105+
* FMODE_PATH fds (involves open & close events) as they are just
106+
* handle creation / destruction events and not "real" file events.
107+
*/
108+
if (file->f_mode & (FMODE_NONOTIFY | FMODE_PATH))
103109
return 0;
104110

105111
path = &file->f_path;

0 commit comments

Comments
 (0)