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

ovl: enable fsnotify events on underlying real files

Overlayfs creates the real underlying files with fake f_path, whose
f_inode is on the underlying fs and f_path on overlayfs.

Those real files were open with FMODE_NONOTIFY, because fsnotify code was
not prapared to handle fsnotify hooks on files with fake path correctly
and fanotify would report unexpected event->fd with fake overlayfs path,
when the underlying fs was being watched.

Teach fsnotify to handle events on the real files, and do not set real
files to FMODE_NONOTIFY to allow operations on real file (e.g. open,
access, modify, close) to generate async and permission events.

Because fsnotify does not have notifications on address space
operations, we do not need to worry about ->vm_file not reporting
events to a watched overlayfs when users are accessing a mapped
overlayfs file.

Acked-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Message-Id: <20230615112229.2143178-6-amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Amir Goldstein and committed by
Christian Brauner
bc2473c9 62d53c4a

+5 -3
+2 -2
fs/overlayfs/file.c
··· 34 34 return 'm'; 35 35 } 36 36 37 - /* No atime modification nor notify on underlying */ 38 - #define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY) 37 + /* No atime modification on underlying */ 38 + #define OVL_OPEN_FLAGS (O_NOATIME) 39 39 40 40 static struct file *ovl_open_realfile(const struct file *file, 41 41 const struct path *realpath)
+3 -1
include/linux/fsnotify.h
··· 91 91 92 92 static inline int fsnotify_file(struct file *file, __u32 mask) 93 93 { 94 - const struct path *path = &file->f_path; 94 + const struct path *path; 95 95 96 96 if (file->f_mode & FMODE_NONOTIFY) 97 97 return 0; 98 98 99 + /* Overlayfs internal files have fake f_path */ 100 + path = file_real_path(file); 99 101 return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); 100 102 } 101 103