root/tools/testing/selftests/bpf/verifier/ld_abs.c

/* [<][>][^][v][top][bottom][index][help] */
   1 {
   2         "ld_abs: check calling conv, r1",
   3         .insns = {
   4         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
   5         BPF_MOV64_IMM(BPF_REG_1, 0),
   6         BPF_LD_ABS(BPF_W, -0x200000),
   7         BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
   8         BPF_EXIT_INSN(),
   9         },
  10         .errstr = "R1 !read_ok",
  11         .result = REJECT,
  12 },
  13 {
  14         "ld_abs: check calling conv, r2",
  15         .insns = {
  16         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  17         BPF_MOV64_IMM(BPF_REG_2, 0),
  18         BPF_LD_ABS(BPF_W, -0x200000),
  19         BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
  20         BPF_EXIT_INSN(),
  21         },
  22         .errstr = "R2 !read_ok",
  23         .result = REJECT,
  24 },
  25 {
  26         "ld_abs: check calling conv, r3",
  27         .insns = {
  28         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  29         BPF_MOV64_IMM(BPF_REG_3, 0),
  30         BPF_LD_ABS(BPF_W, -0x200000),
  31         BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
  32         BPF_EXIT_INSN(),
  33         },
  34         .errstr = "R3 !read_ok",
  35         .result = REJECT,
  36 },
  37 {
  38         "ld_abs: check calling conv, r4",
  39         .insns = {
  40         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  41         BPF_MOV64_IMM(BPF_REG_4, 0),
  42         BPF_LD_ABS(BPF_W, -0x200000),
  43         BPF_MOV64_REG(BPF_REG_0, BPF_REG_4),
  44         BPF_EXIT_INSN(),
  45         },
  46         .errstr = "R4 !read_ok",
  47         .result = REJECT,
  48 },
  49 {
  50         "ld_abs: check calling conv, r5",
  51         .insns = {
  52         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  53         BPF_MOV64_IMM(BPF_REG_5, 0),
  54         BPF_LD_ABS(BPF_W, -0x200000),
  55         BPF_MOV64_REG(BPF_REG_0, BPF_REG_5),
  56         BPF_EXIT_INSN(),
  57         },
  58         .errstr = "R5 !read_ok",
  59         .result = REJECT,
  60 },
  61 {
  62         "ld_abs: check calling conv, r7",
  63         .insns = {
  64         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  65         BPF_MOV64_IMM(BPF_REG_7, 0),
  66         BPF_LD_ABS(BPF_W, -0x200000),
  67         BPF_MOV64_REG(BPF_REG_0, BPF_REG_7),
  68         BPF_EXIT_INSN(),
  69         },
  70         .result = ACCEPT,
  71 },
  72 {
  73         "ld_abs: tests on r6 and skb data reload helper",
  74         .insns = {
  75         BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
  76         BPF_LD_ABS(BPF_B, 0),
  77         BPF_LD_ABS(BPF_H, 0),
  78         BPF_LD_ABS(BPF_W, 0),
  79         BPF_MOV64_REG(BPF_REG_7, BPF_REG_6),
  80         BPF_MOV64_IMM(BPF_REG_6, 0),
  81         BPF_MOV64_REG(BPF_REG_1, BPF_REG_7),
  82         BPF_MOV64_IMM(BPF_REG_2, 1),
  83         BPF_MOV64_IMM(BPF_REG_3, 2),
  84         BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_skb_vlan_push),
  85         BPF_MOV64_REG(BPF_REG_6, BPF_REG_7),
  86         BPF_LD_ABS(BPF_B, 0),
  87         BPF_LD_ABS(BPF_H, 0),
  88         BPF_LD_ABS(BPF_W, 0),
  89         BPF_MOV64_IMM(BPF_REG_0, 42),
  90         BPF_EXIT_INSN(),
  91         },
  92         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
  93         .result = ACCEPT,
  94         .retval = 42 /* ultimate return value */,
  95 },
  96 {
  97         "ld_abs: invalid op 1",
  98         .insns = {
  99                 BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
 100                 BPF_LD_ABS(BPF_DW, 0),
 101                 BPF_EXIT_INSN(),
 102         },
 103         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 104         .result = REJECT,
 105         .errstr = "unknown opcode",
 106 },
 107 {
 108         "ld_abs: invalid op 2",
 109         .insns = {
 110                 BPF_MOV32_IMM(BPF_REG_0, 256),
 111                 BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
 112                 BPF_LD_IND(BPF_DW, BPF_REG_0, 0),
 113                 BPF_EXIT_INSN(),
 114         },
 115         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 116         .result = REJECT,
 117         .errstr = "unknown opcode",
 118 },
 119 {
 120         "ld_abs: nmap reduced",
 121         .insns = {
 122                 BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
 123                 BPF_LD_ABS(BPF_H, 12),
 124                 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0x806, 28),
 125                 BPF_LD_ABS(BPF_H, 12),
 126                 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0x806, 26),
 127                 BPF_MOV32_IMM(BPF_REG_0, 18),
 128                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -64),
 129                 BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_10, -64),
 130                 BPF_LD_IND(BPF_W, BPF_REG_7, 14),
 131                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -60),
 132                 BPF_MOV32_IMM(BPF_REG_0, 280971478),
 133                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -56),
 134                 BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_10, -56),
 135                 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -60),
 136                 BPF_ALU32_REG(BPF_SUB, BPF_REG_0, BPF_REG_7),
 137                 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 15),
 138                 BPF_LD_ABS(BPF_H, 12),
 139                 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0x806, 13),
 140                 BPF_MOV32_IMM(BPF_REG_0, 22),
 141                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -56),
 142                 BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_10, -56),
 143                 BPF_LD_IND(BPF_H, BPF_REG_7, 14),
 144                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -52),
 145                 BPF_MOV32_IMM(BPF_REG_0, 17366),
 146                 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -48),
 147                 BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_10, -48),
 148                 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -52),
 149                 BPF_ALU32_REG(BPF_SUB, BPF_REG_0, BPF_REG_7),
 150                 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
 151                 BPF_MOV32_IMM(BPF_REG_0, 256),
 152                 BPF_EXIT_INSN(),
 153                 BPF_MOV32_IMM(BPF_REG_0, 0),
 154                 BPF_EXIT_INSN(),
 155         },
 156         .data = {
 157                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0,
 158                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 159                 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
 160         },
 161         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 162         .result = ACCEPT,
 163         .retval = 256,
 164 },
 165 {
 166         "ld_abs: div + abs, test 1",
 167         .insns = {
 168                 BPF_ALU64_REG(BPF_MOV, BPF_REG_6, BPF_REG_1),
 169                 BPF_LD_ABS(BPF_B, 3),
 170                 BPF_ALU64_IMM(BPF_MOV, BPF_REG_2, 2),
 171                 BPF_ALU32_REG(BPF_DIV, BPF_REG_0, BPF_REG_2),
 172                 BPF_ALU64_REG(BPF_MOV, BPF_REG_8, BPF_REG_0),
 173                 BPF_LD_ABS(BPF_B, 4),
 174                 BPF_ALU64_REG(BPF_ADD, BPF_REG_8, BPF_REG_0),
 175                 BPF_LD_IND(BPF_B, BPF_REG_8, -70),
 176                 BPF_EXIT_INSN(),
 177         },
 178         .data = {
 179                 10, 20, 30, 40, 50,
 180         },
 181         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 182         .result = ACCEPT,
 183         .retval = 10,
 184 },
 185 {
 186         "ld_abs: div + abs, test 2",
 187         .insns = {
 188                 BPF_ALU64_REG(BPF_MOV, BPF_REG_6, BPF_REG_1),
 189                 BPF_LD_ABS(BPF_B, 3),
 190                 BPF_ALU64_IMM(BPF_MOV, BPF_REG_2, 2),
 191                 BPF_ALU32_REG(BPF_DIV, BPF_REG_0, BPF_REG_2),
 192                 BPF_ALU64_REG(BPF_MOV, BPF_REG_8, BPF_REG_0),
 193                 BPF_LD_ABS(BPF_B, 128),
 194                 BPF_ALU64_REG(BPF_ADD, BPF_REG_8, BPF_REG_0),
 195                 BPF_LD_IND(BPF_B, BPF_REG_8, -70),
 196                 BPF_EXIT_INSN(),
 197         },
 198         .data = {
 199                 10, 20, 30, 40, 50,
 200         },
 201         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 202         .result = ACCEPT,
 203         .retval = 0,
 204 },
 205 {
 206         "ld_abs: div + abs, test 3",
 207         .insns = {
 208                 BPF_ALU64_REG(BPF_MOV, BPF_REG_6, BPF_REG_1),
 209                 BPF_ALU64_IMM(BPF_MOV, BPF_REG_7, 0),
 210                 BPF_LD_ABS(BPF_B, 3),
 211                 BPF_ALU32_REG(BPF_DIV, BPF_REG_0, BPF_REG_7),
 212                 BPF_EXIT_INSN(),
 213         },
 214         .data = {
 215                 10, 20, 30, 40, 50,
 216         },
 217         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 218         .result = ACCEPT,
 219         .retval = 0,
 220 },
 221 {
 222         "ld_abs: div + abs, test 4",
 223         .insns = {
 224                 BPF_ALU64_REG(BPF_MOV, BPF_REG_6, BPF_REG_1),
 225                 BPF_ALU64_IMM(BPF_MOV, BPF_REG_7, 0),
 226                 BPF_LD_ABS(BPF_B, 256),
 227                 BPF_ALU32_REG(BPF_DIV, BPF_REG_0, BPF_REG_7),
 228                 BPF_EXIT_INSN(),
 229         },
 230         .data = {
 231                 10, 20, 30, 40, 50,
 232         },
 233         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 234         .result = ACCEPT,
 235         .retval = 0,
 236 },
 237 {
 238         "ld_abs: vlan + abs, test 1",
 239         .insns = { },
 240         .data = {
 241                 0x34,
 242         },
 243         .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
 244         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 245         .result = ACCEPT,
 246         .retval = 0xbef,
 247 },
 248 {
 249         "ld_abs: vlan + abs, test 2",
 250         .insns = {
 251                 BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
 252                 BPF_LD_ABS(BPF_B, 0),
 253                 BPF_LD_ABS(BPF_H, 0),
 254                 BPF_LD_ABS(BPF_W, 0),
 255                 BPF_MOV64_REG(BPF_REG_7, BPF_REG_6),
 256                 BPF_MOV64_IMM(BPF_REG_6, 0),
 257                 BPF_MOV64_REG(BPF_REG_1, BPF_REG_7),
 258                 BPF_MOV64_IMM(BPF_REG_2, 1),
 259                 BPF_MOV64_IMM(BPF_REG_3, 2),
 260                 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
 261                              BPF_FUNC_skb_vlan_push),
 262                 BPF_MOV64_REG(BPF_REG_6, BPF_REG_7),
 263                 BPF_LD_ABS(BPF_B, 0),
 264                 BPF_LD_ABS(BPF_H, 0),
 265                 BPF_LD_ABS(BPF_W, 0),
 266                 BPF_MOV64_IMM(BPF_REG_0, 42),
 267                 BPF_EXIT_INSN(),
 268         },
 269         .data = {
 270                 0x34,
 271         },
 272         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 273         .result = ACCEPT,
 274         .retval = 42,
 275 },
 276 {
 277         "ld_abs: jump around ld_abs",
 278         .insns = { },
 279         .data = {
 280                 10, 11,
 281         },
 282         .fill_helper = bpf_fill_jump_around_ld_abs,
 283         .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 284         .result = ACCEPT,
 285         .retval = 10,
 286 },

/* [<][>][^][v][top][bottom][index][help] */