selftests/bpf: Fail unbound UDP on sockmap update

sockmap now rejects unbound UDP sockets. Adjust test_maps. While at it,
check socket()'s return value.

This effectively reverts commit c39aa21599 ("bpf, selftests: Fix
test_maps now that sockmap supports UDP").

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-4-f878346f27ab@rbox.co
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
Michal Luczaj 2026-07-07 06:23:59 +02:00 committed by Kumar Kartikeya Dwivedi
parent 30581eda4a
commit 203b069327
No known key found for this signature in database
GPG Key ID: 472D377B63542F83

View File

@ -759,16 +759,15 @@ static void test_sockmap(unsigned int tasks, void *data)
goto out_sockmap;
}
/* Test update with unsupported UDP socket */
/* Test update with unsupported unbound UDP socket */
udp = socket(AF_INET, SOCK_DGRAM, 0);
i = 0;
err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY);
if (err) {
printf("Failed socket update SOCK_DGRAM '%i:%i'\n",
i, udp);
CHECK(udp < 0, "socket(AF_INET, SOCK_DGRAM)", "errno:%d\n", errno);
err = bpf_map_update_elem(fd, &(int){0}, &udp, BPF_ANY);
close(udp);
if (!err) {
printf("Unexpectedly succeeded unbound UDP update '0:%i'\n", udp);
goto out_sockmap;
}
close(udp);
/* Test update without programs */
for (i = 0; i < 6; i++) {