History

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.

Andrii Nakryiko committed 6 years ago

Commit 29fcb051 parent caf62491 file · +12 −5Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/bpf/syscall.c+12−5
@@ -3158,6 +3158,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog) · 3157 unmodified lines
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) · 2 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t