History

bpf: Fix security_bpf_map_create error handling

Commit 5816bf4273ed ("lsm,selinux: Add LSM blob support for BPF objects") made the LSM hook wrappers for BPF object creation clean up the LSM state internally upon denial, e.g. security_bpf_map_create() internally calls security_bpf_map_free() when the bpf_map_create hook returns an error. map_create() however still routes a denial to its free_map_sec label, which invokes security_bpf_map_free() a second time, so the bpf_map_free hook fires twice for a single denied map. In-tree LSMs are unaffected in practice since the blob kfree() inside security_bpf_map_free() is NULL-safe and idempotent and none of them implement bpf_map_free, but a BPF LSM program attached to that hook observes double invocations. Route the denial to free_map instead.

Daniel Borkmann committed 4 months ago

Commit 36ffa861 parent 55db6a41 file · +1 −1Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/bpf/syscall.c+1−1
@@ -1649,7 +1649,7 @@ static int map_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_at · 1648 unmodified lines
1649 1649
1650 err = security_bpf_map_create(map, attr, token, uattr.is_kernel);1650 err = security_bpf_map_create(map, attr, token, uattr.is_kernel);
1651 if (err)1651 if (err)
1652 goto free_map_sec;1652 goto free_map;
1653 1653
1654 err = bpf_map_alloc_id(map);1654 err = bpf_map_alloc_id(map);
1655 if (err)1655 if (err)