From 927e33ee5c1bb6ed2a94c7a59be62956089f87f8 Mon Sep 17 00:00:00 2001 From: Viraj Malia Date: Thu, 17 Sep 2026 14:09:16 -0700 Subject: [PATCH] Fix dangling arch pointer in gen_bpf Signed-off-by: Viraj Malia --- src/gen_bpf.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gen_bpf.c b/src/gen_bpf.c index 2cb79a5f..092f7e9d 100644 --- a/src/gen_bpf.c +++ b/src/gen_bpf.c @@ -2030,32 +2030,44 @@ static int _gen_bpf_build_bpf(struct bpf_state *state, /* generate the badarch action */ b_badarch = _gen_bpf_action(state, NULL, state->attr->act_badarch); - if (b_badarch == NULL) + if (b_badarch == NULL) { + state->arch = NULL; return -ENOMEM; + } rc = _hsh_add(state, &b_badarch, 1); - if (rc < 0) + if (rc < 0) { + state->arch = NULL; return rc; + } state->bad_arch_hsh = b_badarch->hash; /* generate the default action */ b_default = _gen_bpf_action(state, NULL, state->attr->act_default); - if (b_default == NULL) + if (b_default == NULL) { + state->arch = NULL; return -ENOMEM; + } rc = _hsh_add(state, &b_default, 0); - if (rc < 0) + if (rc < 0) { + state->arch = NULL; return rc; + } state->def_hsh = b_default->hash; /* load the architecture token/number */ _BPF_INSTR(instr, _BPF_OP(state->arch, BPF_LD + BPF_ABS), _BPF_JMP_NO, _BPF_JMP_NO, _BPF_ARCH(state->arch)); b_head = _blk_append(state, NULL, &instr); - if (b_head == NULL) + if (b_head == NULL) { + state->arch = NULL; return -ENOMEM; + } b_head->acc_end = _ACC_STATE_OFFSET(_BPF_OFFSET_ARCH); rc = _hsh_add(state, &b_head, 1); - if (rc < 0) + if (rc < 0) { + state->arch = NULL; return rc; + } b_tail = b_head; /* generate the per-architecture filters */