Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Nikolay Aleksandrov
Mon, 23 Nov 2026 08:41
[PATCH bpf 0/2] bpf, net: fix assigned socket mismatches
Author: Nikolay Aleksandrov
Date: Mon, 23 Nov 2026 08:41
Date: Mon, 23 Nov 2026 08:41
40 lines
12484 bytes
12484 bytes
Hi, Patch 01 fixes various mismatches (protocol, netns etc) that can happen with assigned sockets which can lead to different corruptions. Patch 02 exercises such mismatches for IPv4 and IPv6. For more information please check the commit messages. The problem was found during LLM review of the sk assign egress patch-set. Cheers, Nik CC: David S. Miller <davem@davemloft.net> CC: Eric Dumazet <edumazet@kernel.org> CC: Jakub Kicinski <kuba@kernel.org> CC: Paolo Abeni <pabeni@redhat.com> CC: Simon Horman <horms@kernel.org> CC: Kuniyuki Iwashima <kuniyu@google.com> CC: Willem de Bruijn <willemdebruijn.kernel@gmail.com> CC: Martin KaFai Lau <kafai@fb.com> CC: Alexei Starovoitov <ast@kernel.org> CC: Daniel Borkmann <daniel@iogearbox.net> CC: John Fastabend <john.fastabend@gmail.com> CC: netdev@vger.kernel.org Nikolay Aleksandrov (2): bpf, net: validate assigned socket on receive selftests/bpf: Test assigning a TCP listener to a UDP datagram include/net/inet6_hashtables.h | 33 ++++++++++++----- include/net/inet_hashtables.h | 34 +++++++++++++----- include/net/inet_sock.h | 2 ++ net/ipv4/inet_hashtables.c | 13 +++++++ net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 2 +- .../selftests/bpf/prog_tests/sk_assign.c | 36 +++++++++++++++++++ .../selftests/bpf/progs/test_sk_assign.c | 2 +- 8 files changed, 105 insertions(+), 19 deletions(-) -- 2.47.3
[PATCH bpf 2/2] selftests/bpf: test assigning a TCP listener to a UDP datagram
Author: Nikolay Aleksandrov
Date: Mon, 23 Nov 2026 08:41
Date: Mon, 23 Nov 2026 08:41
88 lines
14233 bytes
14233 bytes
Assign the TCP listener from server_map to a UDP datagram for an unbound
port. Without "bpf, net: validate assigned socket on receive" UDP receive
uses the TCP socket and the kernel crashes. With it the datagram gets the
normal lookup and the client sees ECONNREFUSED. Let packets the program
does not parse pass, so the ICMP error reaches the client.
Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
---
CC: Martin KaFai Lau <kafai@fb.com>
CC: Alexei Starovoitov <ast@kernel.org>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: John Fastabend <john.fastabend@gmail.com>
CC: netdev@vger.kernel.org
.../selftests/bpf/prog_tests/sk_assign.c | 36 +++++++++++++++++++
.../selftests/bpf/progs/test_sk_assign.c | 2 +-
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
index 10a0ab954b8a..804087a19aa9 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
@@ -199,6 +199,37 @@ prepare_addr(struct sockaddr *addr, int family, __u16 port, bool rewrite_addr)
}
}
+static void
+run_udp_to_tcp_listener(int server_map, int family)
+{
+ struct sockaddr_storage addr;
+ char buf[] = "testing";
+ const int zero = 0;
+ int client = -1;
+ socklen_t len;
+ __s64 server;
+
+ len = family == AF_INET ? sizeof(struct sockaddr_in) :
+ sizeof(struct sockaddr_in6);
+ prepare_addr((struct sockaddr *)&addr, family, BIND_PORT, false);
+ server = start_server_addr(SOCK_STREAM, &addr, len, NULL);
+ if (!ASSERT_GE(server, 0, "start_server_addr"))
+ return;
+ if (!ASSERT_OK(bpf_map_update_elem(server_map, &zero, &server, BPF_ANY),
+ "update_server_map"))
+ goto out;
+
+ prepare_addr((struct sockaddr *)&addr, family, CONNECT_PORT, false);
+ client = connect_to_addr(SOCK_DGRAM, &addr, len, NULL);
+ if (ASSERT_GE(client, 0, "connect_to_addr") &&
+ ASSERT_EQ(write(client, buf, sizeof(buf)), sizeof(buf), "write") &&
+ ASSERT_LT(recv(client, buf, sizeof(buf), 0), 0, "recv"))
+ ASSERT_EQ(errno, ECONNREFUSED, "recv_errno");
+ close(client);
+out:
+ close(server);
+}
+
struct test_sk_cfg {
const char *name;
int family;
@@ -255,6 +286,11 @@ void test_sk_assign(void)
goto cleanup;
}
+ if (test__start_subtest("ipv4 udp to tcp listener"))
+ run_udp_to_tcp_listener(server_map, AF_INET);
+ if (test__start_subtest("ipv6 udp to tcp listener"))
+ run_udp_to_tcp_listener(server_map, AF_INET6);
+
for (i = 0; i < ARRAY_SIZE(tests) && !READ_ONCE(stop); i++) {
struct test_sk_cfg *test = &tests[i];
const struct sockaddr *addr;
diff --git a/tools/testing/selftests/bpf/progs/test_sk_assign.c b/tools/testing/selftests/bpf/progs/test_sk_assign.c
index 3079244c7f96..4e8ae7b7d297 100644
--- a/tools/testing/selftests/bpf/progs/test_sk_assign.c
+++ b/tools/testing/selftests/bpf/progs/test_sk_assign.c
@@ -178,7 +178,7 @@ int bpf_sk_assign_test(struct __sk_buff *skb)
tuple = get_tuple(skb, &ipv4, &tcp);
if (!tuple)
- return TC_ACT_SHOT;
+ return TC_ACT_OK;
/* Note that the verifier socket return type for bpf_skc_lookup_tcp()
* differs from bpf_sk_lookup_udp(), so even though the C-level type is
--
2.47.3
Re: [PATCH bpf 0/2] bpf, net: fix assigned socket mismatches
Author: Nikolay Aleksandrov
Date: Mon, 23 Nov 2026 09:40
Date: Mon, 23 Nov 2026 09:40
48 lines
12820 bytes
12820 bytes
On 23/11/2026 10:41, Nikolay Aleksandrov wrote: > Hi, > Patch 01 fixes various mismatches (protocol, netns etc) that can happen > with assigned sockets which can lead to different corruptions. Patch 02 > exercises such mismatches for IPv4 and IPv6. For more information please > check the commit messages. The problem was found during LLM review of > the sk assign egress patch-set. > > Cheers, > Nik > > CC: David S. Miller <davem@davemloft.net> > CC: Eric Dumazet <edumazet@kernel.org> > CC: Jakub Kicinski <kuba@kernel.org> > CC: Paolo Abeni <pabeni@redhat.com> > CC: Simon Horman <horms@kernel.org> > CC: Kuniyuki Iwashima <kuniyu@google.com> > CC: Willem de Bruijn <willemdebruijn.kernel@gmail.com> > CC: Martin KaFai Lau <kafai@fb.com> > CC: Alexei Starovoitov <ast@kernel.org> > CC: Daniel Borkmann <daniel@iogearbox.net> > CC: John Fastabend <john.fastabend@gmail.com> > CC: netdev@vger.kernel.org > > Nikolay Aleksandrov (2): > bpf, net: validate assigned socket on receive > selftests/bpf: Test assigning a TCP listener to a UDP datagram > > include/net/inet6_hashtables.h | 33 ++++++++++++----- > include/net/inet_hashtables.h | 34 +++++++++++++----- > include/net/inet_sock.h | 2 ++ > net/ipv4/inet_hashtables.c | 13 +++++++ > net/ipv4/udp.c | 2 +- > net/ipv6/udp.c | 2 +- > .../selftests/bpf/prog_tests/sk_assign.c | 36 +++++++++++++++++++ > .../selftests/bpf/progs/test_sk_assign.c | 2 +- > 8 files changed, 105 insertions(+), 19 deletions(-) > Sashiko found a few more mismatch cases that can happen, I will address them in v2. Thanks, Nik --- pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads