From: Frederick Lawler <fred@cloudflare.com>
To: Song Liu <song@kernel.org>
Cc: KP Singh <kpsingh@kernel.org>,
revest@chromium.org, jackmanb@chromium.org, bpf@vger.kernel.org,
kernel-team@cloudflare.com,
linux-security-module@vger.kernel.org, paul@paul-moore.com,
laoar.shao@gmail.com, casey@schaufler-ca.com,
penguin-kernel@i-love.sakura.ne.jp
Subject: Re: BPF LSM prevent program unload
Date: Thu, 7 Dec 2023 18:21:00 -0600 [thread overview]
Message-ID: <ZXJhbHpIC3zHIYXs@CMGLRV3> (raw)
In-Reply-To: <CAPhsuW6dib__mB8RJUPQGz_f+NLKmdVE3HsZ1JTy6_Ga7ysViw@mail.gmail.com>
On Thu, Dec 07, 2023 at 03:42:49PM -0800, Song Liu wrote:
> Hi Frederick,
>
> On Thu, Dec 7, 2023 at 3:30 PM Frederick Lawler <fred@cloudflare.com> wrote:
> >
> [...]
> > > While, I think this may be doable with existing LSM hooks but we need
> > > to probably have to cover multiple hook points needed to prevent one
> > > action which makes a good case for another LSM hook, perhaps something
> > > in the link->ops->detach path like
> > > https://elixir.bootlin.com/linux/latest/source/kernel/bpf/syscall.c#L5074
> > >
> > > What do you think?
> >
> > That's what I was thinking for option (4) "introduce a
> > security_bpf_prog_unload()". Anyway, I agree. Paul brought up a good
> > point that he'd like to see more discussion around this idea [1].
> > Mucking with the mounts (see below) is a bit of a mess, and there could
> > still exist other methods for unloading I'm not aware of yet.
> >
> > Yesterday I whipped up a hack such that:
> >
> > mkdir -p /run/fs/bpf-lsm
> > mount -t bpf none /run/fs/bpf-lsm
> > ./load-policies /run/fs/bpf-lsm
>
> Trying to understand the solution here. Does load-policies add multiple
> policies to stop different ways to unload the LSM BPF program (unpin,
> umount, etc.)? So the only way to unload these policies is reboot. If this
> is the case, could you please share the list of hooks needed to achieve a
> secure result?
./load-policies loads multiple BPF object files (policy) each containing
N programs. Then for each program, pin it to the bpffs and terminate.
There's more there for atomic loads etc... but not relevant
for answering the question. For this hack, I created a bpf object file
with two programs:
- lsm/sb_umount
- lsm/inode_unlink
More could be added to this list as necessary depending on finding other
ways to unload. I've only found the filesystem to be the most consistent
way so far. libbpf's unpin functions seem to be also trapped by the
inode_unlink program, but more exploration syscalls is on my
TODO list.
And added the object file along with the rest to load in.
> If the list is really long, we should probably add an option to
> permanently load and attach a program (until reboot).
This is an interesting thought as well. I think that would fall under
idea (5) [1]. But the list isn't that long, and lonterm, I'd like the loader
to have permission to load/unload BPF LSM progs. But, this won't help folks that
leverage BPF's skeleton loading methods and users that rely on anon
inodes tied to the task. I think KP offered some ideas there [2].
[1] https://lore.kernel.org/all/ZW+KYViDT3HWtKI1@CMGLRV3/
[2] https://lore.kernel.org/all/CACYkzJ4QpQZ8JmdNXKWeSh8oc=jAyRh4Zj98Z+TG37Ce=cfE0w@mail.gmail.com/
>
> Thanks,
> Song
next prev parent reply other threads:[~2023-12-08 0:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 20:38 BPF LSM prevent program unload Frederick Lawler
2023-12-06 2:42 ` Yafang Shao
2023-12-06 15:02 ` Frederick Lawler
2023-12-07 2:28 ` Yafang Shao
2023-12-07 9:25 ` Tetsuo Handa
2023-12-07 17:34 ` Paul Moore
2023-12-07 20:05 ` Casey Schaufler
2023-12-07 14:01 ` KP Singh
2023-12-07 14:23 ` Yafang Shao
2023-12-07 14:38 ` KP Singh
2023-12-07 14:55 ` Yafang Shao
2023-12-07 15:04 ` KP Singh
2023-12-07 23:30 ` Frederick Lawler
2023-12-07 23:42 ` Song Liu
2023-12-08 0:21 ` Frederick Lawler [this message]
2023-12-08 5:17 ` Song Liu
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=ZXJhbHpIC3zHIYXs@CMGLRV3 \
--to=fred@cloudflare.com \
--cc=bpf@vger.kernel.org \
--cc=casey@schaufler-ca.com \
--cc=jackmanb@chromium.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=revest@chromium.org \
--cc=song@kernel.org \
/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