From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794678457; b=gwNOBQqYyuaYN5ZOGxPUlFz2sUI9x2p9pdsA/v0JGEAeoIZucRXBXWFjkLRcNUYIGdd9 U6XH7c2Nq7BJ7HyQmuDhXjlTi+Fl1uY7iVhnfRH+S53gsLZM1Eze9Z/io5S5iF2U+YZU5 W1uNVi7ypmY76XuPyaeN8WfskCTHoF9l6qUdZ46z2K5ItFxDNT+LmfUUzyPPy+HoyUHu+ FrYIvjXESINJPukpEaDOtXQIp54DsTxsS4yuo3WQCru1U4t/Xyb+WhUejcKAfPTDEbsoS J9/Ro+jxi9ohGUTZI58OIGMqma0gEsVlMUY6JL9iv6H2kRPoz3tcH40Suh7/Q1/RP2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794678457; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=KD6cT7xbJORmX6NN+HAfkkcNMNiV25TVGfS/Qrqok3Y=; b=V1FaKk5lnt+ZzcaDOpyesJ/bTwGNZ2ZzFrdqVxmULljdho6HyF6FhdkUmfMOFmh0vyv+ 8Jn1r1jM4Oyi3t4ofSB9OKhurx9nHdBoveQQUsy/1rjGFz673MIaNfeSzHP/a3KBOBy8R 3o+CVMGkRRTNEpYQSt5pHMbOQWReYkGHN0k/o06tOPrEXZCd9mHXF3f5obOmaElZYi24d CG2iwXkw0ZcWQ4Nxtm+hB4oQr44MVRBqzn7sHe/Dx/obGYz5AjpR2BffoY8hxoyunkKip Rm3LlfW9c+wveouhvUwQ4TOPdADY53509M+Qy4E4oIbWbXdOOE8RsQfjNJmP+UQ0DPA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lU4wMqeZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31C43606A329 for ; Sat, 14 Nov 2026 17:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lU4wMqeZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C92C1F000C4; Sat, 14 Nov 2026 17:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794678456; bh=KD6cT7xbJORmX6NN+HAfkkcNMNiV25TVGfS/Qrqok3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lU4wMqeZRH94AqveVSmfMaqBpDJ/Bmyo1Pke4SOdjwjc+KfdBSjC+txOoIgC7HrMU LiVGeN+x1N/pWjXkwaHAFwbnVl0P9wdhN1pv+aWdc5DOT5dNpJ/iScGdjH20Qm3zH0 Q/NEbFjE0BvNCu26yAGKwcI2VJZSP51N5CNfRJjk5CShJBWz+H7erZWEai0m/yOU/J BtlmB437eXWnQ9kap9OSd11lvkf46KFLwkB8dG2wqIj4Xxxg827fjyoc8VQ4GUa5QG HsSHciUoo7bUtOV3vBRAEof45YsMfb8u7/iD9IZ9KIrjBl++ICLX8el/636HAg3hMG j9ENFGmrDR3vA== From: Sasha Levin To: stable@vger.kernel.org Cc: Amir Goldstein , Edvard Conrad , Sasha Levin Subject: [PATCH 5.10.y] ovl: inherit FMODE_NONOTIFY when reading directory layers Date: Sat, 14 Nov 2026 12:47:35 -0500 Message-ID: <20261114174716.362180-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261109202819-failed-5.10-9ff338af0e00@kernel.org> References: <20261109202819-failed-5.10-9ff338af0e00@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Amir Goldstein [ Upstream commit 9ff338af0e002fe217cfa16b1289b76f6b21fc72 ] Listing a merged or impure overlay directory opens the real layer directories from ovl_dir_read(), when the readdir cache is filled. Those opens use plain ovl_path_open(), so when the directory fd is one that fanotify created for a permission event, they can still raise FS_OPEN_PERM. A listener that also marks the backing filesystem and calls getdents() on the event fd before answering then deadlocks the same way as with the directory open fixed by the previous commit. Store the overlay user file in struct ovl_readdir_data and pass it to ovl_path_open_realfile() from ovl_dir_read(), for both the merged and the impure cache. Internal readers such as ovl_check_empty_dir() and the mount-time workdir cleanup still pass no user file. A note about severity and real world impact: The FAN_OPEN_PERM event is traditionally used by anti-malware protection agents and security/audit agents. The scope that is often used in those use cases is FAN_MARK_MOUNT and agents typically monitor multiple mounts in a mount namespace. FAN_OPEN_PERM from directory open requires user opt-in with FAN_ONDIR. It is often not the case that anti-malware agents monitor open of directories. Security/audit engines are more likely to opt-into FAN_OPEN_PERM on directories, but are less likely to list the content of a directory within the scope of FAN_OPEN_PERM event, so the real world impact of this bug is likely not significant. Reported-by: Edvard Conrad Closes: https://lore.kernel.org/all/P5Qu3co--N-9@tuta.io/ Cc: stable@vger.kernel.org Tested-by: Edvard Conrad Link: https://lore.kernel.org/ltp/P5WKBbq--F-9@tuta.io/ Co-developed-by: Edvard Conrad Signed-off-by: Edvard Conrad Signed-off-by: Amir Goldstein [ sashal: replaced ovl_path_open_realfile() with ovl_path_open() using explicit __FMODE_NONOTIFY flag propagation ] Signed-off-by: Sasha Levin --- fs/overlayfs/readdir.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index e3ff8828b5a8c..1b1cf16544130 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -37,6 +37,7 @@ struct ovl_dir_cache { struct ovl_readdir_data { struct dir_context ctx; + const struct file *user_file; struct dentry *dentry; bool is_lowest; struct rb_root *root; @@ -295,9 +296,13 @@ static inline int ovl_dir_read(struct path *realpath, struct ovl_readdir_data *rdd) { struct file *realfile; + int flags = O_RDONLY | O_LARGEFILE; int err; - realfile = ovl_path_open(realpath, O_RDONLY | O_LARGEFILE); + if (rdd->user_file && (rdd->user_file->f_mode & FMODE_NONOTIFY)) + flags |= __FMODE_NONOTIFY; + + realfile = ovl_path_open(realpath, flags); if (IS_ERR(realfile)) return PTR_ERR(realfile); @@ -341,12 +346,13 @@ static void ovl_dir_reset(struct file *file) } static int ovl_dir_read_merged(struct dentry *dentry, struct list_head *list, - struct rb_root *root) + struct rb_root *root, const struct file *user_file) { int err; struct path realpath; struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, + .user_file = user_file, .dentry = dentry, .list = list, .root = root, @@ -390,9 +396,10 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos) od->cursor = p; } -static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get(struct file *file) { int res; + struct dentry *dentry = file->f_path.dentry; struct ovl_dir_cache *cache; cache = ovl_dir_cache(d_inode(dentry)); @@ -411,7 +418,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) INIT_LIST_HEAD(&cache->entries); cache->root = RB_ROOT; - res = ovl_dir_read_merged(dentry, &cache->entries, &cache->root); + res = ovl_dir_read_merged(dentry, &cache->entries, &cache->root, file); if (res) { ovl_cache_free(&cache->entries); kfree(cache); @@ -545,14 +552,15 @@ static int ovl_fill_plain(struct dir_context *ctx, const char *name, return 0; } -static int ovl_dir_read_impure(struct path *path, struct list_head *list, - struct rb_root *root) +static int ovl_dir_read_impure(struct path *path, struct list_head *list, + struct rb_root *root, const struct file *user_file) { int err; struct path realpath; struct ovl_cache_entry *p, *n; struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, + .user_file = user_file, .list = list, .root = root, }; @@ -590,9 +598,10 @@ static int ovl_dir_read_impure(struct path *path, struct list_head *list, return 0; } -static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure(struct file *file) { int res; + struct path *path = &file->f_path; struct dentry *dentry = path->dentry; struct ovl_fs *ofs = OVL_FS(dentry->d_sb); struct ovl_dir_cache *cache; @@ -609,7 +618,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path) if (!cache) return ERR_PTR(-ENOMEM); - res = ovl_dir_read_impure(path, &cache->entries, &cache->root); + res = ovl_dir_read_impure(path, &cache->entries, &cache->root, file); if (res) { ovl_cache_free(&cache->entries); kfree(cache); @@ -724,7 +733,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx) dput(parent); if (ovl_is_impure_dir(file)) { - rdt.cache = ovl_cache_get_impure(&file->f_path); + rdt.cache = ovl_cache_get_impure(file); if (IS_ERR(rdt.cache)) return PTR_ERR(rdt.cache); } @@ -771,7 +780,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx) if (!od->cache) { struct ovl_dir_cache *cache; - cache = ovl_cache_get(dentry); + cache = ovl_dir_cache_get(file); err = PTR_ERR(cache); if (IS_ERR(cache)) goto out; @@ -986,7 +995,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) const struct cred *old_cred; old_cred = ovl_override_creds(dentry->d_sb); - err = ovl_dir_read_merged(dentry, list, &root); + err = ovl_dir_read_merged(dentry, list, &root, NULL); revert_creds(old_cred); if (err) return err; -- 2.53.0