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.
Unified · Split
| @@ -3158,6 +3158,7 @@ static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog) · 3157 unmodified lines | |||
| 3158 | struct bpf_insn *insns; | 3158 | struct bpf_insn *insns; |
| 3159 | u32 off, type; | 3159 | u32 off, type; |
| 3160 | u64 imm; | 3160 | u64 imm; |
| 3161 | u8 code; | ||
| 3161 | int i; | 3162 | int i; |
| 3162 | 3163 | ||
| 3163 | insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), | 3164 | 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 | |||
| 3166 | return insns; | 3167 | return insns; |
| 3167 | 3168 | ||
| 3168 | for (i = 0; i < prog->len; i++) { | 3169 | 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)) { | ||
| 3170 | insns[i].code = BPF_JMP | BPF_CALL; | 3173 | insns[i].code = BPF_JMP | BPF_CALL; |
| 3171 | insns[i].imm = BPF_FUNC_tail_call; | 3174 | insns[i].imm = BPF_FUNC_tail_call; |
| 3172 | /* fall-through */ | 3175 | /* fall-through */ |
| 3173 | } | 3176 | } |
| 3174 | if (insns[i].code == (BPF_JMP | BPF_CALL) || | 3177 | if (code == (BPF_JMP | BPF_CALL) || |
| 3175 | insns[i].code == (BPF_JMP | BPF_CALL_ARGS)) { | 3178 | code == (BPF_JMP | BPF_CALL_ARGS)) { |
| 3176 | if (insns[i].code == (BPF_JMP | BPF_CALL_ARGS)) | 3179 | if (code == (BPF_JMP | BPF_CALL_ARGS)) |
| 3177 | insns[i].code = BPF_JMP | BPF_CALL; | 3180 | insns[i].code = BPF_JMP | BPF_CALL; |
| 3178 | if (!bpf_dump_raw_ok()) | 3181 | if (!bpf_dump_raw_ok()) |
| 3179 | insns[i].imm = 0; | 3182 | insns[i].imm = 0; |
| 3180 | continue; | 3183 | continue; |
| 3181 | } | 3184 | } |
| 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 | } | ||
| 3182 | 3189 | ||
| 3183 | if (insns[i].code != (BPF_LD | BPF_IMM | BPF_DW)) | 3190 | if (code != (BPF_LD | BPF_IMM | BPF_DW)) |
| 3184 | continue; | 3191 | continue; |
| 3185 | 3192 | ||
| 3186 | imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm; | 3193 | imm = ((u64)insns[i + 1].imm << 32) | (u32)insns[i].imm; |