From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: "Michael Weiß" <michael.weiss@aisec.fraunhofer.de>,
"Alexander Mikhalitsyn" <alexander@mihalicyn.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Quentin Monnet" <quentin@isovalent.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Miklos Szeredi" <miklos@szeredi.hu>,
"Amir Goldstein" <amir73il@gmail.com>,
"Serge E. Hallyn" <serge@hallyn.com>, bpf <bpf@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
"LSM List" <linux-security-module@vger.kernel.org>,
gyroidos@aisec.fraunhofer.de
Subject: Re: [RFC PATCH v3 3/3] devguard: added device guard for mknod in non-initial userns
Date: Sat, 16 Dec 2023 09:41:10 -0800 [thread overview]
Message-ID: <CAADnVQK7MDUZTUxcqCH=unrrGExCjaagfJFqFPhVSLUisJVk_Q@mail.gmail.com> (raw)
In-Reply-To: <20231216-vorrecht-anrief-b096fa50b3f7@brauner>
On Sat, Dec 16, 2023 at 2:38 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Fri, Dec 15, 2023 at 10:08:08AM -0800, Alexei Starovoitov wrote:
> > On Fri, Dec 15, 2023 at 6:15 AM Christian Brauner <brauner@kernel.org> wrote:
> > >
> > > On Fri, Dec 15, 2023 at 02:26:53PM +0100, Michael Weiß wrote:
> > > > On 15.12.23 13:31, Christian Brauner wrote:
> > > > > On Wed, Dec 13, 2023 at 03:38:13PM +0100, Michael Weiß wrote:
> > > > >> devguard is a simple LSM to allow CAP_MKNOD in non-initial user
> > > > >> namespace in cooperation of an attached cgroup device program. We
> > > > >> just need to implement the security_inode_mknod() hook for this.
> > > > >> In the hook, we check if the current task is guarded by a device
> > > > >> cgroup using the lately introduced cgroup_bpf_current_enabled()
> > > > >> helper. If so, we strip out SB_I_NODEV from the super block.
> > > > >>
> > > > >> Access decisions to those device nodes are then guarded by existing
> > > > >> device cgroups mechanism.
> > > > >>
> > > > >> Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
> > > > >> ---
> > > > >
> > > > > I think you misunderstood me... My point was that I believe you don't
> > > > > need an additional LSM at all and no additional LSM hook. But I might be
> > > > > wrong. Only a POC would show.
> > > >
> > > > Yeah sorry, I got your point now.
> > >
> > > I think I might have had a misconception about how this works.
> > > A bpf LSM program can't easily alter a kernel object such as struct
> > > super_block I've been told.
> >
> > Right. bpf cannot change arbitrary kernel objects,
> > but we can add a kfunc that will change a specific bit in a specific
> > data structure.
> > Adding a new lsm hook that does:
> > rc = call_int_hook(sb_device_access, 0, sb);
> > switch (rc) {
> > case 0: do X
> > case 1: do Y
> >
> > is the same thing, but uglier, since return code will be used
> > to do this action.
> > The 'do X' can be one kfunc
> > and 'do Y' can be another.
> > If later we find out that 'do X' is not a good idea we can remove
> > that kfunc.
>
> The reason I moved the SB_I_MANAGED_DEVICES here is that I want a single
> central place where that is done for any possible LSM that wants to
> implement device management. So we don't have to go chasing where that
> bit is set for each LSM. I also don't want to have LSMs raise bits in
> sb->s_iflags directly as that's VFS property.
a kfunc that sets a bit in sb->s_iflags will be the same central place.
It will be somewhere in the fs/ directory and vfs maintainers can do what they
wish with it, including removal.
For traditional LSM one would need to do an accurate code review to make
sure that they don't mess with sb->s_iflags while for bpf_lsm it
will be done automatically. That kfunc will be that only one central place.
next prev parent reply other threads:[~2023-12-16 17:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 14:38 [RFC PATCH v3 0/3] devguard: guard mknod for non-initial user namespace Michael Weiß
2023-12-13 14:38 ` [RFC PATCH v3 1/3] bpf: cgroup: Introduce helper cgroup_bpf_current_enabled() Michael Weiß
2023-12-13 16:59 ` Yonghong Song
2023-12-14 8:17 ` Michael Weiß
2023-12-15 14:31 ` Yonghong Song
2023-12-13 14:38 ` [RFC PATCH v3 2/3] fs: Make vfs_mknod() to check CAP_MKNOD in user namespace of sb Michael Weiß
2023-12-13 14:38 ` [RFC PATCH v3 3/3] devguard: added device guard for mknod in non-initial userns Michael Weiß
2023-12-13 18:35 ` Casey Schaufler
2023-12-15 12:31 ` Christian Brauner
2023-12-15 13:26 ` Michael Weiß
2023-12-15 14:15 ` Christian Brauner
2023-12-15 16:36 ` Christian Brauner
2023-12-18 16:09 ` Alexander Mikhalitsyn
2023-12-19 13:43 ` Christian Brauner
2023-12-15 18:08 ` Alexei Starovoitov
2023-12-16 10:38 ` Christian Brauner
2023-12-16 17:41 ` Alexei Starovoitov [this message]
2023-12-18 12:30 ` Christian Brauner
2023-12-22 23:39 ` Paul Moore
2023-12-27 14:31 ` Michael Weiß
2023-12-29 22:31 ` Paul Moore
2024-01-08 13:44 ` Michael Weiß
2024-01-08 16:34 ` Paul Moore
2023-12-18 16:18 ` Alexander Mikhalitsyn
2023-12-20 19:44 ` Michael Weiß
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='CAADnVQK7MDUZTUxcqCH=unrrGExCjaagfJFqFPhVSLUisJVk_Q@mail.gmail.com' \
--to=alexei.starovoitov@gmail.com \
--cc=alexander@mihalicyn.com \
--cc=amir73il@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=gyroidos@aisec.fraunhofer.de \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=michael.weiss@aisec.fraunhofer.de \
--cc=miklos@szeredi.hu \
--cc=paul@paul-moore.com \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=serge@hallyn.com \
--cc=song@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yhs@fb.com \
/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).