Daniel Borkmann | 49ca615 | 2021-08-24 09:39:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 2 | /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com |
| 3 | * Copyright (c) 2016 Facebook |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/bpf.h> |
| 7 | |
| 8 | #include "disasm.h" |
| 9 | |
| 10 | #define __BPF_FUNC_STR_FN(x) [BPF_FUNC_ ## x] = __stringify(bpf_ ## x) |
| 11 | static const char * const func_id_str[] = { |
| 12 | __BPF_FUNC_MAPPER(__BPF_FUNC_STR_FN) |
| 13 | }; |
| 14 | #undef __BPF_FUNC_STR_FN |
| 15 | |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 16 | static const char *__func_get_name(const struct bpf_insn_cbs *cbs, |
| 17 | const struct bpf_insn *insn, |
| 18 | char *buff, size_t len) |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 19 | { |
| 20 | BUILD_BUG_ON(ARRAY_SIZE(func_id_str) != __BPF_FUNC_MAX_ID); |
| 21 | |
Martin KaFai Lau | e6ac245 | 2021-03-24 18:51:42 -0700 | [diff] [blame] | 22 | if (!insn->src_reg && |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 23 | insn->imm >= 0 && insn->imm < __BPF_FUNC_MAX_ID && |
| 24 | func_id_str[insn->imm]) |
| 25 | return func_id_str[insn->imm]; |
| 26 | |
Martin KaFai Lau | e6ac245 | 2021-03-24 18:51:42 -0700 | [diff] [blame] | 27 | if (cbs && cbs->cb_call) { |
| 28 | const char *res; |
| 29 | |
| 30 | res = cbs->cb_call(cbs->private_data, insn); |
| 31 | if (res) |
| 32 | return res; |
| 33 | } |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 34 | |
| 35 | if (insn->src_reg == BPF_PSEUDO_CALL) |
| 36 | snprintf(buff, len, "%+d", insn->imm); |
Martin KaFai Lau | e6ac245 | 2021-03-24 18:51:42 -0700 | [diff] [blame] | 37 | else if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) |
| 38 | snprintf(buff, len, "kernel-function"); |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 39 | |
| 40 | return buff; |
| 41 | } |
| 42 | |
| 43 | static const char *__func_imm_name(const struct bpf_insn_cbs *cbs, |
| 44 | const struct bpf_insn *insn, |
| 45 | u64 full_imm, char *buff, size_t len) |
| 46 | { |
| 47 | if (cbs && cbs->cb_imm) |
| 48 | return cbs->cb_imm(cbs->private_data, insn, full_imm); |
| 49 | |
| 50 | snprintf(buff, len, "0x%llx", (unsigned long long)full_imm); |
| 51 | return buff; |
| 52 | } |
| 53 | |
| 54 | const char *func_id_name(int id) |
| 55 | { |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 56 | if (id >= 0 && id < __BPF_FUNC_MAX_ID && func_id_str[id]) |
| 57 | return func_id_str[id]; |
| 58 | else |
| 59 | return "unknown"; |
| 60 | } |
| 61 | |
| 62 | const char *const bpf_class_string[8] = { |
| 63 | [BPF_LD] = "ld", |
| 64 | [BPF_LDX] = "ldx", |
| 65 | [BPF_ST] = "st", |
| 66 | [BPF_STX] = "stx", |
| 67 | [BPF_ALU] = "alu", |
| 68 | [BPF_JMP] = "jmp", |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 69 | [BPF_JMP32] = "jmp32", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 70 | [BPF_ALU64] = "alu64", |
| 71 | }; |
| 72 | |
| 73 | const char *const bpf_alu_string[16] = { |
| 74 | [BPF_ADD >> 4] = "+=", |
| 75 | [BPF_SUB >> 4] = "-=", |
| 76 | [BPF_MUL >> 4] = "*=", |
| 77 | [BPF_DIV >> 4] = "/=", |
| 78 | [BPF_OR >> 4] = "|=", |
| 79 | [BPF_AND >> 4] = "&=", |
| 80 | [BPF_LSH >> 4] = "<<=", |
| 81 | [BPF_RSH >> 4] = ">>=", |
| 82 | [BPF_NEG >> 4] = "neg", |
| 83 | [BPF_MOD >> 4] = "%=", |
| 84 | [BPF_XOR >> 4] = "^=", |
| 85 | [BPF_MOV >> 4] = "=", |
| 86 | [BPF_ARSH >> 4] = "s>>=", |
| 87 | [BPF_END >> 4] = "endian", |
| 88 | }; |
| 89 | |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 90 | static const char *const bpf_atomic_alu_string[16] = { |
| 91 | [BPF_ADD >> 4] = "add", |
| 92 | [BPF_AND >> 4] = "and", |
| 93 | [BPF_OR >> 4] = "or", |
Xu Kuohai | d6fe1cf | 2021-03-25 13:41:41 +0000 | [diff] [blame] | 94 | [BPF_XOR >> 4] = "xor", |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 97 | static const char *const bpf_ldst_string[] = { |
| 98 | [BPF_W >> 3] = "u32", |
| 99 | [BPF_H >> 3] = "u16", |
| 100 | [BPF_B >> 3] = "u8", |
| 101 | [BPF_DW >> 3] = "u64", |
| 102 | }; |
| 103 | |
| 104 | static const char *const bpf_jmp_string[16] = { |
| 105 | [BPF_JA >> 4] = "jmp", |
| 106 | [BPF_JEQ >> 4] = "==", |
| 107 | [BPF_JGT >> 4] = ">", |
| 108 | [BPF_JLT >> 4] = "<", |
| 109 | [BPF_JGE >> 4] = ">=", |
| 110 | [BPF_JLE >> 4] = "<=", |
| 111 | [BPF_JSET >> 4] = "&", |
| 112 | [BPF_JNE >> 4] = "!=", |
| 113 | [BPF_JSGT >> 4] = "s>", |
| 114 | [BPF_JSLT >> 4] = "s<", |
| 115 | [BPF_JSGE >> 4] = "s>=", |
| 116 | [BPF_JSLE >> 4] = "s<=", |
| 117 | [BPF_CALL >> 4] = "call", |
| 118 | [BPF_EXIT >> 4] = "exit", |
| 119 | }; |
| 120 | |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 121 | static void print_bpf_end_insn(bpf_insn_print_t verbose, |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 122 | void *private_data, |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 123 | const struct bpf_insn *insn) |
| 124 | { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 125 | verbose(private_data, "(%02x) r%d = %s%d r%d\n", |
| 126 | insn->code, insn->dst_reg, |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 127 | BPF_SRC(insn->code) == BPF_TO_BE ? "be" : "le", |
| 128 | insn->imm, insn->dst_reg); |
| 129 | } |
| 130 | |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 131 | void print_bpf_insn(const struct bpf_insn_cbs *cbs, |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 132 | const struct bpf_insn *insn, |
| 133 | bool allow_ptr_leaks) |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 134 | { |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 135 | const bpf_insn_print_t verbose = cbs->cb_print; |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 136 | u8 class = BPF_CLASS(insn->code); |
| 137 | |
| 138 | if (class == BPF_ALU || class == BPF_ALU64) { |
| 139 | if (BPF_OP(insn->code) == BPF_END) { |
| 140 | if (class == BPF_ALU64) |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 141 | verbose(cbs->private_data, "BUG_alu64_%02x\n", insn->code); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 142 | else |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 143 | print_bpf_end_insn(verbose, cbs->private_data, insn); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 144 | } else if (BPF_OP(insn->code) == BPF_NEG) { |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 145 | verbose(cbs->private_data, "(%02x) %c%d = -%c%d\n", |
| 146 | insn->code, class == BPF_ALU ? 'w' : 'r', |
| 147 | insn->dst_reg, class == BPF_ALU ? 'w' : 'r', |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 148 | insn->dst_reg); |
| 149 | } else if (BPF_SRC(insn->code) == BPF_X) { |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 150 | verbose(cbs->private_data, "(%02x) %c%d %s %c%d\n", |
| 151 | insn->code, class == BPF_ALU ? 'w' : 'r', |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 152 | insn->dst_reg, |
| 153 | bpf_alu_string[BPF_OP(insn->code) >> 4], |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 154 | class == BPF_ALU ? 'w' : 'r', |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 155 | insn->src_reg); |
| 156 | } else { |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 157 | verbose(cbs->private_data, "(%02x) %c%d %s %d\n", |
| 158 | insn->code, class == BPF_ALU ? 'w' : 'r', |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 159 | insn->dst_reg, |
| 160 | bpf_alu_string[BPF_OP(insn->code) >> 4], |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 161 | insn->imm); |
| 162 | } |
| 163 | } else if (class == BPF_STX) { |
| 164 | if (BPF_MODE(insn->code) == BPF_MEM) |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 165 | verbose(cbs->private_data, "(%02x) *(%s *)(r%d %+d) = r%d\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 166 | insn->code, |
| 167 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 168 | insn->dst_reg, |
| 169 | insn->off, insn->src_reg); |
Brendan Jackman | 91c960b | 2021-01-14 18:17:44 +0000 | [diff] [blame] | 170 | else if (BPF_MODE(insn->code) == BPF_ATOMIC && |
Menglong Dong | 60e578e | 2021-01-26 18:25:07 -0800 | [diff] [blame] | 171 | (insn->imm == BPF_ADD || insn->imm == BPF_AND || |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 172 | insn->imm == BPF_OR || insn->imm == BPF_XOR)) { |
| 173 | verbose(cbs->private_data, "(%02x) lock *(%s *)(r%d %+d) %s r%d\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 174 | insn->code, |
| 175 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 176 | insn->dst_reg, insn->off, |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 177 | bpf_alu_string[BPF_OP(insn->imm) >> 4], |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 178 | insn->src_reg); |
Brendan Jackman | 5ca419f | 2021-01-14 18:17:46 +0000 | [diff] [blame] | 179 | } else if (BPF_MODE(insn->code) == BPF_ATOMIC && |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 180 | (insn->imm == (BPF_ADD | BPF_FETCH) || |
| 181 | insn->imm == (BPF_AND | BPF_FETCH) || |
| 182 | insn->imm == (BPF_OR | BPF_FETCH) || |
| 183 | insn->imm == (BPF_XOR | BPF_FETCH))) { |
| 184 | verbose(cbs->private_data, "(%02x) r%d = atomic%s_fetch_%s((%s *)(r%d %+d), r%d)\n", |
Brendan Jackman | 5ca419f | 2021-01-14 18:17:46 +0000 | [diff] [blame] | 185 | insn->code, insn->src_reg, |
| 186 | BPF_SIZE(insn->code) == BPF_DW ? "64" : "", |
Brendan Jackman | 981f94c | 2021-01-14 18:17:49 +0000 | [diff] [blame] | 187 | bpf_atomic_alu_string[BPF_OP(insn->imm) >> 4], |
Brendan Jackman | 5ca419f | 2021-01-14 18:17:46 +0000 | [diff] [blame] | 188 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 189 | insn->dst_reg, insn->off, insn->src_reg); |
Brendan Jackman | 5ffa255 | 2021-01-14 18:17:47 +0000 | [diff] [blame] | 190 | } else if (BPF_MODE(insn->code) == BPF_ATOMIC && |
| 191 | insn->imm == BPF_CMPXCHG) { |
| 192 | verbose(cbs->private_data, "(%02x) r0 = atomic%s_cmpxchg((%s *)(r%d %+d), r0, r%d)\n", |
| 193 | insn->code, |
| 194 | BPF_SIZE(insn->code) == BPF_DW ? "64" : "", |
| 195 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 196 | insn->dst_reg, insn->off, |
| 197 | insn->src_reg); |
| 198 | } else if (BPF_MODE(insn->code) == BPF_ATOMIC && |
| 199 | insn->imm == BPF_XCHG) { |
| 200 | verbose(cbs->private_data, "(%02x) r%d = atomic%s_xchg((%s *)(r%d %+d), r%d)\n", |
| 201 | insn->code, insn->src_reg, |
| 202 | BPF_SIZE(insn->code) == BPF_DW ? "64" : "", |
| 203 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 204 | insn->dst_reg, insn->off, insn->src_reg); |
Brendan Jackman | 91c960b | 2021-01-14 18:17:44 +0000 | [diff] [blame] | 205 | } else { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 206 | verbose(cbs->private_data, "BUG_%02x\n", insn->code); |
Brendan Jackman | 91c960b | 2021-01-14 18:17:44 +0000 | [diff] [blame] | 207 | } |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 208 | } else if (class == BPF_ST) { |
Daniel Borkmann | f5e81d1 | 2021-07-13 08:18:31 +0000 | [diff] [blame] | 209 | if (BPF_MODE(insn->code) == BPF_MEM) { |
| 210 | verbose(cbs->private_data, "(%02x) *(%s *)(r%d %+d) = %d\n", |
| 211 | insn->code, |
| 212 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 213 | insn->dst_reg, |
| 214 | insn->off, insn->imm); |
| 215 | } else if (BPF_MODE(insn->code) == 0xc0 /* BPF_NOSPEC, no UAPI */) { |
| 216 | verbose(cbs->private_data, "(%02x) nospec\n", insn->code); |
| 217 | } else { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 218 | verbose(cbs->private_data, "BUG_st_%02x\n", insn->code); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 219 | } |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 220 | } else if (class == BPF_LDX) { |
| 221 | if (BPF_MODE(insn->code) != BPF_MEM) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 222 | verbose(cbs->private_data, "BUG_ldx_%02x\n", insn->code); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 223 | return; |
| 224 | } |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 225 | verbose(cbs->private_data, "(%02x) r%d = *(%s *)(r%d %+d)\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 226 | insn->code, insn->dst_reg, |
| 227 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 228 | insn->src_reg, insn->off); |
| 229 | } else if (class == BPF_LD) { |
| 230 | if (BPF_MODE(insn->code) == BPF_ABS) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 231 | verbose(cbs->private_data, "(%02x) r0 = *(%s *)skb[%d]\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 232 | insn->code, |
| 233 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 234 | insn->imm); |
| 235 | } else if (BPF_MODE(insn->code) == BPF_IND) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 236 | verbose(cbs->private_data, "(%02x) r0 = *(%s *)skb[r%d + %d]\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 237 | insn->code, |
| 238 | bpf_ldst_string[BPF_SIZE(insn->code) >> 3], |
| 239 | insn->src_reg, insn->imm); |
| 240 | } else if (BPF_MODE(insn->code) == BPF_IMM && |
| 241 | BPF_SIZE(insn->code) == BPF_DW) { |
| 242 | /* At this point, we already made sure that the second |
| 243 | * part of the ldimm64 insn is accessible. |
| 244 | */ |
| 245 | u64 imm = ((u64)(insn + 1)->imm << 32) | (u32)insn->imm; |
Daniel Borkmann | d8eca5b | 2019-04-09 23:20:03 +0200 | [diff] [blame] | 246 | bool is_ptr = insn->src_reg == BPF_PSEUDO_MAP_FD || |
| 247 | insn->src_reg == BPF_PSEUDO_MAP_VALUE; |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 248 | char tmp[64]; |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 249 | |
Daniel Borkmann | d8eca5b | 2019-04-09 23:20:03 +0200 | [diff] [blame] | 250 | if (is_ptr && !allow_ptr_leaks) |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 251 | imm = 0; |
| 252 | |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 253 | verbose(cbs->private_data, "(%02x) r%d = %s\n", |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 254 | insn->code, insn->dst_reg, |
| 255 | __func_imm_name(cbs, insn, imm, |
| 256 | tmp, sizeof(tmp))); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 257 | } else { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 258 | verbose(cbs->private_data, "BUG_ld_%02x\n", insn->code); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 259 | return; |
| 260 | } |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 261 | } else if (class == BPF_JMP32 || class == BPF_JMP) { |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 262 | u8 opcode = BPF_OP(insn->code); |
| 263 | |
| 264 | if (opcode == BPF_CALL) { |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 265 | char tmp[64]; |
| 266 | |
| 267 | if (insn->src_reg == BPF_PSEUDO_CALL) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 268 | verbose(cbs->private_data, "(%02x) call pc%s\n", |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 269 | insn->code, |
| 270 | __func_get_name(cbs, insn, |
| 271 | tmp, sizeof(tmp))); |
| 272 | } else { |
| 273 | strcpy(tmp, "unknown"); |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 274 | verbose(cbs->private_data, "(%02x) call %s#%d\n", insn->code, |
Daniel Borkmann | 7105e82 | 2017-12-20 13:42:57 +0100 | [diff] [blame] | 275 | __func_get_name(cbs, insn, |
| 276 | tmp, sizeof(tmp)), |
| 277 | insn->imm); |
| 278 | } |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 279 | } else if (insn->code == (BPF_JMP | BPF_JA)) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 280 | verbose(cbs->private_data, "(%02x) goto pc%+d\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 281 | insn->code, insn->off); |
| 282 | } else if (insn->code == (BPF_JMP | BPF_EXIT)) { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 283 | verbose(cbs->private_data, "(%02x) exit\n", insn->code); |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 284 | } else if (BPF_SRC(insn->code) == BPF_X) { |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 285 | verbose(cbs->private_data, |
| 286 | "(%02x) if %c%d %s %c%d goto pc%+d\n", |
| 287 | insn->code, class == BPF_JMP32 ? 'w' : 'r', |
| 288 | insn->dst_reg, |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 289 | bpf_jmp_string[BPF_OP(insn->code) >> 4], |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 290 | class == BPF_JMP32 ? 'w' : 'r', |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 291 | insn->src_reg, insn->off); |
| 292 | } else { |
Jiong Wang | 56cbd82 | 2019-01-26 12:26:02 -0500 | [diff] [blame] | 293 | verbose(cbs->private_data, |
| 294 | "(%02x) if %c%d %s 0x%x goto pc%+d\n", |
| 295 | insn->code, class == BPF_JMP32 ? 'w' : 'r', |
| 296 | insn->dst_reg, |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 297 | bpf_jmp_string[BPF_OP(insn->code) >> 4], |
| 298 | insn->imm, insn->off); |
| 299 | } |
| 300 | } else { |
Jiri Olsa | abe0884 | 2018-03-23 11:41:28 +0100 | [diff] [blame] | 301 | verbose(cbs->private_data, "(%02x) %s\n", |
Jakub Kicinski | f4ac7e0 | 2017-10-09 10:30:12 -0700 | [diff] [blame] | 302 | insn->code, bpf_class_string[class]); |
| 303 | } |
| 304 | } |