From: Kees Cook <keescook@chromium.org>
To: KP Singh <kpsingh@kernel.org>
Cc: linux-security-module@vger.kernel.org, bpf@vger.kernel.org,
ast@kernel.org, daniel@iogearbox.net, jackmanb@google.com,
renauld@google.com, paul@paul-moore.com, casey@schaufler-ca.com,
song@kernel.org, revest@chromium.org
Subject: Re: [PATCH bpf-next v10 5/5] bpf: Only enable BPF LSM hooks when an LSM program is attached
Date: Tue, 7 May 2024 17:01:00 -0700 [thread overview]
Message-ID: <202405071653.2C761D80@keescook> (raw)
In-Reply-To: <20240507221045.551537-6-kpsingh@kernel.org>
On Wed, May 08, 2024 at 12:10:45AM +0200, KP Singh wrote:
> [...]
> +/**
> + * security_toggle_hook - Toggle the state of the LSM hook.
> + * @hook_addr: The address of the hook to be toggled.
> + * @state: Whether to enable for disable the hook.
> + *
> + * Returns 0 on success, -EINVAL if the address is not found.
> + */
> +int security_toggle_hook(void *hook_addr, bool state)
> +{
> + struct lsm_static_call *scalls = ((void *)&static_calls_table);
> + unsigned long num_entries =
> + (sizeof(static_calls_table) / sizeof(struct lsm_static_call));
> + int i;
> +
> + for (i = 0; i < num_entries; i++) {
> + if (!scalls[i].hl)
> + continue;
> +
> + if (scalls[i].hl->hook.lsm_func_addr != hook_addr)
> + continue;
> +
> + if (state)
> + static_branch_enable(scalls[i].active);
> + else
> + static_branch_disable(scalls[i].active);
> + return 0;
> + }
> + return -EINVAL;
> +}
First of all: patches 1-4 are great. They have a measurable performance
benefit; let's get those in.
But here I come to patch 5 where I will suggest the exact opposite of
what Paul said in v9 for patch 5. :P
I don't want to have a global function that can be used to disable LSMs.
We got an entire distro (RedHat) to change their SELinux configurations
to get rid of CONFIG_SECURITY_SELINUX_DISABLE (and therefore
CONFIG_SECURITY_WRITABLE_HOOKS), via commit f22f9aaf6c3d ("selinux:
remove the runtime disable functionality"). We cannot reintroduce that,
and I'm hoping Paul will agree, given this reminder of LSM history. :)
Run-time hook changing should be BPF_LSM specific, if it exists at all.
--
Kees Cook
next prev parent reply other threads:[~2024-05-08 0:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 22:10 [PATCH bpf-next v10 0/5] Reduce overhead of LSMs with static calls KP Singh
2024-05-07 22:10 ` [PATCH bpf-next v10 1/5] kernel: Add helper macros for loop unrolling KP Singh
2024-05-07 22:10 ` [PATCH bpf-next v10 2/5] security: Count the LSMs enabled at compile time KP Singh
2024-05-07 22:10 ` [PATCH bpf-next v10 3/5] security: Replace indirect LSM hook calls with static calls KP Singh
2024-05-07 22:10 ` [PATCH bpf-next v10 4/5] security: Update non standard hooks to use " KP Singh
2024-05-07 22:10 ` [PATCH bpf-next v10 5/5] bpf: Only enable BPF LSM hooks when an LSM program is attached KP Singh
2024-05-08 0:01 ` Kees Cook [this message]
2024-05-08 1:45 ` Paul Moore
2024-05-08 2:35 ` Kees Cook
2024-05-09 20:08 ` Paul Moore
2024-05-08 7:00 ` KP Singh
2024-05-08 7:48 ` Kees Cook
2024-05-09 20:24 ` Paul Moore
2024-05-10 13:23 ` KP Singh
2024-05-15 16:08 ` KP Singh
2024-05-15 16:44 ` KP Singh
2024-05-15 16:57 ` Casey Schaufler
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=202405071653.2C761D80@keescook \
--to=keescook@chromium.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=casey@schaufler-ca.com \
--cc=daniel@iogearbox.net \
--cc=jackmanb@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=renauld@google.com \
--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