FAILED: patch "[PATCH] ovl: inherit FMODE_NONOTIFY when opening directory realfiles" failed to apply to 5.15-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 323899b4ed233d5b6e2fc160c16fbf39cf0317da
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 323899b4ed233d5b6e2fc160c16fbf39cf0317da Mon Sep 17 00:00:00 2001
From: Amir Goldstein <[email protected]>
Date: Fri, 30 Oct 2026 18:07:02 +0100
Subject: [PATCH] ovl: inherit FMODE_NONOTIFY when opening directory realfiles
When fanotify hands a listener an fd for a permission event on an overlay directory, ovl_dir_open_realfile() opens the real directory via dentry_open(), not backing_file_open(), so the lower open could still raise FS_OPEN_PERM and deadlock a listener that also marks the backing filesystem.
Export dentry_open_nonotify() and call it from ovl_path_open_realfile() when the overlay user file must not generate events. Ordinary ovl_path_open() callers are unchanged.
--- fs/open.c | 1 + fs/overlayfs/overlayfs.h | 9 ++++++++- fs/overlayfs/readdir.c | 3 ++- fs/overlayfs/util.c | 11 ++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-)
fs/open.c +1 -0
@@ -1172,6 +1172,7 @@ struct file *dentry_open_nonotify(const struct path *path, int flags, }return f; } +EXPORT_SYMBOL_GPL (dentry_open_nonotify);/** * kernel_file_open - open a file for kernel internal use
fs/overlayfs/overlayfs.h +8 -1
@@ -531,7 +531,14 @@ void ovl_dir_modified(struct dentry *dentry, bool impurity);u64 ovl_inode_version_get (struct inode *inode);bool ovl_is_whiteout (struct dentry *dentry);bool ovl_path_is_whiteout (struct ovl_fs *ofs,const struct path *path); -struct file *ovl_path_open (const struct path *path,int flags); +struct file *ovl_path_open_realfile (const struct file *user_file, +const struct path *path,int flags); + +static inline struct file *ovl_path_open (const struct path *path,int flags) +{ +return ovl_path_open_realfile (NULL , path, flags); +} +int ovl_copy_up_start (struct dentry *dentry,int flags);void ovl_copy_up_end (struct dentry *dentry);bool ovl_already_copied_up (struct dentry *dentry,int flags);
fs/overlayfs/readdir.c +2 -1
@@ -994,7 +994,8 @@ static struct file *ovl_dir_open_realfile(const struct file *file, const struct path *realpath) { with_ovl_creds(file_inode(file)->i_sb) -return ovl_path_open (realpath,O_RDONLY | (file->f_flags &O_LARGEFILE )); +return ovl_path_open_realfile (file, realpath, +O_RDONLY | (file->f_flags &O_LARGEFILE )); }/*
fs/overlayfs/util.c +10 -1
@@ -654,7 +654,8 @@ bool ovl_path_is_whiteout(struct ovl_fs *ofs, const struct path *path)ovl_path_check_xwhiteout_xattr (ofs, path); } -struct file *ovl_path_open (const struct path *path,int flags) +struct file *ovl_path_open_realfile (const struct file *user_file, +const struct path *path,int flags) {struct inode *inode =d_inode (path->dentry);const struct mnt_idmap *real_idmap =mnt_idmap (path->mnt);
@@ -682,6 +683,14 @@ struct file *ovl_path_open(const struct path *path, int flags)if (inode_owner_or_capable (real_idmap, inode)) flags |=O_NOATIME ; +/* +* Directory opens use dentry_open() here, not backing_file_open(). +* Inherit FMODE_NONOTIFY from a fanotify permission fd so a listener +* that also watches the real filesystem does not deadlock. +*/ +if (user_file &&FMODE_FSNOTIFY_NONE (user_file->f_mode)) +return dentry_open_nonotify (path, flags,current_cred ()); +return dentry_open (path, flags,current_cred ()); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ovl: inherit FMODE_NONOTIFY when opening directory realfiles
From: Amir Goldstein <[email protected]>
[ Upstream commit 323899b4ed233d5b6e2fc160c16fbf39cf0317da ]
When fanotify hands a listener an fd for a permission event on an overlay directory, ovl_dir_open_realfile() opens the real directory via dentry_open(), not backing_file_open(), so the lower open could still raise FS_OPEN_PERM and deadlock a listener that also marks the backing filesystem.
Export dentry_open_nonotify() and call it from ovl_path_open_realfile() when the overlay user file must not generate events. Ordinary ovl_path_open() callers are unchanged.
--- fs/overlayfs/readdir.c | 10 +++++++++- fs/overlayfs/util.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
fs/overlayfs/readdir.c +9 -1
@@ -850,9 +850,17 @@ static struct file *ovl_dir_open_realfile(const struct file *file, {struct file *res;const struct cred *old_cred; +int flags =O_RDONLY | (file->f_flags &O_LARGEFILE ); + +/* +* Inherit FMODE_NONOTIFY from a fanotify permission fd so a listener +* that also watches the real filesystem does not deadlock. +*/ +if (file->f_mode &FMODE_NONOTIFY ) + flags |= __FMODE_NONOTIFY; old_cred =ovl_override_creds (file_inode (file)->i_sb); - res =ovl_path_open (realpath,O_RDONLY | (file->f_flags &O_LARGEFILE )); + res =ovl_path_open (realpath, flags);revert_creds (old_cred);return res;
fs/overlayfs/util.c +1 -1
@@ -502,7 +502,7 @@ struct file *ovl_path_open(struct path *path, int flags)struct inode *inode =d_inode (path->dentry);int err, acc_mode; -if (flags & ~(O_ACCMODE |O_LARGEFILE )) +if (flags & ~(O_ACCMODE |O_LARGEFILE | __FMODE_NONOTIFY))BUG ();switch (flags &O_ACCMODE ) {
Signature · 1 line
2.53.0