Commit b0f3af0b authored by Jordan Rife's avatar Jordan Rife Committed by Alexei Starovoitov

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: default avatarJordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20240510190246.3247730-11-jrife@google.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 8eaf8056
......@@ -490,6 +490,22 @@ static struct sock_addr_test tests[] = {
NULL,
SUCCESS,
},
{
SOCK_ADDR_TEST_BIND,
"bind4: load prog with wrong expected attach type",
bind_v4_prog_load,
bind_v4_prog_destroy,
BPF_CGROUP_INET6_BIND,
&user_ops,
AF_INET,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
SOCK_ADDR_TEST_BIND,
"bind6: bind (stream)",
......@@ -522,6 +538,22 @@ static struct sock_addr_test tests[] = {
NULL,
SUCCESS,
},
{
SOCK_ADDR_TEST_BIND,
"bind6: load prog with wrong expected attach type",
bind_v6_prog_load,
bind_v6_prog_destroy,
BPF_CGROUP_INET4_BIND,
&user_ops,
AF_INET6,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
/* bind - kernel calls */
{
......@@ -622,6 +654,22 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SUCCESS,
},
{
SOCK_ADDR_TEST_CONNECT,
"connect4: load prog with wrong expected attach type",
connect_v4_prog_load,
connect_v4_prog_destroy,
BPF_CGROUP_INET6_CONNECT,
&user_ops,
AF_INET,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
SOCK_ADDR_TEST_CONNECT,
"connect6: connect (stream)",
......@@ -654,6 +702,22 @@ static struct sock_addr_test tests[] = {
SRC6_REWRITE_IP,
SUCCESS,
},
{
SOCK_ADDR_TEST_CONNECT,
"connect6: load prog with wrong expected attach type",
connect_v6_prog_load,
connect_v6_prog_destroy,
BPF_CGROUP_INET4_CONNECT,
&user_ops,
AF_INET6,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
SOCK_ADDR_TEST_CONNECT,
"connect_unix: connect (stream)",
......@@ -786,6 +850,22 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SYSCALL_EPERM,
},
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg4: load prog with wrong expected attach type",
sendmsg_v4_prog_load,
sendmsg_v4_prog_destroy,
BPF_CGROUP_UDP6_SENDMSG,
&user_ops,
AF_INET,
SOCK_DGRAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg6: sendmsg (dgram)",
......@@ -866,6 +946,22 @@ static struct sock_addr_test tests[] = {
SRC6_REWRITE_IP,
SUCCESS,
},
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg6: load prog with wrong expected attach type",
sendmsg_v6_prog_load,
sendmsg_v6_prog_destroy,
BPF_CGROUP_UDP4_SENDMSG,
&user_ops,
AF_INET6,
SOCK_DGRAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
SOCK_ADDR_TEST_SENDMSG,
"sendmsg_unix: sendmsg (dgram)",
......
......@@ -97,20 +97,6 @@ static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
static struct sock_addr_test tests[] = {
/* bind */
{
"bind4: load prog with wrong expected attach type",
bind4_prog_load,
BPF_CGROUP_INET6_BIND,
BPF_CGROUP_INET4_BIND,
AF_INET,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"bind4: attach prog with wrong attach type",
bind4_prog_load,
......@@ -125,20 +111,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"bind6: load prog with wrong expected attach type",
bind6_prog_load,
BPF_CGROUP_INET4_BIND,
BPF_CGROUP_INET6_BIND,
AF_INET6,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"bind6: attach prog with wrong attach type",
bind6_prog_load,
......@@ -155,20 +127,6 @@ static struct sock_addr_test tests[] = {
},
/* connect */
{
"connect4: load prog with wrong expected attach type",
connect4_prog_load,
BPF_CGROUP_INET6_CONNECT,
BPF_CGROUP_INET4_CONNECT,
AF_INET,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"connect4: attach prog with wrong attach type",
connect4_prog_load,
......@@ -183,20 +141,6 @@ static struct sock_addr_test tests[] = {
NULL,
ATTACH_REJECT,
},
{
"connect6: load prog with wrong expected attach type",
connect6_prog_load,
BPF_CGROUP_INET4_CONNECT,
BPF_CGROUP_INET6_CONNECT,
AF_INET6,
SOCK_STREAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"connect6: attach prog with wrong attach type",
connect6_prog_load,
......@@ -213,20 +157,6 @@ static struct sock_addr_test tests[] = {
},
/* sendmsg */
{
"sendmsg4: load prog with wrong expected attach type",
sendmsg4_rw_asm_prog_load,
BPF_CGROUP_UDP6_SENDMSG,
BPF_CGROUP_UDP4_SENDMSG,
AF_INET,
SOCK_DGRAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"sendmsg4: attach prog with wrong attach type",
sendmsg4_rw_asm_prog_load,
......@@ -255,20 +185,6 @@ static struct sock_addr_test tests[] = {
SRC4_REWRITE_IP,
SUCCESS,
},
{
"sendmsg6: load prog with wrong expected attach type",
sendmsg6_rw_asm_prog_load,
BPF_CGROUP_UDP4_SENDMSG,
BPF_CGROUP_UDP6_SENDMSG,
AF_INET6,
SOCK_DGRAM,
NULL,
0,
NULL,
0,
NULL,
LOAD_REJECT,
},
{
"sendmsg6: attach prog with wrong attach type",
sendmsg6_rw_asm_prog_load,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment