Skip to content

Commit 29fcb05

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
bpf: Undo internal BPF_PROBE_MEM in BPF insns dump
BPF_PROBE_MEM is kernel-internal implmementation details. When dumping BPF instructions to user-space, it needs to be replaced back with BPF_MEM mode. Fixes: 2a02759 ("bpf: Add support for BTF pointers to interpreter") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent caf6249 commit 29fcb05

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

kernel/bpf/syscall.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog)
31583158
struct bpf_insn *insns;
31593159
u32 off, type;
31603160
u64 imm;
3161+
u8 code;
31613162
int i;
31623163

31633164
insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog),
@@ -3166,21 +3167,27 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog)
31663167
return insns;
31673168

31683169
for (i = 0; i < prog->len; i++) {
3169-
if (insns[i].code == (BPF_JMP | BPF_TAIL_CALL)) {
3170+
code = insns[i].code;
3171+
3172+
if (code == (BPF_JMP | BPF_TAIL_CALL)) {
31703173
insns[i].code = BPF_JMP | BPF_CALL;
31713174
insns[i].imm = BPF_FUNC_tail_call;
31723175
/* fall-through */
31733176
}
3174-
if (insns[i].code == (BPF_JMP | BPF_CALL) ||
3175-
insns[i].code == (BPF_JMP | BPF_CALL_ARGS)) {
3176-
if (insns[i].code == (BPF_JMP | BPF_CALL_ARGS))
3177+
if (code == (BPF_JMP | BPF_CALL) ||
3178+
code == (BPF_JMP | BPF_CALL_ARGS)) {
3179+
if (code == (BPF_JMP | BPF_CALL_ARGS))
31773180
insns[i].code = BPF_JMP | BPF_CALL;
31783181
if (!bpf_dump_raw_ok())
31793182
insns[i].imm = 0;
31803183
continue;
31813184
}
3185+
if (BPF_CLASS(code) == BPF_LDX && BPF_MODE(code) == BPF_PROBE_MEM) {
3186+
insns[i].code = BPF_LDX | BPF_SIZE(code) | BPF_MEM;
3187+
continue;
3188+
}
31823189

3183-
if (insns[i].code != (BPF_LD | BPF_IMM | BPF_DW))
3190+
if (code != (BPF_LD | BPF_IMM | BPF_DW))
31843191
continue;
31853192

31863193
imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm;

0 commit comments

Comments
 (0)