* [PATCH bpf-next v2] bpf: Update verification logic for LSM programs
@ 2020-11-05 23:06 KP Singh
2020-11-06 21:16 ` Alexei Starovoitov
2020-11-06 21:21 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: KP Singh @ 2020-11-05 23:06 UTC (permalink / raw)
To: linux-kernel, bpf; +Cc: Alexei Starovoitov, Daniel Borkmann
From: KP Singh <kpsingh@google.com>
The current logic checks if the name of the BTF type passed in
attach_btf_id starts with "bpf_lsm_", this is not sufficient as it also
allows attachment to non-LSM hooks like the very function that performs
this check, i.e. bpf_lsm_verify_prog.
In order to ensure that this verification logic allows attachment to
only LSM hooks, the LSM_HOOK definitions in lsm_hook_defs.h are used to
generate a BTF_ID set. Upon verification, the attach_btf_id of the
program being attached is checked for presence in this set.
Signed-off-by: KP Singh <kpsingh@google.com>
---
kernel/bpf/bpf_lsm.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index 78ea8a7bd27f..56cc5a915f67 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -13,6 +13,7 @@
#include <linux/bpf_verifier.h>
#include <net/bpf_sk_storage.h>
#include <linux/bpf_local_storage.h>
+#include <linux/btf_ids.h>
/* For every LSM hook that allows attachment of BPF programs, declare a nop
* function where a BPF program can be attached.
@@ -26,7 +27,11 @@ noinline RET bpf_lsm_##NAME(__VA_ARGS__) \
#include <linux/lsm_hook_defs.h>
#undef LSM_HOOK
-#define BPF_LSM_SYM_PREFX "bpf_lsm_"
+#define LSM_HOOK(RET, DEFAULT, NAME, ...) BTF_ID(func, bpf_lsm_##NAME)
+BTF_SET_START(bpf_lsm_hooks)
+#include <linux/lsm_hook_defs.h>
+#undef LSM_HOOK
+BTF_SET_END(bpf_lsm_hooks)
int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
const struct bpf_prog *prog)
@@ -37,8 +42,7 @@ int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
return -EINVAL;
}
- if (strncmp(BPF_LSM_SYM_PREFX, prog->aux->attach_func_name,
- sizeof(BPF_LSM_SYM_PREFX) - 1)) {
+ if (!btf_id_set_contains(&bpf_lsm_hooks, prog->aux->attach_btf_id)) {
bpf_log(vlog, "attach_btf_id %u points to wrong type name %s\n",
prog->aux->attach_btf_id, prog->aux->attach_func_name);
return -EINVAL;
--
2.29.1.341.ge80a0c044ae-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpf: Update verification logic for LSM programs
2020-11-05 23:06 [PATCH bpf-next v2] bpf: Update verification logic for LSM programs KP Singh
@ 2020-11-06 21:16 ` Alexei Starovoitov
2020-11-06 21:21 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-11-06 21:16 UTC (permalink / raw)
To: KP Singh; +Cc: LKML, bpf, Alexei Starovoitov, Daniel Borkmann
On Thu, Nov 5, 2020 at 3:06 PM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> The current logic checks if the name of the BTF type passed in
> attach_btf_id starts with "bpf_lsm_", this is not sufficient as it also
> allows attachment to non-LSM hooks like the very function that performs
> this check, i.e. bpf_lsm_verify_prog.
>
> In order to ensure that this verification logic allows attachment to
> only LSM hooks, the LSM_HOOK definitions in lsm_hook_defs.h are used to
> generate a BTF_ID set. Upon verification, the attach_btf_id of the
> program being attached is checked for presence in this set.
>
> Signed-off-by: KP Singh <kpsingh@google.com>
I've added Fixes tag and applied to bpf tree.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpf: Update verification logic for LSM programs
2020-11-05 23:06 [PATCH bpf-next v2] bpf: Update verification logic for LSM programs KP Singh
2020-11-06 21:16 ` Alexei Starovoitov
@ 2020-11-06 21:21 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-11-06 21:21 UTC (permalink / raw)
To: KP Singh; +Cc: linux-kernel, bpf, ast, daniel
Hello:
This patch was applied to bpf/bpf.git (refs/heads/master):
On Thu, 5 Nov 2020 23:06:51 +0000 you wrote:
> From: KP Singh <kpsingh@google.com>
>
> The current logic checks if the name of the BTF type passed in
> attach_btf_id starts with "bpf_lsm_", this is not sufficient as it also
> allows attachment to non-LSM hooks like the very function that performs
> this check, i.e. bpf_lsm_verify_prog.
>
> [...]
Here is the summary with links:
- [bpf-next,v2] bpf: Update verification logic for LSM programs
https://git.kernel.org/bpf/bpf/c/6f64e4778300
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-06 21:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 23:06 [PATCH bpf-next v2] bpf: Update verification logic for LSM programs KP Singh
2020-11-06 21:16 ` Alexei Starovoitov
2020-11-06 21:21 ` patchwork-bot+netdevbpf
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).