Commit 29fcb05b authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

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: 2a02759e ("bpf: Add support for BTF pointers to interpreter")
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200613002115.1632142-1-andriin@fb.com
parent caf62492
...@@ -3158,6 +3158,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog) ...@@ -3158,6 +3158,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog)
struct bpf_insn *insns; struct bpf_insn *insns;
u32 off, type; u32 off, type;
u64 imm; u64 imm;
u8 code;
int i; int i;
insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), 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) ...@@ -3166,21 +3167,27 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog)
return insns; return insns;
for (i = 0; i < prog->len; i++) { for (i = 0; i < prog->len; i++) {
if (insns[i].code == (BPF_JMP | BPF_TAIL_CALL)) { code = insns[i].code;
if (code == (BPF_JMP | BPF_TAIL_CALL)) {
insns[i].code = BPF_JMP | BPF_CALL; insns[i].code = BPF_JMP | BPF_CALL;
insns[i].imm = BPF_FUNC_tail_call; insns[i].imm = BPF_FUNC_tail_call;
/* fall-through */ /* fall-through */
} }
if (insns[i].code == (BPF_JMP | BPF_CALL) || if (code == (BPF_JMP | BPF_CALL) ||
insns[i].code == (BPF_JMP | BPF_CALL_ARGS)) { code == (BPF_JMP | BPF_CALL_ARGS)) {
if (insns[i].code == (BPF_JMP | BPF_CALL_ARGS)) if (code == (BPF_JMP | BPF_CALL_ARGS))
insns[i].code = BPF_JMP | BPF_CALL; insns[i].code = BPF_JMP | BPF_CALL;
if (!bpf_dump_raw_ok()) if (!bpf_dump_raw_ok())
insns[i].imm = 0; insns[i].imm = 0;
continue; continue;
} }
if (BPF_CLASS(code) == BPF_LDX && BPF_MODE(code) == BPF_PROBE_MEM) {
insns[i].code = BPF_LDX | BPF_SIZE(code) | BPF_MEM;
continue;
}
if (insns[i].code != (BPF_LD | BPF_IMM | BPF_DW)) if (code != (BPF_LD | BPF_IMM | BPF_DW))
continue; continue;
imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm; imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment