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

/* [<][>][^][v][top][bottom][index][help] */
   1 {
   2         "meta access, test1",
   3         .insns = {
   4         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
   5                     offsetof(struct xdp_md, data_meta)),
   6         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
   7         BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
   8         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
   9         BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
  10         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
  11         BPF_MOV64_IMM(BPF_REG_0, 0),
  12         BPF_EXIT_INSN(),
  13         },
  14         .result = ACCEPT,
  15         .prog_type = BPF_PROG_TYPE_XDP,
  16 },
  17 {
  18         "meta access, test2",
  19         .insns = {
  20         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
  21                     offsetof(struct xdp_md, data_meta)),
  22         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
  23         BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
  24         BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, 8),
  25         BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
  26         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
  27         BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
  28         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
  29         BPF_MOV64_IMM(BPF_REG_0, 0),
  30         BPF_EXIT_INSN(),
  31         },
  32         .result = REJECT,
  33         .errstr = "invalid access to packet, off=-8",
  34         .prog_type = BPF_PROG_TYPE_XDP,
  35 },
  36 {
  37         "meta access, test3",
  38         .insns = {
  39         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
  40                     offsetof(struct xdp_md, data_meta)),
  41         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
  42                     offsetof(struct xdp_md, data_end)),
  43         BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
  44         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
  45         BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
  46         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
  47         BPF_MOV64_IMM(BPF_REG_0, 0),
  48         BPF_EXIT_INSN(),
  49         },
  50         .result = REJECT,
  51         .errstr = "invalid access to packet",
  52         .prog_type = BPF_PROG_TYPE_XDP,
  53 },
  54 {
  55         "meta access, test4",
  56         .insns = {
  57         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
  58                     offsetof(struct xdp_md, data_meta)),
  59         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
  60                     offsetof(struct xdp_md, data_end)),
  61         BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1, offsetof(struct xdp_md, data)),
  62         BPF_MOV64_REG(BPF_REG_0, BPF_REG_4),
  63         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
  64         BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
  65         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
  66         BPF_MOV64_IMM(BPF_REG_0, 0),
  67         BPF_EXIT_INSN(),
  68         },
  69         .result = REJECT,
  70         .errstr = "invalid access to packet",
  71         .prog_type = BPF_PROG_TYPE_XDP,
  72 },
  73 {
  74         "meta access, test5",
  75         .insns = {
  76         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
  77                     offsetof(struct xdp_md, data_meta)),
  78         BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1, offsetof(struct xdp_md, data)),
  79         BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
  80         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
  81         BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_4, 3),
  82         BPF_MOV64_IMM(BPF_REG_2, -8),
  83         BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_xdp_adjust_meta),
  84         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_3, 0),
  85         BPF_MOV64_IMM(BPF_REG_0, 0),
  86         BPF_EXIT_INSN(),
  87         },
  88         .result = REJECT,
  89         .errstr = "R3 !read_ok",
  90         .prog_type = BPF_PROG_TYPE_XDP,
  91 },
  92 {
  93         "meta access, test6",
  94         .insns = {
  95         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
  96                     offsetof(struct xdp_md, data_meta)),
  97         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
  98         BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
  99         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
 100         BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
 101         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
 102         BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_0, 1),
 103         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
 104         BPF_MOV64_IMM(BPF_REG_0, 0),
 105         BPF_EXIT_INSN(),
 106         },
 107         .result = REJECT,
 108         .errstr = "invalid access to packet",
 109         .prog_type = BPF_PROG_TYPE_XDP,
 110 },
 111 {
 112         "meta access, test7",
 113         .insns = {
 114         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 115                     offsetof(struct xdp_md, data_meta)),
 116         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 117         BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
 118         BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
 119         BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
 120         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
 121         BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
 122         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
 123         BPF_MOV64_IMM(BPF_REG_0, 0),
 124         BPF_EXIT_INSN(),
 125         },
 126         .result = ACCEPT,
 127         .prog_type = BPF_PROG_TYPE_XDP,
 128 },
 129 {
 130         "meta access, test8",
 131         .insns = {
 132         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 133                     offsetof(struct xdp_md, data_meta)),
 134         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 135         BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
 136         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xFFFF),
 137         BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
 138         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
 139         BPF_MOV64_IMM(BPF_REG_0, 0),
 140         BPF_EXIT_INSN(),
 141         },
 142         .result = ACCEPT,
 143         .prog_type = BPF_PROG_TYPE_XDP,
 144 },
 145 {
 146         "meta access, test9",
 147         .insns = {
 148         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 149                     offsetof(struct xdp_md, data_meta)),
 150         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 151         BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
 152         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xFFFF),
 153         BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 1),
 154         BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
 155         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
 156         BPF_MOV64_IMM(BPF_REG_0, 0),
 157         BPF_EXIT_INSN(),
 158         },
 159         .result = REJECT,
 160         .errstr = "invalid access to packet",
 161         .prog_type = BPF_PROG_TYPE_XDP,
 162 },
 163 {
 164         "meta access, test10",
 165         .insns = {
 166         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 167                     offsetof(struct xdp_md, data_meta)),
 168         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 169         BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
 170                     offsetof(struct xdp_md, data_end)),
 171         BPF_MOV64_IMM(BPF_REG_5, 42),
 172         BPF_MOV64_IMM(BPF_REG_6, 24),
 173         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_5, -8),
 174         BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_6, -8),
 175         BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_10, -8),
 176         BPF_JMP_IMM(BPF_JGT, BPF_REG_5, 100, 6),
 177         BPF_ALU64_REG(BPF_ADD, BPF_REG_3, BPF_REG_5),
 178         BPF_MOV64_REG(BPF_REG_5, BPF_REG_3),
 179         BPF_MOV64_REG(BPF_REG_6, BPF_REG_2),
 180         BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 8),
 181         BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_5, 1),
 182         BPF_LDX_MEM(BPF_B, BPF_REG_2, BPF_REG_2, 0),
 183         BPF_MOV64_IMM(BPF_REG_0, 0),
 184         BPF_EXIT_INSN(),
 185         },
 186         .result = REJECT,
 187         .errstr = "invalid access to packet",
 188         .prog_type = BPF_PROG_TYPE_XDP,
 189 },
 190 {
 191         "meta access, test11",
 192         .insns = {
 193         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 194                     offsetof(struct xdp_md, data_meta)),
 195         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 196         BPF_MOV64_IMM(BPF_REG_5, 42),
 197         BPF_MOV64_IMM(BPF_REG_6, 24),
 198         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_5, -8),
 199         BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_6, -8),
 200         BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_10, -8),
 201         BPF_JMP_IMM(BPF_JGT, BPF_REG_5, 100, 6),
 202         BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_5),
 203         BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
 204         BPF_MOV64_REG(BPF_REG_6, BPF_REG_2),
 205         BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 8),
 206         BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_3, 1),
 207         BPF_LDX_MEM(BPF_B, BPF_REG_5, BPF_REG_5, 0),
 208         BPF_MOV64_IMM(BPF_REG_0, 0),
 209         BPF_EXIT_INSN(),
 210         },
 211         .result = ACCEPT,
 212         .prog_type = BPF_PROG_TYPE_XDP,
 213 },
 214 {
 215         "meta access, test12",
 216         .insns = {
 217         BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
 218                     offsetof(struct xdp_md, data_meta)),
 219         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data)),
 220         BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
 221                     offsetof(struct xdp_md, data_end)),
 222         BPF_MOV64_REG(BPF_REG_5, BPF_REG_3),
 223         BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 16),
 224         BPF_JMP_REG(BPF_JGT, BPF_REG_5, BPF_REG_4, 5),
 225         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_3, 0),
 226         BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
 227         BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 16),
 228         BPF_JMP_REG(BPF_JGT, BPF_REG_5, BPF_REG_3, 1),
 229         BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
 230         BPF_MOV64_IMM(BPF_REG_0, 0),
 231         BPF_EXIT_INSN(),
 232         },
 233         .result = ACCEPT,
 234         .prog_type = BPF_PROG_TYPE_XDP,
 235 },

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