diff mbox series

[v4,2/2] ovl: enable fsnotify events on underlying real files

Message ID 20230614074907.1943007-3-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Handle notifications on overlayfs fake path files | expand

Commit Message

Amir Goldstein June 14, 2023, 7:49 a.m. UTC
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.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/file.c      | 4 ++--
 include/linux/fsnotify.h | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Jan Kara June 14, 2023, 9:54 a.m. UTC | #1
On Wed 14-06-23 10:49:07, Amir Goldstein wrote:
> 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.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Looks good to me. Feel free to add:

Acked-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/overlayfs/file.c      | 4 ++--
>  include/linux/fsnotify.h | 3 ++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 8cf099aa97de..1fdfc53f1207 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -34,8 +34,8 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode)
>  		return 'm';
>  }
>  
> -/* No atime modification nor notify on underlying */
> -#define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
> +/* No atime modification on underlying */
> +#define OVL_OPEN_FLAGS (O_NOATIME)
>  
>  static struct file *ovl_open_realfile(const struct file *file,
>  				      const struct path *realpath)
> diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
> index bb8467cd11ae..6f6cbc2dc49b 100644
> --- a/include/linux/fsnotify.h
> +++ b/include/linux/fsnotify.h
> @@ -91,7 +91,8 @@ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
>  
>  static inline int fsnotify_file(struct file *file, __u32 mask)
>  {
> -	const struct path *path = &file->f_path;
> +	/* Overlayfs internal files have fake f_path */
> +	const struct path *path = f_real_path(file);
>  
>  	if (file->f_mode & FMODE_NONOTIFY)
>  		return 0;
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 8cf099aa97de..1fdfc53f1207 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -34,8 +34,8 @@  static char ovl_whatisit(struct inode *inode, struct inode *realinode)
 		return 'm';
 }
 
-/* No atime modification nor notify on underlying */
-#define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
+/* No atime modification on underlying */
+#define OVL_OPEN_FLAGS (O_NOATIME)
 
 static struct file *ovl_open_realfile(const struct file *file,
 				      const struct path *realpath)
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index bb8467cd11ae..6f6cbc2dc49b 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -91,7 +91,8 @@  static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
 
 static inline int fsnotify_file(struct file *file, __u32 mask)
 {
-	const struct path *path = &file->f_path;
+	/* Overlayfs internal files have fake f_path */
+	const struct path *path = f_real_path(file);
 
 	if (file->f_mode & FMODE_NONOTIFY)
 		return 0;