* [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts
@ 2025-08-25 18:12 Askar Safin
2025-08-25 18:12 ` [PATCH v2 1/4] namei: move cross-device check to traverse_mounts Askar Safin
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Askar Safin @ 2025-08-25 18:12 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches
openat2 had a bug: if we pass RESOLVE_NO_XDEV, then openat2
doesn't traverse through automounts, but may still trigger them.
See this link for full bug report with reproducer:
https://lore.kernel.org/linux-fsdevel/20250817075252.4137628-1-safinaskar@zohomail.com/
This patchset fixes the bug.
RESOLVE_NO_XDEV logic hopefully becomes more clear:
now we immediately fail when we cross mountpoints.
I think 4th patch should go to -fixes and stable trees.
I split everything to very small commits to make
everything as bisectable as possible.
Minimal testing was performed. I tested that my original
reproducer doesn't reproduce anymore. And I did boot-test
with localmodconfig in qemu
I'm not very attached to this patchset. I. e. I will not be offended
if someone else will submit different fix for this bug.
v1: https://lore.kernel.org/linux-fsdevel/20250817171513.259291-1-safinaskar@zohomail.com/
v1 -> v2:
- Commit messages
- Comments
- Clarified that 4th patch should go to stable
- Whitespace
Askar Safin (4):
namei: move cross-device check to traverse_mounts
namei: remove LOOKUP_NO_XDEV check from handle_mounts
namei: move cross-device check to __traverse_mounts
openat2: don't trigger automounts with RESOLVE_NO_XDEV
fs/namei.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] namei: move cross-device check to traverse_mounts
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
@ 2025-08-25 18:12 ` Askar Safin
2025-08-25 18:12 ` [PATCH v2 2/4] namei: remove LOOKUP_NO_XDEV check from handle_mounts Askar Safin
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Askar Safin @ 2025-08-25 18:12 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches
This is preparation to RESOLVE_NO_XDEV fix in following commits.
No functional change intended
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
fs/namei.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index cd43ff89fbaa..1e13d8e119a4 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1518,6 +1518,7 @@ static inline int traverse_mounts(struct path *path, bool *jumped,
int *count, unsigned lookup_flags)
{
unsigned flags = smp_load_acquire(&path->dentry->d_flags);
+ int ret;
/* fastpath */
if (likely(!(flags & DCACHE_MANAGED_DENTRY))) {
@@ -1526,7 +1527,11 @@ static inline int traverse_mounts(struct path *path, bool *jumped,
return -ENOENT;
return 0;
}
- return __traverse_mounts(path, flags, jumped, count, lookup_flags);
+
+ ret = __traverse_mounts(path, flags, jumped, count, lookup_flags);
+ if (*jumped && unlikely(lookup_flags & LOOKUP_NO_XDEV))
+ return -EXDEV;
+ return ret;
}
int follow_down_one(struct path *path)
@@ -1631,9 +1636,7 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry,
}
ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
if (jumped) {
- if (unlikely(nd->flags & LOOKUP_NO_XDEV))
- ret = -EXDEV;
- else
+ if (!unlikely(nd->flags & LOOKUP_NO_XDEV))
nd->state |= ND_JUMPED;
}
if (unlikely(ret)) {
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] namei: remove LOOKUP_NO_XDEV check from handle_mounts
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 1/4] namei: move cross-device check to traverse_mounts Askar Safin
@ 2025-08-25 18:12 ` Askar Safin
2025-08-25 18:12 ` [PATCH v2 3/4] namei: move cross-device check to __traverse_mounts Askar Safin
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Askar Safin @ 2025-08-25 18:12 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches
This is preparation to RESOLVE_NO_XDEV fix in following commits.
No functional change intended.
The only place that ever looks at
ND_JUMPED in nd->state is complete_walk()
and we are not going to reach
it if handle_mounts() returns an error
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
fs/namei.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 1e13d8e119a4..00f79559e135 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1635,10 +1635,8 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry,
return -ECHILD;
}
ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
- if (jumped) {
- if (!unlikely(nd->flags & LOOKUP_NO_XDEV))
- nd->state |= ND_JUMPED;
- }
+ if (jumped)
+ nd->state |= ND_JUMPED;
if (unlikely(ret)) {
dput(path->dentry);
if (path->mnt != nd->path.mnt)
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] namei: move cross-device check to __traverse_mounts
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 1/4] namei: move cross-device check to traverse_mounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 2/4] namei: remove LOOKUP_NO_XDEV check from handle_mounts Askar Safin
@ 2025-08-25 18:12 ` Askar Safin
2025-08-25 18:12 ` [PATCH v2 4/4] openat2: don't trigger automounts with RESOLVE_NO_XDEV Askar Safin
2025-09-02 8:41 ` [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Christian Brauner
4 siblings, 0 replies; 6+ messages in thread
From: Askar Safin @ 2025-08-25 18:12 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches
This is preparation to RESOLVE_NO_XDEV fix in following commits.
Also this commit makes LOOKUP_NO_XDEV logic more clear: now we
immediately fail with EXDEV on first mount crossing
instead of waiting for very end.
No functional change intended
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
fs/namei.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 00f79559e135..c23e5a076ab3 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1489,6 +1489,10 @@ static int __traverse_mounts(struct path *path, unsigned flags, bool *jumped,
// here we know it's positive
flags = path->dentry->d_flags;
need_mntput = true;
+ if (unlikely(lookup_flags & LOOKUP_NO_XDEV)) {
+ ret = -EXDEV;
+ break;
+ }
continue;
}
}
@@ -1518,7 +1522,6 @@ static inline int traverse_mounts(struct path *path, bool *jumped,
int *count, unsigned lookup_flags)
{
unsigned flags = smp_load_acquire(&path->dentry->d_flags);
- int ret;
/* fastpath */
if (likely(!(flags & DCACHE_MANAGED_DENTRY))) {
@@ -1527,11 +1530,7 @@ static inline int traverse_mounts(struct path *path, bool *jumped,
return -ENOENT;
return 0;
}
-
- ret = __traverse_mounts(path, flags, jumped, count, lookup_flags);
- if (*jumped && unlikely(lookup_flags & LOOKUP_NO_XDEV))
- return -EXDEV;
- return ret;
+ return __traverse_mounts(path, flags, jumped, count, lookup_flags);
}
int follow_down_one(struct path *path)
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] openat2: don't trigger automounts with RESOLVE_NO_XDEV
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
` (2 preceding siblings ...)
2025-08-25 18:12 ` [PATCH v2 3/4] namei: move cross-device check to __traverse_mounts Askar Safin
@ 2025-08-25 18:12 ` Askar Safin
2025-09-02 8:41 ` [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Christian Brauner
4 siblings, 0 replies; 6+ messages in thread
From: Askar Safin @ 2025-08-25 18:12 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches, stable
openat2 had a bug: if we pass RESOLVE_NO_XDEV, then openat2
doesn't traverse through automounts, but may still trigger them.
(See the link for full bug report with reproducer.)
This commit fixes this bug.
Link: https://lore.kernel.org/linux-fsdevel/20250817075252.4137628-1-safinaskar@zohomail.com/
Fixes: fddb5d430ad9fa91b49b1 ("open: introduce openat2(2) syscall")
Reviewed-by: Aleksa Sarai <cyphar@cyphar.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
fs/namei.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/namei.c b/fs/namei.c
index c23e5a076ab3..bfa8232b94dc 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1449,6 +1449,10 @@ static int follow_automount(struct path *path, int *count, unsigned lookup_flags
dentry->d_inode)
return -EISDIR;
+ /* No need to trigger automounts if mountpoint crossing is disabled. */
+ if (lookup_flags & LOOKUP_NO_XDEV)
+ return -EXDEV;
+
if (count && (*count)++ >= MAXSYMLINKS)
return -ELOOP;
@@ -1472,6 +1476,10 @@ static int __traverse_mounts(struct path *path, unsigned flags, bool *jumped,
/* Allow the filesystem to manage the transit without i_rwsem
* being held. */
if (flags & DCACHE_MANAGE_TRANSIT) {
+ if (lookup_flags & LOOKUP_NO_XDEV) {
+ ret = -EXDEV;
+ break;
+ }
ret = path->dentry->d_op->d_manage(path, false);
flags = smp_load_acquire(&path->dentry->d_flags);
if (ret < 0)
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
` (3 preceding siblings ...)
2025-08-25 18:12 ` [PATCH v2 4/4] openat2: don't trigger automounts with RESOLVE_NO_XDEV Askar Safin
@ 2025-09-02 8:41 ` Christian Brauner
4 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-09-02 8:41 UTC (permalink / raw)
To: Askar Safin
Cc: Christian Brauner, linux-fsdevel, David Howells, cyphar, Ian Kent,
autofs mailing list, patches, Alexander Viro, Jan Kara
On Mon, 25 Aug 2025 18:12:29 +0000, Askar Safin wrote:
> openat2 had a bug: if we pass RESOLVE_NO_XDEV, then openat2
> doesn't traverse through automounts, but may still trigger them.
> See this link for full bug report with reproducer:
> https://lore.kernel.org/linux-fsdevel/20250817075252.4137628-1-safinaskar@zohomail.com/
>
> This patchset fixes the bug.
>
> [...]
Applied to the vfs-6.18.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.18.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.18.misc
[1/4] namei: move cross-device check to traverse_mounts
https://git.kernel.org/vfs/vfs/c/11c2b7ec2e18
[2/4] namei: remove LOOKUP_NO_XDEV check from handle_mounts
https://git.kernel.org/vfs/vfs/c/8b966d00b3ec
[3/4] namei: move cross-device check to __traverse_mounts
https://git.kernel.org/vfs/vfs/c/8ded1fde0827
[4/4] openat2: don't trigger automounts with RESOLVE_NO_XDEV
https://git.kernel.org/vfs/vfs/c/042a60680de4
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-02 8:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 18:12 [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 1/4] namei: move cross-device check to traverse_mounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 2/4] namei: remove LOOKUP_NO_XDEV check from handle_mounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 3/4] namei: move cross-device check to __traverse_mounts Askar Safin
2025-08-25 18:12 ` [PATCH v2 4/4] openat2: don't trigger automounts with RESOLVE_NO_XDEV Askar Safin
2025-09-02 8:41 ` [PATCH v2 0/4] vfs: if RESOLVE_NO_XDEV passed to openat2, don't *trigger* automounts Christian Brauner
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).