]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
libbpf: Also reset {insn,data}_cur on realloc failure
authorDaniel Borkmann <daniel@iogearbox.net>
Fri, 29 May 2026 09:41:18 +0000 (11:41 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 1 Jun 2026 00:47:48 +0000 (17:47 -0700)
realloc_insn_buf() as well as realloc_data_buf() free and NULL
gen->insn_start / gen->data_start on -ENOMEM but leave gen->insn_cur /
gen->data_cur pointing into the old, freed buffer. Just reset the
cursors to NULL alongside the base pointers so the freed state is
coherent.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20260529094119.307264-3-daniel@iogearbox.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/gen_loader.c

index 3a6e1d53f287af9b1c2679da443b3817cfa838e4..492360ca07ea393762a8f7e8071ec79b7dd7d76c 100644 (file)
@@ -63,6 +63,7 @@ static int realloc_insn_buf(struct bpf_gen *gen, __u32 size)
                gen->error = -ENOMEM;
                free(gen->insn_start);
                gen->insn_start = NULL;
+               gen->insn_cur = NULL;
                return -ENOMEM;
        }
        gen->insn_start = insn_start;
@@ -86,6 +87,7 @@ static int realloc_data_buf(struct bpf_gen *gen, __u32 size)
                gen->error = -ENOMEM;
                free(gen->data_start);
                gen->data_start = NULL;
+               gen->data_cur = NULL;
                return -ENOMEM;
        }
        gen->data_start = data_start;