From: "Mickaël Salaün" <mic@digikod.net>
To: Christian Brauner <brauner@kernel.org>
Cc: Shervin Oloumi <enlightened@chromium.org>,
viro@zeniv.linux.org.uk, jack@suse.cz, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, gnoack@google.com,
shuah@kernel.org, jorgelo@chromium.org, allenwebb@chromium.org
Subject: Re: [PATCH v3 1/2] fs: add loopback/bind mount specific security hook
Date: Thu, 23 Jan 2025 21:34:08 +0100 [thread overview]
Message-ID: <20250123.So6iudahtoom@digikod.net> (raw)
In-Reply-To: <20250110-luftverkehr-lagen-e9c26ffc277f@brauner>
On Fri, Jan 10, 2025 at 04:42:19PM +0100, Christian Brauner wrote:
> On Thu, Jan 09, 2025 at 08:14:07PM -0800, Shervin Oloumi wrote:
> > On Fri, Jan 3, 2025 at 3:11 AM Jan Kara <jack@suse.cz> wrote:
> > >
> > > On Mon 30-12-24 17:46:31, Shervin Oloumi wrote:
> > > > diff --git a/fs/namespace.c b/fs/namespace.c
> > > > index 23e81c2a1e3f..c902608c9759 100644
> > > > --- a/fs/namespace.c
> > > > +++ b/fs/namespace.c
> > > > @@ -2765,6 +2765,10 @@ static int do_loopback(struct path *path, const char *old_name,
> > > > if (err)
> > > > return err;
> > > >
> > > > + err = security_sb_bindmount(&old_path, path);
> > > > + if (err)
> > > > + goto out;
> > > > +
> > >
> > > So this gets triggered for the legacy mount API path (mount(2) syscall).
> > > For the new mount API, I can see open_tree() does not have any security
> > > hook. Is that intented? Are you catching equivalent changes done through
> > > the new mount API inside security_move_mount() hook?
> >
> > I am not very familiar with the new API and when it is used, but LandLock does
> > listen to security_move_mount() and it rejects all such requests. It also
> > listens to and rejects remount and pivotroot. Are there cases where bind mount
> > requests go through open_tree() and this hook is bypassed?
>
> Whether or not Landlock currently blocks security_move_mount()
> unconditionally doesn't matter. Introducing this api will have to do it
> for the old and the new mount api. First, because we don't implement new
> features for the old mount api that aren't also available in the new
> mount api. Second, because this asymmetry just begs for bugs when
> security_move_mount() isn't blocked anymore.
>
> And third, there seems to be a misconception here.
> open_tree(OPEN_TREE_CLONE) gives you an unattached bind-mount.
> move_mount() is just sugar on top to attach it to a mount namespace.
>
> But a file descriptor from open_tree(OPEN_TREE_CLONE) can be interacted
> with just fine, i.e., read, write, create, shared with other processes.
> You could create a bind-mount that is never attached anywhere. So I'm
> not sure what security guarantees it would give you to block MS_BIND but
> not OPEN_TREE_CLONE.
>
> It should be done for both.
Yes, the new hook should probably be called by attach_recursive_mnt().
Landlock tests should check with the legacy mount(2) and the new
move_mount(2) (e.g. with test variants).
>
> >
> > > Also what caught my eye is that the LSM doesn't care at all whether this is
> > > a recursive bind mount (copying all mounts beneath the specified one) or
> > > just a normal one (copying only a single mount). Maybe that's fine but it
> > > seems a bit counter-intuitive to me as AFAIU it implicitly places a
> > > requirement on the policy that if doing some bind mount is forbidden, then
> > > doing bind mount of any predecessor must be forbidden as well (otherwise
> > > the policy will be inconsistent).
> >
> > I need to double check this with Mickaël, but I think it is safe to allow
> > recursive bind mounts. If a bind mount was allowed, let's say /A -> /home/B,
> > then we already verified that the process did not gain more access (or even
> > dropped some access) through the new mount point, e.g. accessing /A/a through
> > /home/B/a. So with a recursive bind mount, let's say /home -> /C, once we check
> > for privilege escalation as usual, it should be safe to clone any existing sub
> > mounts in the new destination. Because if access through B <= A and C <= B then
> > access through C <= A. So back to your point, there should never exist an
> > illegal bind mount action that can implicitly happen through a legal recursive
> > bind mount of its predecessor. Regardless, I think it might be useful to know if
> > a mount is recursive for other use cases so I added a boolean for surfacing
> > MS_REC in the new patches.
>
> Say /home/hidden is covered by a bind-mount of /dev/null and you're
> doing mount --bind /home /somewhere then /home/hidden will be uncovered
> (There's cases where the kernel itself fuses mounts together or "locks"
> them so things like this cannot happen e.g., when creating an
> unprivileged mount namespace.). If your policy blocks unmounting
> /home/hidden to protect the underlying file then a non-recursive
> bind-mount would be able to circumvent that restriction.
That would be a valid attack scenario. For Landlock, to make it simple,
non-recursive bind mounts should always be denied.
Shervin, please add this scenario in a comment for the Landlock
implementation of the hook.
next prev parent reply other threads:[~2025-01-23 20:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-31 1:46 [PATCH 1/2] fs: add loopback/bind mount specific security hook Shervin Oloumi
2024-12-31 1:46 ` [PATCH 2/2] landlock: add support for private bind mount Shervin Oloumi
2024-12-31 21:03 ` kernel test robot
2024-12-31 5:28 ` [PATCH 1/2] fs: add loopback/bind mount specific security hook kernel test robot
2024-12-31 6:01 ` kernel test robot
2024-12-31 16:43 ` Casey Schaufler
2025-01-03 5:11 ` Paul Moore
2025-01-10 4:11 ` Shervin Oloumi
2025-01-03 11:10 ` Jan Kara
2025-01-10 4:14 ` Shervin Oloumi
2025-01-10 15:42 ` [PATCH v3 " Christian Brauner
2025-01-23 20:34 ` Mickaël Salaün [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-01-10 2:10 Shervin Oloumi
2025-01-10 2:10 ` [PATCH v3 2/2] landlock: add support for private bind mount Shervin Oloumi
2025-01-23 20:34 ` Mickaël Salaün
2025-01-23 21:08 ` Mickaël Salaün
2025-01-23 22:02 ` Mickaël Salaün
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=20250123.So6iudahtoom@digikod.net \
--to=mic@digikod.net \
--cc=allenwebb@chromium.org \
--cc=brauner@kernel.org \
--cc=enlightened@chromium.org \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=jorgelo@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=shuah@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;
as well as URLs for NNTP newsgroup(s).