diff mbox series

[D,SRU,1/1] ovl: do not generate duplicate fsnotify events for "fake" path

Message ID 20190617110425.27689-2-po-hsu.lin@canonical.com
State New
Headers show
Series [D,SRU,1/1] ovl: do not generate duplicate fsnotify events for "fake" path | expand

Commit Message

Po-Hsu Lin June 17, 2019, 11:04 a.m. UTC
From: Amir Goldstein <amir73il@gmail.com>

BugLink: https://bugs.launchpad.net/bugs/1833028

Overlayfs "fake" path is used for stacked file operations on underlying
files.  Operations on files with "fake" path must not generate fsnotify
events with path data, because those events have already been generated at
overlayfs layer and because the reported event->fd for fanotify marks on
underlying inode/filesystem will have the wrong path (the overlayfs path).

Link: https://lore.kernel.org/linux-fsdevel/20190423065024.12695-1-jencce.kernel@gmail.com/
Reported-by: Murphy Zhou <jencce.kernel@gmail.com>
Fixes: d1d04ef8572b ("ovl: stack file ops")
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
(cherry picked from commit d989903058a83e8536cc7aadf9256a47d5c173fe)
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 fs/overlayfs/file.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Connor Kuehl June 26, 2019, 5:47 p.m. UTC | #1
On 6/17/19 4:04 AM, Po-Hsu Lin wrote:
> From: Amir Goldstein <amir73il@gmail.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1833028
> 
> Overlayfs "fake" path is used for stacked file operations on underlying
> files.  Operations on files with "fake" path must not generate fsnotify
> events with path data, because those events have already been generated at
> overlayfs layer and because the reported event->fd for fanotify marks on
> underlying inode/filesystem will have the wrong path (the overlayfs path).
> 
> Link: https://lore.kernel.org/linux-fsdevel/20190423065024.12695-1-jencce.kernel@gmail.com/
> Reported-by: Murphy Zhou <jencce.kernel@gmail.com>
> Fixes: d1d04ef8572b ("ovl: stack file ops")
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> (cherry picked from commit d989903058a83e8536cc7aadf9256a47d5c173fe)
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>

Acked-by: Connor Kuehl <connor.kuehl@canonical.com>

> ---
>  fs/overlayfs/file.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 84dd957..6f6eb63 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -29,10 +29,11 @@ static struct file *ovl_open_realfile(const struct file *file,
>  	struct inode *inode = file_inode(file);
>  	struct file *realfile;
>  	const struct cred *old_cred;
> +	int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;
>  
>  	old_cred = ovl_override_creds(inode->i_sb);
> -	realfile = open_with_fake_path(&file->f_path, file->f_flags | O_NOATIME,
> -				       realinode, current_cred());
> +	realfile = open_with_fake_path(&file->f_path, flags, realinode,
> +				       current_cred());
>  	revert_creds(old_cred);
>  
>  	pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
> @@ -50,7 +51,7 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
>  	int err;
>  
>  	/* No atime modificaton on underlying */
> -	flags |= O_NOATIME;
> +	flags |= O_NOATIME | FMODE_NONOTIFY;
>  
>  	/* If some flag changed that cannot be changed then something's amiss */
>  	if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))
>
Stefan Bader June 28, 2019, 3:34 p.m. UTC | #2
On 17.06.19 13:04, Po-Hsu Lin wrote:
> From: Amir Goldstein <amir73il@gmail.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1833028
> 
> Overlayfs "fake" path is used for stacked file operations on underlying
> files.  Operations on files with "fake" path must not generate fsnotify
> events with path data, because those events have already been generated at
> overlayfs layer and because the reported event->fd for fanotify marks on
> underlying inode/filesystem will have the wrong path (the overlayfs path).
> 
> Link: https://lore.kernel.org/linux-fsdevel/20190423065024.12695-1-jencce.kernel@gmail.com/
> Reported-by: Murphy Zhou <jencce.kernel@gmail.com>
> Fixes: d1d04ef8572b ("ovl: stack file ops")
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> (cherry picked from commit d989903058a83e8536cc7aadf9256a47d5c173fe)
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  fs/overlayfs/file.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 84dd957..6f6eb63 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -29,10 +29,11 @@ static struct file *ovl_open_realfile(const struct file *file,
>  	struct inode *inode = file_inode(file);
>  	struct file *realfile;
>  	const struct cred *old_cred;
> +	int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;
>  
>  	old_cred = ovl_override_creds(inode->i_sb);
> -	realfile = open_with_fake_path(&file->f_path, file->f_flags | O_NOATIME,
> -				       realinode, current_cred());
> +	realfile = open_with_fake_path(&file->f_path, flags, realinode,
> +				       current_cred());
>  	revert_creds(old_cred);
>  
>  	pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
> @@ -50,7 +51,7 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
>  	int err;
>  
>  	/* No atime modificaton on underlying */
> -	flags |= O_NOATIME;
> +	flags |= O_NOATIME | FMODE_NONOTIFY;
>  
>  	/* If some flag changed that cannot be changed then something's amiss */
>  	if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))
>
diff mbox series

Patch

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 84dd957..6f6eb63 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -29,10 +29,11 @@  static struct file *ovl_open_realfile(const struct file *file,
 	struct inode *inode = file_inode(file);
 	struct file *realfile;
 	const struct cred *old_cred;
+	int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;
 
 	old_cred = ovl_override_creds(inode->i_sb);
-	realfile = open_with_fake_path(&file->f_path, file->f_flags | O_NOATIME,
-				       realinode, current_cred());
+	realfile = open_with_fake_path(&file->f_path, flags, realinode,
+				       current_cred());
 	revert_creds(old_cred);
 
 	pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
@@ -50,7 +51,7 @@  static int ovl_change_flags(struct file *file, unsigned int flags)
 	int err;
 
 	/* No atime modificaton on underlying */
-	flags |= O_NOATIME;
+	flags |= O_NOATIME | FMODE_NONOTIFY;
 
 	/* If some flag changed that cannot be changed then something's amiss */
 	if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))