linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org
Subject: [PATCH v2 3/3] ovl: enable fsnotify events on underlying real files
Date: Sun, 11 Jun 2023 16:27:32 +0300	[thread overview]
Message-ID: <20230611132732.1502040-4-amir73il@gmail.com> (raw)
In-Reply-To: <20230611132732.1502040-1-amir73il@gmail.com>

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 | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 39737c2aaa84..61b5faa2b10f 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..f4f5db765ec2 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -91,12 +91,14 @@ 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;
+	struct path path;
 
 	if (file->f_mode & FMODE_NONOTIFY)
 		return 0;
 
-	return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
+	/* Overlayfs internal files have fake f_path */
+	path = f_real_path(file);
+	return fsnotify_parent(path.dentry, mask, &path, FSNOTIFY_EVENT_PATH);
 }
 
 /* Simple call site for access decisions */
-- 
2.34.1


  parent reply	other threads:[~2023-06-11 13:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-11 13:27 [PATCH v2 0/3] Handle notifications on overlayfs fake path files Amir Goldstein
2023-06-11 13:27 ` [PATCH v2 1/3] fs: rename FMODE_NOACCOUNT to FMODE_INTERNAL Amir Goldstein
2023-06-12  4:27   ` Christoph Hellwig
2023-06-12  6:08     ` Amir Goldstein
2023-06-12  6:11       ` Christoph Hellwig
2023-06-12  6:15         ` Christoph Hellwig
2023-06-12  6:32         ` Amir Goldstein
2023-06-12  6:35           ` Christoph Hellwig
2023-06-11 13:27 ` [PATCH v2 2/3] fs: introduce f_real_path() helper Amir Goldstein
2023-06-12  4:36   ` Christoph Hellwig
2023-06-12  6:28     ` Amir Goldstein
2023-06-12  6:36       ` Christoph Hellwig
2023-06-12  8:13         ` Amir Goldstein
2023-06-11 13:27 ` Amir Goldstein [this message]
2023-06-11 14:23 ` [PATCH v2 0/3] Handle notifications on overlayfs fake path files Miklos Szeredi
2023-06-11 16:55   ` Amir Goldstein
2023-06-11 17:52     ` Amir Goldstein
2023-06-11 19:12       ` Miklos Szeredi
2023-06-11 19:25         ` Amir Goldstein
2023-06-11 19:37           ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230611132732.1502040-4-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).