Skip to content

Commit 3c56ee3

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Reject exclusive maps for bpf_map_elem iterators
Exclusive maps (aka excl_prog_hash) are meant to be reachable only from the single program whose hash matches. This is enforced by check_map_prog_compatibility() when the map is referenced from a program such as signed BPF loaders. A bpf_map_elem iterator, however, binds its target map at attach time in bpf_iter_attach_map() instead of referencing it from the program, so the exclusivity check is never reached. On top of that, the iterator exposes the map value as a writable buffer. Fixes: baefdbd ("bpf: Implement exclusive map creation") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260602133052.423725-2-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent b93c55b commit 3c56ee3

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

kernel/bpf/map_iter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
112112
map = bpf_map_get_with_uref(linfo->map.map_fd);
113113
if (IS_ERR(map))
114114
return PTR_ERR(map);
115+
if (map->excl_prog_sha) {
116+
err = -EPERM;
117+
goto put_map;
118+
}
115119

116120
if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
117121
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||

0 commit comments

Comments
 (0)