Skip to content

Commit b0f3af0

Browse files
jrifeAlexei Starovoitov
authored andcommitted
selftests/bpf: Migrate expected_attach_type tests
Migrates tests from progs/test_sock_addr.c ensuring that programs fail to load when the expected attach type does not match. Signed-off-by: Jordan Rife <jrife@google.com> Link: https://lore.kernel.org/r/20240510190246.3247730-11-jrife@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 8eaf805 commit b0f3af0

2 files changed

Lines changed: 96 additions & 84 deletions

File tree

tools/testing/selftests/bpf/prog_tests/sock_addr.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,22 @@ static struct sock_addr_test tests[] = {
490490
NULL,
491491
SUCCESS,
492492
},
493+
{
494+
SOCK_ADDR_TEST_BIND,
495+
"bind4: load prog with wrong expected attach type",
496+
bind_v4_prog_load,
497+
bind_v4_prog_destroy,
498+
BPF_CGROUP_INET6_BIND,
499+
&user_ops,
500+
AF_INET,
501+
SOCK_STREAM,
502+
NULL,
503+
0,
504+
NULL,
505+
0,
506+
NULL,
507+
LOAD_REJECT,
508+
},
493509
{
494510
SOCK_ADDR_TEST_BIND,
495511
"bind6: bind (stream)",
@@ -522,6 +538,22 @@ static struct sock_addr_test tests[] = {
522538
NULL,
523539
SUCCESS,
524540
},
541+
{
542+
SOCK_ADDR_TEST_BIND,
543+
"bind6: load prog with wrong expected attach type",
544+
bind_v6_prog_load,
545+
bind_v6_prog_destroy,
546+
BPF_CGROUP_INET4_BIND,
547+
&user_ops,
548+
AF_INET6,
549+
SOCK_STREAM,
550+
NULL,
551+
0,
552+
NULL,
553+
0,
554+
NULL,
555+
LOAD_REJECT,
556+
},
525557

526558
/* bind - kernel calls */
527559
{
@@ -622,6 +654,22 @@ static struct sock_addr_test tests[] = {
622654
SRC4_REWRITE_IP,
623655
SUCCESS,
624656
},
657+
{
658+
SOCK_ADDR_TEST_CONNECT,
659+
"connect4: load prog with wrong expected attach type",
660+
connect_v4_prog_load,
661+
connect_v4_prog_destroy,
662+
BPF_CGROUP_INET6_CONNECT,
663+
&user_ops,
664+
AF_INET,
665+
SOCK_STREAM,
666+
NULL,
667+
0,
668+
NULL,
669+
0,
670+
NULL,
671+
LOAD_REJECT,
672+
},
625673
{
626674
SOCK_ADDR_TEST_CONNECT,
627675
"connect6: connect (stream)",
@@ -654,6 +702,22 @@ static struct sock_addr_test tests[] = {
654702
SRC6_REWRITE_IP,
655703
SUCCESS,
656704
},
705+
{
706+
SOCK_ADDR_TEST_CONNECT,
707+
"connect6: load prog with wrong expected attach type",
708+
connect_v6_prog_load,
709+
connect_v6_prog_destroy,
710+
BPF_CGROUP_INET4_CONNECT,
711+
&user_ops,
712+
AF_INET6,
713+
SOCK_STREAM,
714+
NULL,
715+
0,
716+
NULL,
717+
0,
718+
NULL,
719+
LOAD_REJECT,
720+
},
657721
{
658722
SOCK_ADDR_TEST_CONNECT,
659723
"connect_unix: connect (stream)",
@@ -786,6 +850,22 @@ static struct sock_addr_test tests[] = {
786850
SRC4_REWRITE_IP,
787851
SYSCALL_EPERM,
788852
},
853+
{
854+
SOCK_ADDR_TEST_SENDMSG,
855+
"sendmsg4: load prog with wrong expected attach type",
856+
sendmsg_v4_prog_load,
857+
sendmsg_v4_prog_destroy,
858+
BPF_CGROUP_UDP6_SENDMSG,
859+
&user_ops,
860+
AF_INET,
861+
SOCK_DGRAM,
862+
NULL,
863+
0,
864+
NULL,
865+
0,
866+
NULL,
867+
LOAD_REJECT,
868+
},
789869
{
790870
SOCK_ADDR_TEST_SENDMSG,
791871
"sendmsg6: sendmsg (dgram)",
@@ -866,6 +946,22 @@ static struct sock_addr_test tests[] = {
866946
SRC6_REWRITE_IP,
867947
SUCCESS,
868948
},
949+
{
950+
SOCK_ADDR_TEST_SENDMSG,
951+
"sendmsg6: load prog with wrong expected attach type",
952+
sendmsg_v6_prog_load,
953+
sendmsg_v6_prog_destroy,
954+
BPF_CGROUP_UDP4_SENDMSG,
955+
&user_ops,
956+
AF_INET6,
957+
SOCK_DGRAM,
958+
NULL,
959+
0,
960+
NULL,
961+
0,
962+
NULL,
963+
LOAD_REJECT,
964+
},
869965
{
870966
SOCK_ADDR_TEST_SENDMSG,
871967
"sendmsg_unix: sendmsg (dgram)",

tools/testing/selftests/bpf/test_sock_addr.c

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,6 @@ static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
9797

9898
static struct sock_addr_test tests[] = {
9999
/* bind */
100-
{
101-
"bind4: load prog with wrong expected attach type",
102-
bind4_prog_load,
103-
BPF_CGROUP_INET6_BIND,
104-
BPF_CGROUP_INET4_BIND,
105-
AF_INET,
106-
SOCK_STREAM,
107-
NULL,
108-
0,
109-
NULL,
110-
0,
111-
NULL,
112-
LOAD_REJECT,
113-
},
114100
{
115101
"bind4: attach prog with wrong attach type",
116102
bind4_prog_load,
@@ -125,20 +111,6 @@ static struct sock_addr_test tests[] = {
125111
NULL,
126112
ATTACH_REJECT,
127113
},
128-
{
129-
"bind6: load prog with wrong expected attach type",
130-
bind6_prog_load,
131-
BPF_CGROUP_INET4_BIND,
132-
BPF_CGROUP_INET6_BIND,
133-
AF_INET6,
134-
SOCK_STREAM,
135-
NULL,
136-
0,
137-
NULL,
138-
0,
139-
NULL,
140-
LOAD_REJECT,
141-
},
142114
{
143115
"bind6: attach prog with wrong attach type",
144116
bind6_prog_load,
@@ -155,20 +127,6 @@ static struct sock_addr_test tests[] = {
155127
},
156128

157129
/* connect */
158-
{
159-
"connect4: load prog with wrong expected attach type",
160-
connect4_prog_load,
161-
BPF_CGROUP_INET6_CONNECT,
162-
BPF_CGROUP_INET4_CONNECT,
163-
AF_INET,
164-
SOCK_STREAM,
165-
NULL,
166-
0,
167-
NULL,
168-
0,
169-
NULL,
170-
LOAD_REJECT,
171-
},
172130
{
173131
"connect4: attach prog with wrong attach type",
174132
connect4_prog_load,
@@ -183,20 +141,6 @@ static struct sock_addr_test tests[] = {
183141
NULL,
184142
ATTACH_REJECT,
185143
},
186-
{
187-
"connect6: load prog with wrong expected attach type",
188-
connect6_prog_load,
189-
BPF_CGROUP_INET4_CONNECT,
190-
BPF_CGROUP_INET6_CONNECT,
191-
AF_INET6,
192-
SOCK_STREAM,
193-
NULL,
194-
0,
195-
NULL,
196-
0,
197-
NULL,
198-
LOAD_REJECT,
199-
},
200144
{
201145
"connect6: attach prog with wrong attach type",
202146
connect6_prog_load,
@@ -213,20 +157,6 @@ static struct sock_addr_test tests[] = {
213157
},
214158

215159
/* sendmsg */
216-
{
217-
"sendmsg4: load prog with wrong expected attach type",
218-
sendmsg4_rw_asm_prog_load,
219-
BPF_CGROUP_UDP6_SENDMSG,
220-
BPF_CGROUP_UDP4_SENDMSG,
221-
AF_INET,
222-
SOCK_DGRAM,
223-
NULL,
224-
0,
225-
NULL,
226-
0,
227-
NULL,
228-
LOAD_REJECT,
229-
},
230160
{
231161
"sendmsg4: attach prog with wrong attach type",
232162
sendmsg4_rw_asm_prog_load,
@@ -255,20 +185,6 @@ static struct sock_addr_test tests[] = {
255185
SRC4_REWRITE_IP,
256186
SUCCESS,
257187
},
258-
{
259-
"sendmsg6: load prog with wrong expected attach type",
260-
sendmsg6_rw_asm_prog_load,
261-
BPF_CGROUP_UDP4_SENDMSG,
262-
BPF_CGROUP_UDP6_SENDMSG,
263-
AF_INET6,
264-
SOCK_DGRAM,
265-
NULL,
266-
0,
267-
NULL,
268-
0,
269-
NULL,
270-
LOAD_REJECT,
271-
},
272188
{
273189
"sendmsg6: attach prog with wrong attach type",
274190
sendmsg6_rw_asm_prog_load,

0 commit comments

Comments
 (0)