selftests/bpf: add verifier tests for wide stores
[muen/linux.git] / tools / testing / selftests / bpf / verifier / wide_store.c
1 #define BPF_SOCK_ADDR(field, off, res, err) \
2 { \
3         "wide store to bpf_sock_addr." #field "[" #off "]", \
4         .insns = { \
5         BPF_MOV64_IMM(BPF_REG_0, 1), \
6         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, \
7                     offsetof(struct bpf_sock_addr, field[off])), \
8         BPF_EXIT_INSN(), \
9         }, \
10         .result = res, \
11         .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
12         .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
13         .errstr = err, \
14 }
15
16 /* user_ip6[0] is u64 aligned */
17 BPF_SOCK_ADDR(user_ip6, 0, ACCEPT,
18               NULL),
19 BPF_SOCK_ADDR(user_ip6, 1, REJECT,
20               "invalid bpf_context access off=12 size=8"),
21 BPF_SOCK_ADDR(user_ip6, 2, ACCEPT,
22               NULL),
23 BPF_SOCK_ADDR(user_ip6, 3, REJECT,
24               "invalid bpf_context access off=20 size=8"),
25
26 /* msg_src_ip6[0] is _not_ u64 aligned */
27 BPF_SOCK_ADDR(msg_src_ip6, 0, REJECT,
28               "invalid bpf_context access off=44 size=8"),
29 BPF_SOCK_ADDR(msg_src_ip6, 1, ACCEPT,
30               NULL),
31 BPF_SOCK_ADDR(msg_src_ip6, 2, REJECT,
32               "invalid bpf_context access off=52 size=8"),
33 BPF_SOCK_ADDR(msg_src_ip6, 3, REJECT,
34               "invalid bpf_context access off=56 size=8"),
35
36 #undef BPF_SOCK_ADDR