bpf: Update verification logic for LSM programs
authorKP Singh <kpsingh@google.com>
Thu, 5 Nov 2020 23:06:51 +0000 (23:06 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 6 Nov 2020 21:15:21 +0000 (13:15 -0800)
commit6f64e477830000746c1f992050fbd45c03c89429
treefd19151da1e1c3dbe87ceeb1c123019de69771bf
parentd3bec0138bfbe58606fc1d6f57a4cdc1a20218db
bpf: Update verification logic for LSM programs

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.

Fixes: 9e4e01dfd325 ("bpf: lsm: Implement attach, detach and execution")
Signed-off-by: KP Singh <kpsingh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201105230651.2621917-1-kpsingh@chromium.org
kernel/bpf/bpf_lsm.c