From: Jeff Layton <jlayton@kernel.org>
To: David Lee <david.lee@trailofbits.com>,
viro@zeniv.linux.org.uk, Christian Brauner <brauner@kernel.org>,
Jan Kara <jack@suse.cz>
Cc: Chuck Lever <cel@kernel.org>, Amir Goldstein <amir73il@gmail.com>,
Jann Horn <jannh@google.com>,
Dominik 'Disconnect3d' Czarnota
<dominik.czarnota@trailofbits.com>,
linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] fhandle: reject detached mounts in capable_wrt_mount()
Date: Wed, 01 Jul 2026 08:17:58 -0400 [thread overview]
Message-ID: <221834b1e2f98e35fa0e8675734d4dfac8ca9bb1.camel@kernel.org> (raw)
In-Reply-To: <20260701114438.24431-1-david.lee@trailofbits.com>
On Wed, 2026-07-01 at 11:44 +0000, David Lee wrote:
> The recent fhandle RCU fix moved the mount namespace capability check
> into capable_wrt_mount(), so a non-NULL mnt_namespace survives the
> ns_capable() dereference. The helper still assumes the later
> READ_ONCE(mount->mnt_ns) must be non-NULL because may_decode_fh()
> checked is_mounted() first.
>
> That assumption is not stable. A detached mount from
> open_tree(..., OPEN_TREE_CLONE) can be dissolved on fput while
> open_by_handle_at() is between those checks, and umount_tree() can
> clear mount->mnt_ns. If the helper observes NULL, it dereferences
> mnt_ns->user_ns and panics.
>
> Return false when the RCU read observes a detached mount. This keeps
> the relaxed permission path conservative: a mount no longer attached
> to a namespace cannot authorize open_by_handle_at() access.
>
> Fixes: 620c266f3949 ("fhandle: relax open_by_handle_at() permission checks")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Lee <david.lee@trailofbits.com>
> Assisted-by: Codex:gpt-5
> ---
> Bug found and triaged by David Lee from Trail of Bits.
>
> Trail of Bits has a minimal PoC that triggers this crash on a custom
> kernel build, which can be shared further if needed.
>
> fs/fhandle.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/fhandle.c b/fs/fhandle.c
> index 1ca7eb3a6cb5..f8829231e3d7 100644
> --- a/fs/fhandle.c
> +++ b/fs/fhandle.c
> @@ -295,7 +295,7 @@ static bool capable_wrt_mount(struct mount *mount)
> */
> guard(rcu)();
> mnt_ns = READ_ONCE(mount->mnt_ns);
> - return ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN);
> + return mnt_ns && ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN);
> }
>
> static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
Seems sane.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-07-01 12:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 11:44 [PATCH] fhandle: reject detached mounts in capable_wrt_mount() David Lee
2026-07-01 12:17 ` Jeff Layton [this message]
2026-07-01 12:41 ` Christian Brauner
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=221834b1e2f98e35fa0e8675734d4dfac8ca9bb1.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=david.lee@trailofbits.com \
--cc=dominik.czarnota@trailofbits.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.