On Nov 3, 2023 Andrii Nakryiko <andrii@xxxxxxxxxx> wrote: > > Similarly to bpf_prog_alloc LSM hook, rename and extend bpf_map_alloc > hook into bpf_map_create, taking not just struct bpf_map, but also > bpf_attr and bpf_token, to give a fuller context to LSMs. > > Unlike bpf_prog_alloc, there is no need to move the hook around, as it > currently is firing right before allocating BPF map ID and FD, which > seems to be a sweet spot. > > But like bpf_prog_alloc/bpf_prog_free combo, make sure that bpf_map_free > LSM hook is called even if bpf_map_create hook returned error, as if few > LSMs are combined together it could be that one LSM successfully > allocated security blob for its needs, while subsequent LSM rejected BPF > map creation. The former LSM would still need to free up LSM blob, so we > need to ensure security_bpf_map_free() is called regardless of the > outcome. > > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > --- > include/linux/lsm_hook_defs.h | 5 +++-- > include/linux/security.h | 6 ++++-- > kernel/bpf/bpf_lsm.c | 6 +++--- > kernel/bpf/syscall.c | 4 ++-- > security/security.c | 16 ++++++++++------ > security/selinux/hooks.c | 7 ++++--- > 6 files changed, 26 insertions(+), 18 deletions(-) Acked-by: Paul Moore <paul@xxxxxxxxxxxxxx> -- paul-moore.com