* [PATCH bpf v3 1/4] selftests/bpf: Ensure UDP sockets are bound
2026-07-01 23:28 [PATCH bpf v3 0/4] bpf, sockmap: Fix sockmap leaking UDP socks Michal Luczaj
@ 2026-07-01 23:28 ` Michal Luczaj
2026-07-02 10:35 ` Jakub Sitnicki
2026-07-01 23:28 ` [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update Michal Luczaj
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Michal Luczaj @ 2026-07-01 23:28 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jakub Sitnicki, Jiayuan Chen, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn, David S. Miller,
Jakub Kicinski, Simon Horman, Cong Wang
Cc: Michal Luczaj, bpf, linux-kselftest, linux-kernel, netdev
Update sockmap_basic tests to bind sockets before they are used. This
accommodates the recent change in sockmap that rejects unbound UDP sockets.
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
index cb3229711f93..2d22a9058a8e 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
@@ -853,7 +853,7 @@ static void test_sockmap_many_socket(void)
return;
}
- udp = xsocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ udp = socket_loopback(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK);
if (udp < 0) {
close(dgram);
close(tcp);
@@ -922,7 +922,7 @@ static void test_sockmap_many_maps(void)
return;
}
- udp = xsocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ udp = socket_loopback(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK);
if (udp < 0) {
close(dgram);
close(tcp);
@@ -993,7 +993,7 @@ static void test_sockmap_same_sock(void)
return;
}
- udp = xsocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ udp = socket_loopback(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK);
if (udp < 0) {
close(dgram);
close(tcp);
--
2.54.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 1/4] selftests/bpf: Ensure UDP sockets are bound
2026-07-01 23:28 ` [PATCH bpf v3 1/4] selftests/bpf: Ensure UDP sockets are bound Michal Luczaj
@ 2026-07-02 10:35 ` Jakub Sitnicki
0 siblings, 0 replies; 14+ messages in thread
From: Jakub Sitnicki @ 2026-07-02 10:35 UTC (permalink / raw)
To: Michal Luczaj
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jiayuan Chen, Eric Dumazet, Kuniyuki Iwashima,
Paolo Abeni, Willem de Bruijn, David S. Miller, Jakub Kicinski,
Simon Horman, Cong Wang, bpf, linux-kselftest, linux-kernel,
netdev
On Thu, Jul 02, 2026 at 01:28 AM +02, Michal Luczaj wrote:
> Update sockmap_basic tests to bind sockets before they are used. This
> accommodates the recent change in sockmap that rejects unbound UDP sockets.
>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update
2026-07-01 23:28 [PATCH bpf v3 0/4] bpf, sockmap: Fix sockmap leaking UDP socks Michal Luczaj
2026-07-01 23:28 ` [PATCH bpf v3 1/4] selftests/bpf: Ensure UDP sockets are bound Michal Luczaj
@ 2026-07-01 23:28 ` Michal Luczaj
2026-07-01 23:55 ` sashiko-bot
2026-07-01 23:28 ` [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling Michal Luczaj
2026-07-01 23:28 ` [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update Michal Luczaj
3 siblings, 1 reply; 14+ messages in thread
From: Michal Luczaj @ 2026-07-01 23:28 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jakub Sitnicki, Jiayuan Chen, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn, David S. Miller,
Jakub Kicinski, Simon Horman, Cong Wang
Cc: Michal Luczaj, bpf, linux-kselftest, linux-kernel, netdev
UDP sockets get SOCK_RCU_FREE set when (auto-)bound. This means
sk_is_refcounted(unbound) = true, while sk_is_refcounted(bound) = false.
Because sockmap accepts unbound UDP sockets, a BPF program can increment a
socket's refcount via lookup. If the socket is subsequently bound, the
transition from unbound to bound causes bpf_sk_release() to skip the
decrement of the refcount, causing a memory leak.
unreferenced object 0xffff88810bc2eb40 (size 1984):
comm "test_progs", pid 2451, jiffies 4295320596
hex dump (first 32 bytes):
7f 00 00 01 7f 00 00 01 d2 04 1b b7 04 d2 00 00 ................
02 00 01 40 00 00 00 00 00 00 00 00 00 00 00 00 ...@............
backtrace (crc bdee079d):
kmem_cache_alloc_noprof+0x557/0x660
sk_prot_alloc+0x69/0x240
sk_alloc+0x30/0x460
inet_create+0x2ce/0xf80
__sock_create+0x25b/0x5c0
__sys_socket+0x119/0x1d0
__x64_sys_socket+0x72/0xd0
do_syscall_64+0xa1/0x5f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
Instead of special-casing for refcounted sockets, reject unhashed UDP
sockets during sockmap updates, as there is no benefit to supporting those.
This effectively reverts the commit under Fixes, with two exceptions:
1. sock_map_sk_state_allowed() maintains a fall-through `return true`.
2. In the spirit of commit b8b8315e39ff ("bpf, sockmap: Remove unhash
handler for BPF sockmap usage"), the proto::unhash BPF handler is not
reintroduced.
Historical note: this issue is related to commit 67312adc96b5 ("bpf: reject
unhashed sockets in bpf_sk_assign").
Fixes: 0c48eefae712 ("sock_map: Lift socket state restriction for datagram sockets")
Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
net/core/sock_map.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index c60ba6d292f9..9efbd8ca7db8 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -542,6 +542,8 @@ static bool sock_map_sk_state_allowed(const struct sock *sk)
{
if (sk_is_tcp(sk))
return (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_LISTEN);
+ if (sk_is_udp(sk))
+ return sk_hashed(sk);
if (sk_is_stream_unix(sk))
return (1 << READ_ONCE(sk->sk_state)) & TCPF_ESTABLISHED;
if (sk_is_vsock(sk) &&
--
2.54.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update
2026-07-01 23:28 ` [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update Michal Luczaj
@ 2026-07-01 23:55 ` sashiko-bot
2026-07-02 7:30 ` Michal Luczaj
0 siblings, 1 reply; 14+ messages in thread
From: sashiko-bot @ 2026-07-01 23:55 UTC (permalink / raw)
To: Michal Luczaj; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The refcount leak fixed for UDP sockets by this patch still exists for TCP sockets (and via bpf_sk_lookup_tcp) because bpf_sk_release relies on the mutable SOCK_RCU_FREE flag.
--
commit 120f1940dc9e4cc498f383925d488cf77882caea
Author: Michal Luczaj <mhal@rbox.co>
bpf, sockmap: Reject unhashed UDP sockets on sockmap update
This commit rejects unhashed UDP sockets during sockmap updates to prevent
a memory leak when a socket transitions from unbound to bound. This transition
causes bpf_sk_release() to skip the refcount decrement due to the SOCK_RCU_FREE
flag being set.
> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> index c60ba6d292f9a..9efbd8ca7db83 100644
> --- a/net/core/sock_map.c
> +++ b/net/core/sock_map.c
> @@ -542,6 +542,8 @@ static bool sock_map_sk_state_allowed(const struct sock *sk)
> {
> if (sk_is_tcp(sk))
> return (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_LISTEN);
[Severity: High]
This isn't a bug introduced by this patch, but does the same refcount leak
still exist for TCP sockets?
A BPF program can acquire a reference to a TCP socket in the TCP_ESTABLISHED
state (e.g., via bpf_sk_lookup_tcp or bpf_map_lookup_elem on a sockmap) because
TCP_ESTABLISHED sockets do not have the SOCK_RCU_FREE flag set.
If a user-space thread concurrently calls connect(AF_UNSPEC) to transition the
socket to TCP_CLOSE, followed by listen(), inet_hash() will dynamically set the
SOCK_RCU_FREE flag on the socket.
When the BPF program finishes and calls bpf_sk_release():
net/core/filter.c:bpf_sk_release() {
if (sk && sk_is_refcounted(sk))
sock_gen_put(sk);
return 0;
}
Because the flag was just set, sk_is_refcounted(sk) will dynamically evaluate
to false, skipping sock_gen_put(sk) and permanently leaking the acquired
reference.
> + if (sk_is_udp(sk))
> + return sk_hashed(sk);
> if (sk_is_stream_unix(sk))
> return (1 << READ_ONCE(sk->sk_state)) & TCPF_ESTABLISHED;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702-sockmap-lookup-udp-leak-v3-0-ff8de8782468@rbox.co?part=2
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update
2026-07-01 23:55 ` sashiko-bot
@ 2026-07-02 7:30 ` Michal Luczaj
0 siblings, 0 replies; 14+ messages in thread
From: Michal Luczaj @ 2026-07-02 7:30 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 7/2/26 01:55, sashiko-bot@kernel.org wrote:
> [Severity: High]
> This isn't a bug introduced by this patch, but does the same refcount leak
> still exist for TCP sockets?
>
> A BPF program can acquire a reference to a TCP socket in the TCP_ESTABLISHED
> state (e.g., via bpf_sk_lookup_tcp or bpf_map_lookup_elem on a sockmap) because
> TCP_ESTABLISHED sockets do not have the SOCK_RCU_FREE flag set.
>
> If a user-space thread concurrently calls connect(AF_UNSPEC) to transition the
> socket to TCP_CLOSE, followed by listen(), inet_hash() will dynamically set the
> SOCK_RCU_FREE flag on the socket.
>
> When the BPF program finishes and calls bpf_sk_release():
>
> net/core/filter.c:bpf_sk_release() {
> if (sk && sk_is_refcounted(sk))
> sock_gen_put(sk);
> return 0;
> }
>
> Because the flag was just set, sk_is_refcounted(sk) will dynamically evaluate
> to false, skipping sock_gen_put(sk) and permanently leaking the acquired
> reference.
Yup, a known issue:
https://lore.kernel.org/bpf/e08be4f5-0bd9-4228-843d-86ed20594bac@rbox.co/
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling
2026-07-01 23:28 [PATCH bpf v3 0/4] bpf, sockmap: Fix sockmap leaking UDP socks Michal Luczaj
2026-07-01 23:28 ` [PATCH bpf v3 1/4] selftests/bpf: Ensure UDP sockets are bound Michal Luczaj
2026-07-01 23:28 ` [PATCH bpf v3 2/4] bpf, sockmap: Reject unhashed UDP sockets on sockmap update Michal Luczaj
@ 2026-07-01 23:28 ` Michal Luczaj
2026-07-02 0:00 ` bot+bpf-ci
2026-07-02 10:52 ` Jakub Sitnicki
2026-07-01 23:28 ` [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update Michal Luczaj
3 siblings, 2 replies; 14+ messages in thread
From: Michal Luczaj @ 2026-07-01 23:28 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jakub Sitnicki, Jiayuan Chen, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn, David S. Miller,
Jakub Kicinski, Simon Horman, Cong Wang
Cc: Michal Luczaj, bpf, linux-kselftest, linux-kernel, netdev
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.
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
.../selftests/bpf/prog_tests/sockmap_listen.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index cc0c68bab907..b87118aab7c4 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -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 if (err) {
+ 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),
--
2.54.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling
2026-07-01 23:28 ` [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling Michal Luczaj
@ 2026-07-02 0:00 ` bot+bpf-ci
2026-07-02 7:30 ` Michal Luczaj
2026-07-02 10:52 ` Jakub Sitnicki
1 sibling, 1 reply; 14+ messages in thread
From: bot+bpf-ci @ 2026-07-02 0:00 UTC (permalink / raw)
To: mhal, ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
yonghong.song, jolsa, emil, shuah, john.fastabend, jakub,
jiayuan.chen, edumazet, kuniyu, pabeni, willemb, davem, kuba,
horms, cong.wang
Cc: mhal, bpf, linux-kselftest, linux-kernel, netdev, ast, andrii,
daniel, martin.lau, eddyz87, yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
> index cc0c68bab907..b87118aab7c4 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
[ ... ]
> @@ -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 if (err) {
> + ASSERT_OK(err, "map_update");
> + }
This isn't a bug, but could the UDP branch just be `else ASSERT_OK(err,
"map_update");` — the `if (err)` guard looks redundant since ASSERT_OK is
a no-op on success?
> close:
> xclose(s);
> }
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/28554911192
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling
2026-07-02 0:00 ` bot+bpf-ci
@ 2026-07-02 7:30 ` Michal Luczaj
0 siblings, 0 replies; 14+ messages in thread
From: Michal Luczaj @ 2026-07-02 7:30 UTC (permalink / raw)
To: bot+bpf-ci, ast, daniel, andrii, eddyz87, memxor, martin.lau,
song, yonghong.song, jolsa, emil, shuah, john.fastabend, jakub,
jiayuan.chen, edumazet, kuniyu, pabeni, willemb, davem, kuba,
horms, cong.wang
Cc: bpf, linux-kselftest, linux-kernel, netdev, martin.lau, clm,
ihor.solodrai
On 7/2/26 02:00, bot+bpf-ci@kernel.org wrote:
>> @@ -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 if (err) {
>> + ASSERT_OK(err, "map_update");
>> + }
>
> This isn't a bug, but could the UDP branch just be `else ASSERT_OK(err,
> "map_update");` — the `if (err)` guard looks redundant since ASSERT_OK is
> a no-op on success?
Ugh, sorry. If there are no other comments for this series, I'd happy to
fix it later in bpf-next.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling
2026-07-01 23:28 ` [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling Michal Luczaj
2026-07-02 0:00 ` bot+bpf-ci
@ 2026-07-02 10:52 ` Jakub Sitnicki
1 sibling, 0 replies; 14+ messages in thread
From: Jakub Sitnicki @ 2026-07-02 10:52 UTC (permalink / raw)
To: Michal Luczaj
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jiayuan Chen, Eric Dumazet, Kuniyuki Iwashima,
Paolo Abeni, Willem de Bruijn, David S. Miller, Jakub Kicinski,
Simon Horman, Cong Wang, bpf, linux-kselftest, linux-kernel,
netdev
On Thu, Jul 02, 2026 at 01:28 AM +02, Michal Luczaj wrote:
> 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.
>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update
2026-07-01 23:28 [PATCH bpf v3 0/4] bpf, sockmap: Fix sockmap leaking UDP socks Michal Luczaj
` (2 preceding siblings ...)
2026-07-01 23:28 ` [PATCH bpf v3 3/4] selftests/bpf: Adapt sockmap update error handling Michal Luczaj
@ 2026-07-01 23:28 ` Michal Luczaj
2026-07-01 23:34 ` sashiko-bot
2026-07-02 11:01 ` Jakub Sitnicki
3 siblings, 2 replies; 14+ messages in thread
From: Michal Luczaj @ 2026-07-01 23:28 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jakub Sitnicki, Jiayuan Chen, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn, David S. Miller,
Jakub Kicinski, Simon Horman, Cong Wang
Cc: Michal Luczaj, bpf, linux-kselftest, linux-kernel, netdev
sockmap now rejects unbound UDP sockets. Adjust test_maps. While at it,
check socket()'s return value.
This effectively reverts commit c39aa2159974 ("bpf, selftests: Fix
test_maps now that sockmap supports UDP").
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
tools/testing/selftests/bpf/test_maps.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index c32da7bd8be2..6a2641ee7897 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -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++) {
--
2.54.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update
2026-07-01 23:28 ` [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update Michal Luczaj
@ 2026-07-01 23:34 ` sashiko-bot
2026-07-02 7:30 ` Michal Luczaj
2026-07-02 11:01 ` Jakub Sitnicki
1 sibling, 1 reply; 14+ messages in thread
From: sashiko-bot @ 2026-07-01 23:34 UTC (permalink / raw)
To: Michal Luczaj; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch uses the deprecated `CHECK()` macro instead of the required `ASSERT_*()` macros.
--
commit 050b7402e55d196faa9ab77dfc6be970046bf275
Author: Michal Luczaj <mhal@rbox.co>
selftests/bpf: Fail unbound UDP on sockmap update
This commit adjusts test_maps to reflect that sockmap now rejects unbound UDP
sockets. It also checks the return value of socket() when creating the test
socket.
> diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
> index c32da7bd8be27..6a2641ee78975 100644
> --- a/tools/testing/selftests/bpf/test_maps.c
> +++ b/tools/testing/selftests/bpf/test_maps.c
[ ... ]
> @@ -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);
[Severity: Low]
This isn't a bug, but should this new code use the modern ASSERT_OK_FD()
macro rather than the deprecated CHECK() macro?
> + 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);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702-sockmap-lookup-udp-leak-v3-0-ff8de8782468@rbox.co?part=4
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update
2026-07-01 23:34 ` sashiko-bot
@ 2026-07-02 7:30 ` Michal Luczaj
0 siblings, 0 replies; 14+ messages in thread
From: Michal Luczaj @ 2026-07-02 7:30 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 7/2/26 01:34, sashiko-bot@kernel.org wrote:
> [ ... ]
>> @@ -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);
>
> [Severity: Low]
> This isn't a bug, but should this new code use the modern ASSERT_OK_FD()
> macro rather than the deprecated CHECK() macro?
It should, but it's a slightly bigger refactor. test_maps.c uses CHECK()
from test_maps.h that conflicts with CHECK() from test_progs.h (where
ASSERT_OK_FD() lives).
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update
2026-07-01 23:28 ` [PATCH bpf v3 4/4] selftests/bpf: Fail unbound UDP on sockmap update Michal Luczaj
2026-07-01 23:34 ` sashiko-bot
@ 2026-07-02 11:01 ` Jakub Sitnicki
1 sibling, 0 replies; 14+ messages in thread
From: Jakub Sitnicki @ 2026-07-02 11:01 UTC (permalink / raw)
To: Michal Luczaj
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
John Fastabend, Jiayuan Chen, Eric Dumazet, Kuniyuki Iwashima,
Paolo Abeni, Willem de Bruijn, David S. Miller, Jakub Kicinski,
Simon Horman, Cong Wang, bpf, linux-kselftest, linux-kernel,
netdev
On Thu, Jul 02, 2026 at 01:28 AM +02, Michal Luczaj wrote:
> sockmap now rejects unbound UDP sockets. Adjust test_maps. While at it,
> check socket()'s return value.
>
> This effectively reverts commit c39aa2159974 ("bpf, selftests: Fix
> test_maps now that sockmap supports UDP").
>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
^ permalink raw reply [flat|nested] 14+ messages in thread