From: Jakub Sitnicki <jakub@cloudflare.com>
To: Kui-Feng Lee <sinquersw@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
kernel-team@cloudflare.com, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Cong Wang <cong.wang@bytedance.com>
Subject: Re: [PATCH bpf] bpf, sockmap: Reject sk_msg egress redirects to non-TCP sockets
Date: Wed, 20 Sep 2023 22:59:58 +0200 [thread overview]
Message-ID: <87wmwk7dy5.fsf@cloudflare.com> (raw)
In-Reply-To: <1224b3f1-4b2a-3c49-5f29-cfce0652ba94@gmail.com>
On Wed, Sep 20, 2023 at 11:19 AM -07, Kui-Feng Lee wrote:
> On 9/20/23 03:20, Jakub Sitnicki wrote:
>> 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
next prev parent reply other threads:[~2023-09-20 21:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 10:20 [PATCH bpf] bpf, sockmap: Reject sk_msg egress redirects to non-TCP sockets Jakub Sitnicki
2023-09-20 18:19 ` Kui-Feng Lee
2023-09-20 20:59 ` Jakub Sitnicki [this message]
2023-09-20 21:11 ` Kui-Feng Lee
2023-09-25 18:27 ` John Fastabend
2023-09-29 15:20 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmwk7dy5.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=sinquersw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox