From: Alexander Mikhalitsyn <alex@amutable.com>
To: Christian Brauner <brauner@kernel.org>, linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Aleksa Sarai <cyphar@cyphar.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] namespace: allow bind mounts of ephemeral procfs files again
Date: Fri, 27 Nov 2026 09:22:03 +0100 [thread overview]
Message-ID: <2b0198ff605e865fa1b17df354511949bce70038.camel@amutable.com> (raw)
In-Reply-To: <20261126-work-mount-cant_mount-v1-1-781d911a32e1@kernel.org>
On Thu, 2026-11-26 at 12:40 +0100, Christian Brauner wrote:
> Commit 75f4197f1e11 ("dcache: don't put a mountpoint on a dentry
> that's
> being removed") made d_set_mounted() refuse dentries that
> dont_mount()
> was called on. I overlooked that procfs calls dont_mount() on the
> files
> in /proc/<pid>/{fd,fdinfo,map_files} and below /proc/<pid>/net when
> it
> creates them and that attach_recursive_mnt() makes a mountpoint out
> of
> the root of every source in case it goes beneath a mount. So
> bind-mounting one of these files fails with ENOENT now. libpathrs
> does
> that in its tests, e.g., by bind-mounting /proc/1/fd/0 over
> /proc/self/exe.
>
> Nothing may be mounted on top of these files but they can be the
> source
> of a mount. So drop the check from d_set_mounted() again and refuse
> such
> a root only if the source or one of its copies would go beneath a
> mount
> that is already there. attach_recursive_mnt() checks the source and
> propagate_mnt() checks each copy right after making it. The root is a
> mountpoint by then so either we see the flag or detach_mounts() finds
> the mount, same as before.
>
> Fixes: 75f4197f1e11 ("dcache: don't put a mountpoint on a dentry
> that's being removed")
> Cc: stable@vger.kernel.org
> Reported-by: Aleksa Sarai <cyphar@cyphar.com>
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
> ---
> fs/dcache.c | 5 ++---
> fs/namespace.c | 25 +++++++++++++++++++++++++
> fs/pnode.c | 6 ++++++
> fs/pnode.h | 2 ++
> 4 files changed, 35 insertions(+), 3 deletions(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index ba17f49f8a636..b734ce65e6377 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1628,8 +1628,7 @@ static __cacheline_aligned_in_smp
> DEFINE_SEQLOCK(d_set_mounted_lock);
> *
> * Only one of d_invalidate() and d_set_mounted() must succeed. For
> * this reason take rename_lock, d_set_mounted_lock and d_lock on
> dentry
> - * and ancestors. Likewise for dont_mount() which marks a dentry
> that
> - * is being removed under d_lock.
> + * and ancestors.
> */
> int d_set_mounted(struct dentry *dentry)
> {
> @@ -1647,7 +1646,7 @@ int d_set_mounted(struct dentry *dentry)
> spin_unlock(&p->d_lock);
> }
> spin_lock(&dentry->d_lock);
> - if (!d_unlinked(dentry) && !cant_mount(dentry)) {
> + if (!d_unlinked(dentry)) {
> ret = -EBUSY;
> if (!d_mountpoint(dentry)) {
> dentry->d_flags |= DCACHE_MOUNTED;
> diff --git a/fs/namespace.c b/fs/namespace.c
> index aecd05ac01705..443a8e3b74f9b 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -2561,6 +2561,21 @@ int count_mounts(struct mnt_namespace *ns,
> struct mount *mnt)
> return 0;
> }
>
> +/*
> + * Would @source_mnt or a copy of it go beneath a mount that is
> already at
> + * @mp on @parent? Call under namespace_sem, without mount_lock.
> + */
> +bool mount_goes_beneath(struct mount *parent, struct mountpoint *mp,
> + struct mount *source_mnt)
> +{
> + struct mount *q;
> +
> + guard(mount_locked_reader)();
> + q = __lookup_mnt(&parent->mnt, mp->m_dentry);
> + /* a moved @source_mnt is gone from there by then */
> + return q && q != source_mnt;
> +}
> +
> enum mnt_tree_flags_t {
> MNT_TREE_BENEATH = BIT(0),
> MNT_TREE_PROPAGATION = BIT(1),
> @@ -2677,6 +2692,16 @@ static int attach_recursive_mnt(struct mount
> *source_mnt,
> if (err)
> return err;
>
> + /*
> + * Don't mount on top of a root that dont_mount() was called
> on. It's
> + * a mountpoint now so a later detach_mounts() will find it.
> + */
> + if (cant_mount(root.mp->m_dentry) &&
> + mount_goes_beneath(dest_mnt, dest_mp, source_mnt)) {
> + err = -ENOENT;
> + goto out;
> + }
> +
> /* Is there space to add these mounts to the mount
> namespace? */
> if (!moving) {
> err = count_mounts(ns, source_mnt);
> diff --git a/fs/pnode.c b/fs/pnode.c
> index 5f07fa14099bf..4514e75311972 100644
> --- a/fs/pnode.c
> +++ b/fs/pnode.c
Hi Christian,
> @@ -351,6 +351,12 @@ int propagate_mnt(struct mount *dest_mnt, struct
> mountpoint *dest_mp,
> err = count_mounts(n->mnt_ns, this);
> if (err)
> break;
> + /* what is already there would end up on
> this root */
> + if (cant_mount(topmost_overmount(this)-
> >mnt.mnt_root) &&
> + mount_goes_beneath(n, dest_mp,
> source_mnt)) {
> + err = -ENOENT;
> + break;
> + }
Please correct me if I'm wrong, but shouldn't we do this check before
count_mounts()? AFAIU, it changes ns->pending_mounts and then I can't
see where we clean it up on the error path.
Kind regards,
Alex
> type = CL_MAKE_SHARED;
> } while ((n = next_peer(n)) != m);
> }
> diff --git a/fs/pnode.h b/fs/pnode.h
> index b029db225f33c..0fb217c48f17a 100644
> --- a/fs/pnode.h
> +++ b/fs/pnode.h
> @@ -59,6 +59,8 @@ struct mount *copy_tree(struct mount *, struct
> dentry *, int);
> bool is_path_reachable(struct mount *, struct dentry *,
> const struct path *root);
> int count_mounts(struct mnt_namespace *ns, struct mount *mnt);
> +bool mount_goes_beneath(struct mount *parent, struct mountpoint *mp,
> + struct mount *source_mnt);
> bool propagation_would_overmount(const struct mount *from,
> const struct mount *to,
> const struct mountpoint *mp);
next prev parent reply other threads:[~2026-11-27 8:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:40 [PATCH 0/2] namespace: allow bind mounts of ephemeral procfs files again Christian Brauner
2026-11-26 11:40 ` [PATCH 1/2] " Christian Brauner
2026-11-27 8:22 ` Alexander Mikhalitsyn [this message]
2026-11-27 8:53 ` Christian Brauner
2026-11-27 8:58 ` Alexander Mikhalitsyn
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=2b0198ff605e865fa1b17df354511949bce70038.camel@amutable.com \
--to=alex@amutable.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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