Skip to content

Commit 513f485

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: Reject static entry-point BPF programs
Detect use of static entry-point BPF programs (those with SEC() markings) and emit error message. This is similar to c1cccec ("libbpf: Reject static maps") but for BPF programs. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c1cccec commit 513f485

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,
677677
return -LIBBPF_ERRNO__FORMAT;
678678
}
679679

680+
if (sec_idx != obj->efile.text_shndx && GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
681+
pr_warn("sec '%s': program '%s' is static and not supported\n", sec_name, name);
682+
return -ENOTSUP;
683+
}
684+
680685
pr_debug("sec '%s': found program '%s' at insn offset %zu (%zu bytes), code size %zu insns (%zu bytes)\n",
681686
sec_name, name, sec_off / BPF_INSN_SZ, sec_off, prog_sz / BPF_INSN_SZ, prog_sz);
682687

0 commit comments

Comments
 (0)