Thread (6 messages) 6 messages, 4 authors, 2023-09-29

Re: [PATCH bpf] bpf, sockmap: Reject sk_msg egress redirects to non-TCP sockets

From: Jakub Sitnicki <jakub@cloudflare.com>
Date: 2023-09-20 21:05:43
Also in: bpf

On Wed, Sep 20, 2023 at 11:19 AM -07, Kui-Feng Lee wrote:
On 9/20/23 03:20, Jakub Sitnicki wrote:
quoted
diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index cb11750b1df5..4292c2ed1828 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -668,6 +668,8 @@ BPF_CALL_4(bpf_msg_redirect_map, struct sk_msg *, msg,
  	sk = __sock_map_lookup_elem(map, key);
  	if (unlikely(!sk || !sock_map_redirect_allowed(sk)))
  		return SK_DROP;
+	if (!(flags & BPF_F_INGRESS) && !sk_is_tcp(sk))
+		return SK_DROP;
    	msg->flags = flags;
  	msg->sk_redir = sk;
@@ -1267,6 +1269,8 @@ BPF_CALL_4(bpf_msg_redirect_hash, struct sk_msg *, msg,
  	sk = __sock_hash_lookup_elem(map, key);
  	if (unlikely(!sk || !sock_map_redirect_allowed(sk)))
  		return SK_DROP;
+	if (!(flags & BPF_F_INGRESS) && !sk_is_tcp(sk))
+		return SK_DROP;
    	msg->flags = flags;
  	msg->sk_redir = sk;
Just be curious! Can it happen to other socket types?
I mean to redirect a msg from a sk of any type to one of another type.
Today sk_msg redirects are implemented only for tcp4 and tcp6.

Here's a full matrix of what redirects are supported [1].

[1] https://gist.github.com/jsitnicki/578fdd614d181bed2b02922b17972b4e
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help