Skip to contentSkip to conversation

bpf: sockmap: don't attach programs to UDP sockets

PATCH In review Lorenz Bauer 3 participants 3 messages Jun 11, 2020 – Jun 12, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: sockmap: don't attach programs to UDP sockets

The stream parser infrastructure isn't set up to deal with UDP sockets, so we mustn't try to attach programs to them.

I remember making this change at some point, but I must have lost it while rebasing or something similar.

Fixes 7b98cd42b049 ("bpf: sockmap: Add UDP support")
---
 net/core/sock_map.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/core/sock_map.c +6 -4
index 00a26cf2cfe9..35cea36f3892 100644
@@ -424,10 +424,7 @@ static int sock_map_get_next_key(struct bpf_map *map, void *key, void *next)
 	return 0;
 }
 
-static bool sock_map_redirect_allowed(const struct sock *sk)
-{
-	return sk->sk_state != TCP_LISTEN;
-}
+static bool sock_map_redirect_allowed(const struct sock *sk);
 
 static int sock_map_update_common(struct bpf_map *map, u32 idx,
 				  struct sock *sk, u64 flags)
@@ -508,6 +505,11 @@ static bool sk_is_udp(const struct sock *sk)
 	       sk->sk_protocol == IPPROTO_UDP;
 }
 
+static bool sock_map_redirect_allowed(const struct sock *sk)
+{
+	return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;
+}
+
 static bool sock_map_sk_is_suitable(const struct sock *sk)
 {
 	return sk_is_tcp(sk) || sk_is_udp(sk);
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 30 lines · On Thu, 11 Jun 2020 18:25:20 +0100 Lorenz Bauer <[email protected]> wrote:

The stream parser infrastructure isn't set up to deal with UDP sockets, so we mustn't try to attach programs to them.

I remember making this change at some point, but I must have lost it while rebasing or something similar.

Fixes 7b98cd42b049 ("bpf: sockmap: Add UDP support")
---
 net/core/sock_map.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/core/sock_map.c +1 -4
index 00a26cf2cfe9..35cea36f3892 100644
@@ -424,10 +424,7 @@ static int sock_map_get_next_key(struct bpf_map *map, void *key, void *next)
 	return 0;
 }
 
-static bool sock_map_redirect_allowed(const struct sock *sk)
-{
-	return sk->sk_state != TCP_LISTEN;
-}
+static bool sock_map_redirect_allowed(const struct sock *sk);
 
 static int sock_map_update_common(struct bpf_map *map, u32 idx,
 				  struct sock *sk, u64 flags)
@@ -508,6 +505,11 @@ static bool sk_is_udp(const struct sock *sk)
 	       sk->sk_protocol == IPPROTO_UDP;

net/core/sock_map.c static bool sk_is_udp(const struct sock *sk) · line 515

Quoted 10 lines
net/core/sock_map.c +5 -0
 }
 
+static bool sock_map_redirect_allowed(const struct sock *sk)
+{
+	return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;
+}
+
 static bool sock_map_sk_is_suitable(const struct sock *sk)
 {
 	return sk_is_tcp(sk) || sk_is_udp(sk);
maintainer Acked-by
#2 lore raw
Quoted 35 lines · Jakub Sitnicki
Quoted 32 lines · On Thu, 11 Jun 2020 18:25:20 +0100 Lorenz Bauer <[email protected]> wrote:

The stream parser infrastructure isn't set up to deal with UDP sockets, so we mustn't try to attach programs to them.

I remember making this change at some point, but I must have lost it while rebasing or something similar.

Fixes 7b98cd42b049 ("bpf: sockmap: Add UDP support")
---
 net/core/sock_map.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/core/sock_map.c +1 -4
index 00a26cf2cfe9..35cea36f3892 100644
@@ -424,10 +424,7 @@ static int sock_map_get_next_key(struct bpf_map *map, void *key, void *next)
 	return 0;
 }
 
-static bool sock_map_redirect_allowed(const struct sock *sk)
-{
-	return sk->sk_state != TCP_LISTEN;
-}
+static bool sock_map_redirect_allowed(const struct sock *sk);
 
 static int sock_map_update_common(struct bpf_map *map, u32 idx,
 				  struct sock *sk, u64 flags)
@@ -508,6 +505,11 @@ static bool sk_is_udp(const struct sock *sk)
 	       sk->sk_protocol == IPPROTO_UDP;
 }
 
Quoted 10 lines

net/core/sock_map.c static bool sk_is_udp(const struct sock *sk) · line 515

Quoted 8 lines
net/core/sock_map.c +5 -0
+static bool sock_map_redirect_allowed(const struct sock *sk)
+{
+	return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;
+}
+
 static bool sock_map_sk_is_suitable(const struct sock *sk)
 {
 	return sk_is_tcp(sk) || sk_is_udp(sk);

Thanks.