From 731868dfbf075124c1e7716b2ce8dea409875339 Mon Sep 17 00:00:00 2001 From: Christoph Werle Date: Wed, 8 Jan 2025 23:09:37 +0100 Subject: [PATCH] bpftool: Fix control flow graph segfault during edge creation If the last instruction of a control flow graph building block is a BPF_CALL, an incorrect edge with e->dst set to NULL is created and results in a segfault during graph output. Ensure that BPF_CALL as last instruction of a building block is handled correctly and only generates a single edge unlike actual BPF_JUMP* instructions. Signed-off-by: Christoph Werle Signed-off-by: Andrii Nakryiko Tested-by: Quentin Monnet Reviewed-by: Quentin Monnet Link: https://lore.kernel.org/bpf/20250108220937.1470029-1-christoph.werle@longjmp.de --- src/cfg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cfg.c b/src/cfg.c index eec437cc..e3785f9a 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -302,6 +302,7 @@ static bool func_add_bb_edges(struct func_node *func) insn = bb->tail; if (!is_jmp_insn(insn->code) || + BPF_OP(insn->code) == BPF_CALL || BPF_OP(insn->code) == BPF_EXIT) { e->dst = bb_next(bb); e->flags |= EDGE_FLAG_FALLTHROUGH;