Skip to content

Commit 7dd6256

Browse files
sinkapAlexei Starovoitov
authored andcommitted
libbpf: fix off-by-one in emit_signature_match jump offset
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: fb2b0e2 ("libbpf: Update light skeleton for signing") Signed-off-by: KP Singh <kpsingh@kernel.org> Link: https://lore.kernel.org/r/20260522215337.662271-2-kpsingh@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 49b1831 commit 7dd6256

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

tools/lib/bpf/gen_loader.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,12 @@ static void emit_signature_match(struct bpf_gen *gen)
592592
gen->hash_insn_offset[i] = gen->insn_cur - gen->insn_start;
593593
emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_3, 0, 0, 0, 0, 0));
594594

595-
off = -(gen->insn_cur - gen->insn_start - gen->cleanup_label) / 8 - 1;
595+
off = -(gen->insn_cur - gen->insn_start - gen->cleanup_label) / 8 - 2;
596596
if (is_simm16(off)) {
597597
emit(gen, BPF_MOV64_IMM(BPF_REG_7, -EINVAL));
598598
emit(gen, BPF_JMP_REG(BPF_JNE, BPF_REG_2, BPF_REG_3, off));
599599
} else {
600600
gen->error = -ERANGE;
601-
emit(gen, BPF_JMP_IMM(BPF_JA, 0, 0, -1));
602601
}
603602
}
604603
}

0 commit comments

Comments
 (0)