Skip to content

Commit 41300d0

Browse files
borkmannAlexei Starovoitov
authored andcommitted
libbpf: Skip endianness swap when loader generation failed
bpf_gen__prog_load() byte-swaps the program insns and the {func,line}_info and CO-RE relo blobs in place for cross-endian targets. The blob offsets come from add_data(), which returns 0 on failure: realloc_data_buf() either frees and NULLs gen->data_start (realloc OOM) or returns early on an already-latched gen->error, leaving a stale, possibly too-small buffer. Neither bswap site checked for this. With gen->swapped_endian set and a failed generation, "gen->data_start + off" becomes NULL + 0. Guard the same way via !gen->error so they are skipped once generation has failed. Fixes: 8ca3323 ("libbpf: Support creating light skeleton of either endianness") Reported-by: sashiko <sashiko@sashiko.dev> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260529162829.315921-1-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent d2f7bd0 commit 41300d0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tools/lib/bpf/gen_loader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ void bpf_gen__prog_load(struct bpf_gen *gen,
10541054
prog_idx, prog_type, insns_off, insn_cnt, license_off);
10551055

10561056
/* convert blob insns to target endianness */
1057-
if (gen->swapped_endian) {
1057+
if (gen->swapped_endian && !gen->error) {
10581058
struct bpf_insn *insn = gen->data_start + insns_off;
10591059
int i;
10601060

@@ -1092,7 +1092,7 @@ void bpf_gen__prog_load(struct bpf_gen *gen,
10921092
sizeof(struct bpf_core_relo));
10931093

10941094
/* convert all info blobs to target endianness */
1095-
if (gen->swapped_endian)
1095+
if (gen->swapped_endian && !gen->error)
10961096
info_blob_bswap(gen, func_info, line_info, core_relos, load_attr);
10971097

10981098
libbpf_strlcpy(attr.prog_name, prog_name, sizeof(attr.prog_name));

0 commit comments

Comments
 (0)