1 #define BPF_SOCK_ADDR_STORE(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_STORE(user_ip6, 0, ACCEPT,
18 		    NULL),
19 BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT,
20 		    "invalid bpf_context access off=12 size=8"),
21 BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT,
22 		    NULL),
23 BPF_SOCK_ADDR_STORE(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_STORE(msg_src_ip6, 0, REJECT,
28 		    "invalid bpf_context access off=44 size=8"),
29 BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT,
30 		    NULL),
31 BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT,
32 		    "invalid bpf_context access off=52 size=8"),
33 BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT,
34 		    "invalid bpf_context access off=56 size=8"),
35 
36 #undef BPF_SOCK_ADDR_STORE
37 
38 #define BPF_SOCK_ADDR_LOAD(field, off, res, err) \
39 { \
40 	"wide load from bpf_sock_addr." #field "[" #off "]", \
41 	.insns = { \
42 	BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, \
43 		    offsetof(struct bpf_sock_addr, field[off])), \
44 	BPF_MOV64_IMM(BPF_REG_0, 1), \
45 	BPF_EXIT_INSN(), \
46 	}, \
47 	.result = res, \
48 	.prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
49 	.expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
50 	.errstr = err, \
51 }
52 
53 /* user_ip6[0] is u64 aligned */
54 BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT,
55 		   NULL),
56 BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT,
57 		   "invalid bpf_context access off=12 size=8"),
58 BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT,
59 		   NULL),
60 BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT,
61 		   "invalid bpf_context access off=20 size=8"),
62 
63 /* msg_src_ip6[0] is _not_ u64 aligned */
64 BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT,
65 		   "invalid bpf_context access off=44 size=8"),
66 BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT,
67 		   NULL),
68 BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT,
69 		   "invalid bpf_context access off=52 size=8"),
70 BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT,
71 		   "invalid bpf_context access off=56 size=8"),
72 
73 #undef BPF_SOCK_ADDR_LOAD
74