[PATCH v2 1/2] libbpf: fix off-by-one in emit_signature_match jump offset

Daniel Borkmann daniel at iogearbox.net
Fri May 22 21:21:04 UTC 2026


On 5/21/26 5:22 PM, KP Singh wrote:
> The offset for the cleanup-label jump is computed before the MOV R7
> instruction is emitted, but the JMP lands after it. Account for the
> extra insn in the offset calculation (-2 instead of -1). Drop the
> redundant self-loop in the else branch; gen->error = -ERANGE already
> marks the generation as failed.
> 
> Fixes: fb2b0e290147 ("libbpf: Update light skeleton for signing")

Fixes: ea923080c145 ("libbpf: Embed and verify the metadata hash in the loader")

The fb2b0e290147 does not touch emit_signature_match as pointed out.

> Signed-off-by: KP Singh <kpsingh at kernel.org>

Other than that, lgtm:

Acked-by: Daniel Borkmann <daniel at iogearbox.net>

> ---
>   tools/lib/bpf/gen_loader.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
> index cd5c2543f54d..9478b8f78f26 100644
> --- a/tools/lib/bpf/gen_loader.c
> +++ b/tools/lib/bpf/gen_loader.c
> @@ -592,13 +592,12 @@ static void emit_signature_match(struct bpf_gen *gen)
>   		gen->hash_insn_offset[i] = gen->insn_cur - gen->insn_start;
>   		emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_3, 0, 0, 0, 0, 0));
>   
> -		off =  -(gen->insn_cur - gen->insn_start - gen->cleanup_label) / 8 - 1;
> +		off = -(gen->insn_cur - gen->insn_start - gen->cleanup_label) / 8 - 2;
>   		if (is_simm16(off)) {
>   			emit(gen, BPF_MOV64_IMM(BPF_REG_7, -EINVAL));
>   			emit(gen, BPF_JMP_REG(BPF_JNE, BPF_REG_2, BPF_REG_3, off));
>   		} else {
>   			gen->error = -ERANGE;
> -			emit(gen, BPF_JMP_IMM(BPF_JA, 0, 0, -1));

It would make sense to move this into a separate commit, and then also clean
up the same in emit_check_err() in one go?

>   		}
>   	}
>   }




More information about the Linux-security-module-archive mailing list