]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Adapt sockmap update error handling
authorMichal Luczaj <mhal@rbox.co>
Tue, 7 Jul 2026 04:23:58 +0000 (06:23 +0200)
committerKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 15 Jul 2026 08:34:14 +0000 (10:34 +0200)
Update sockmap_listen to accommodate the recent change in sockmap that
rejects unbound UDP sockets.

TCP: Reject unbound and bound (unless established or listening).
UDP: Accept only bound sockets.

While at it, migrate to ASSERT_* and enforce reverse xmas tree.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/20260707-sockmap-lookup-udp-leak-v4-3-f878346f27ab@rbox.co
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c

index cc0c68bab907964401da88ba680c6d745952d799..1c96a3cf4b979223d4c6cb78502cbe2b35641af9 100644 (file)
@@ -53,8 +53,8 @@ static void test_insert_opened(struct test_sockmap_listen *skel __always_unused,
                               int family, int sotype, int mapfd)
 {
        u32 key = 0;
-       u64 value;
        int err, s;
+       u64 value;
 
        s = xsocket(family, sotype, 0);
        if (s == -1)
@@ -63,11 +63,8 @@ static void test_insert_opened(struct test_sockmap_listen *skel __always_unused,
        errno = 0;
        value = s;
        err = bpf_map_update_elem(mapfd, &key, &value, BPF_NOEXIST);
-       if (sotype == SOCK_STREAM) {
-               if (!err || errno != EOPNOTSUPP)
-                       FAIL_ERRNO("map_update: expected EOPNOTSUPP");
-       } else if (err)
-               FAIL_ERRNO("map_update: expected success");
+       ASSERT_ERR(err, "map_update");
+       ASSERT_EQ(errno, EOPNOTSUPP, "errno");
        xclose(s);
 }
 
@@ -77,8 +74,8 @@ static void test_insert_bound(struct test_sockmap_listen *skel __always_unused,
        struct sockaddr_storage addr;
        socklen_t len = 0;
        u32 key = 0;
-       u64 value;
        int err, s;
+       u64 value;
 
        init_addr_loopback(family, &addr, &len);
 
@@ -93,8 +90,12 @@ static void test_insert_bound(struct test_sockmap_listen *skel __always_unused,
        errno = 0;
        value = s;
        err = bpf_map_update_elem(mapfd, &key, &value, BPF_NOEXIST);
-       if (!err || errno != EOPNOTSUPP)
-               FAIL_ERRNO("map_update: expected EOPNOTSUPP");
+       if (sotype == SOCK_STREAM) {
+               ASSERT_ERR(err, "map_update");
+               ASSERT_EQ(errno, EOPNOTSUPP, "errno");
+       } else {
+               ASSERT_OK(err, "map_update");
+       }
 close:
        xclose(s);
 }
@@ -1289,7 +1290,7 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map,
                /* insert */
                TEST(test_insert_invalid),
                TEST(test_insert_opened),
-               TEST(test_insert_bound, SOCK_STREAM),
+               TEST(test_insert_bound),
                TEST(test_insert),
                /* delete */
                TEST(test_delete_after_insert),