Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cfcb650 authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman
Browse files

fsnotify: Do not generate events for O_PATH file descriptors



commit 702eb71fd6501b3566283f8c96d7ccc6ddd662e9 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: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240617162303.1596-1-jack@suse.cz


Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6ac69187
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,13 @@ static inline int fsnotify_perm(struct file *file, int mask)
	struct inode *inode = file_inode(file);
	struct inode *inode = file_inode(file);
	__u32 fsnotify_mask = 0;
	__u32 fsnotify_mask = 0;


	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;
		return 0;
	if (!(mask & (MAY_READ | MAY_OPEN)))
	if (!(mask & (MAY_READ | MAY_OPEN)))
		return 0;
		return 0;