Skip to content

Commit 9a3c3c4

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Reject exclusive maps as inner maps in map-in-map
An exclusive map (created with excl_prog_hash) is bound to a single program by hash: check_map_prog_compatibility() refuses to load any program whose digest does not match map->excl_prog_sha. That check only runs for maps a program references directly, i.e. its used_maps. A map reached at runtime through a map-of-maps is never in used_maps, and bpf_map_meta_equal() does not consider excl_prog_sha, so an exclusive map can be inserted into a non-exclusive outer map and then looked up and mutated by an unrelated program, bypassing the exclusivity guarantee. For the signed loader this defeats the metadata map exclusivity check added in the signed loader: the cached map->sha[] is validated against the signed hash while another program on a hostile host rewrites the frozen map's contents through the outer map. Fixes: baefdbd ("bpf: Implement exclusive map creation") Reported-by: sashiko <sashiko@sashiko.dev> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260601150248.394863-2-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 3d781ff commit 9a3c3c4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

kernel/bpf/map_in_map.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
2020
/* Does not support >1 level map-in-map */
2121
if (inner_map->inner_map_meta)
2222
return ERR_PTR(-EINVAL);
23-
23+
if (inner_map->excl_prog_sha)
24+
return ERR_PTR(-ENOTSUPP);
2425
if (!inner_map->ops->map_meta_equal)
2526
return ERR_PTR(-ENOTSUPP);
2627

@@ -101,6 +102,8 @@ void *bpf_map_fd_get_ptr(struct bpf_map *map,
101102
inner_map = __bpf_map_get(f);
102103
if (IS_ERR(inner_map))
103104
return inner_map;
105+
if (inner_map->excl_prog_sha)
106+
return ERR_PTR(-ENOTSUPP);
104107

105108
inner_map_meta = map->inner_map_meta;
106109
if (inner_map_meta->ops->map_meta_equal(inner_map_meta, inner_map))

0 commit comments

Comments
 (0)