Skip to content

Commit 6021443

Browse files
borkmannAlexei Starovoitov
authored andcommitted
libbpf: Skip max_entries override on signed loaders
bpf_gen__map_create() lets the host-supplied loader ctx override a map's max_entries at runtime (map_desc[idx].max_entries, when non-zero). This is how the light skeleton sizes maps to the target machine, but it happens after emit_signature_match() and is covered by neither the signed loader instructions nor the hashed blob. For a signed loader this means an untrusted host can re-dimension the program's maps, outside what the signature attests to. Gate the override on gen_hash so signed loaders use the signer-provided max_entries baked into the blob. Fixes: ea92308 ("libbpf: Embed and verify the metadata hash in the loader") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260601150248.394863-6-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 61e0841 commit 6021443

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

tools/lib/bpf/gen_loader.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,22 @@ void bpf_gen__map_create(struct bpf_gen *gen,
546546
default:
547547
break;
548548
}
549-
/* conditionally update max_entries */
550-
if (map_idx >= 0)
549+
550+
/*
551+
* Conditionally update max_entries from the host-supplied loader
552+
* ctx. This sizes the map at runtime, but for a signed loader
553+
* (gen_hash) it would let an untrusted host re-dimension the
554+
* program's maps after emit_signature_match(), outside what the
555+
* signature attests to. Keep the signer-provided max_entries
556+
* baked into the blob in that case.
557+
*/
558+
if (map_idx >= 0 && !OPTS_GET(gen->opts, gen_hash, false))
551559
move_ctx2blob(gen, attr_field(map_create_attr, max_entries), 4,
552560
sizeof(struct bpf_loader_ctx) +
553561
sizeof(struct bpf_map_desc) * map_idx +
554562
offsetof(struct bpf_map_desc, max_entries),
555563
true /* check that max_entries != 0 */);
564+
556565
/* emit MAP_CREATE command */
557566
emit_sys_bpf(gen, BPF_MAP_CREATE, map_create_attr, attr_size);
558567
debug_ret(gen, "map_create %s idx %d type %d value_size %d value_btf_id %d",

0 commit comments

Comments
 (0)