Skip to content

Commit bc2473c

Browse files
amir73ilbrauner
authored andcommitted
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 <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 62d53c4 commit bc2473c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/overlayfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode)
3434
return 'm';
3535
}
3636

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)
3939

4040
static struct file *ovl_open_realfile(const struct file *file,
4141
const struct path *realpath)

include/linux/fsnotify.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
9191

9292
static inline int fsnotify_file(struct file *file, __u32 mask)
9393
{
94-
const struct path *path = &file->f_path;
94+
const struct path *path;
9595

9696
if (file->f_mode & FMODE_NONOTIFY)
9797
return 0;
9898

99+
/* Overlayfs internal files have fake f_path */
100+
path = file_real_path(file);
99101
return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
100102
}
101103

0 commit comments

Comments
 (0)