]> git.dujemihanovic.xyz Git - linux.git/commitdiff
selftests/bpf: Migrate expected_attach_type tests
authorJordan Rife <jrife@google.com>
Fri, 10 May 2024 19:02:27 +0000 (14:02 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 13 May 2024 00:10:42 +0000 (17:10 -0700)
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>
tools/testing/selftests/bpf/prog_tests/sock_addr.c
tools/testing/selftests/bpf/test_sock_addr.c

index e3c450d11b9ef467d8cd55bbcb78d9b6a834825b..8c7c56f997549877d3056b2409e0b04fd2b45de2 100644 (file)
@@ -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)",
index 85fb2a793be501e4905c06bdb520e086ae3f6832..4ecbc72477f1ff916f5aeab0c298e0bac6c6efb6 100644 (file)
@@ -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,