Skip to content

Commit ed29b0d

Browse files
committed
bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X
Add support for indirect jump instruction. Example output from bpftool: 0: (79) r3 = *(u64 *)(r1 +0) 1: (25) if r3 > 0x4 goto pc+666 2: (67) r3 <<= 3 3: (18) r1 = 0xffffbeefspameggs 5: (0f) r1 += r3 6: (79) r1 = *(u64 *)(r1 +0) 7: (0d) gotox r1 Signed-off-by: Anton Protopopov <[email protected]>
1 parent 5b0983f commit ed29b0d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kernel/bpf/disasm.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ static inline bool is_mov_percpu_addr(const struct bpf_insn *insn)
183183
return insn->code == (BPF_ALU64 | BPF_MOV | BPF_X) && insn->off == BPF_ADDR_PERCPU;
184184
}
185185

186+
static void print_bpf_ja_indirect(bpf_insn_print_t verbose,
187+
void *private_data,
188+
const struct bpf_insn *insn)
189+
{
190+
verbose(private_data, "(%02x) gotox r%d\n", insn->code, insn->dst_reg);
191+
}
192+
186193
void print_bpf_insn(const struct bpf_insn_cbs *cbs,
187194
const struct bpf_insn *insn,
188195
bool allow_ptr_leaks)
@@ -358,6 +365,9 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
358365
} else if (insn->code == (BPF_JMP | BPF_JA)) {
359366
verbose(cbs->private_data, "(%02x) goto pc%+d\n",
360367
insn->code, insn->off);
368+
} else if (insn->code == (BPF_JMP | BPF_JA | BPF_X) ||
369+
insn->code == (BPF_JMP32 | BPF_JA | BPF_X)) {
370+
print_bpf_ja_indirect(verbose, cbs->private_data, insn);
361371
} else if (insn->code == (BPF_JMP | BPF_JCOND) &&
362372
insn->src_reg == BPF_MAY_GOTO) {
363373
verbose(cbs->private_data, "(%02x) may_goto pc%+d\n",

0 commit comments

Comments
 (0)