Re: [Patch bpf v3 3/4] net: implement ->sock_is_readable() for UDP and AF_UNIX
flat view
From: John Fastabend <john.fastabend@gmail.com>
Date: 2021-10-08 15:26:57
Also in:
bpf
Cong Wang wrote:
On Thu, Oct 7, 2021 at 1:00 PM Daniel Borkmann [off-list ref] wrote:quoted
On 10/2/21 2:37 AM, Cong Wang wrote:quoted
From: Cong Wang <redacted> Yucong noticed we can't poll() sockets in sockmap even when they are the destination sockets of redirections. This is because we never poll any psock queues in ->poll(), except for TCP. With ->sock_is_readable() now we can overwrite >sock_is_readable(), invoke and implement it for both UDP and AF_UNIX sockets. Reported-by: Yucong Sun <redacted> Cc: John Fastabend <john.fastabend@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Jakub Sitnicki <jakub@cloudflare.com> Cc: Lorenz Bauer <redacted> Signed-off-by: Cong Wang <redacted> --- net/ipv4/udp.c | 2 ++ net/ipv4/udp_bpf.c | 1 + net/unix/af_unix.c | 4 ++++ net/unix/unix_bpf.c | 2 ++ 4 files changed, 9 insertions(+)diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 2a7825a5b842..4a7e15a43a68 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c@@ -2866,6 +2866,8 @@ __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait) !(sk->sk_shutdown & RCV_SHUTDOWN) && first_packet_length(sk) == -1) mask &= ~(EPOLLIN | EPOLLRDNORM); + if (sk_is_readable(sk)) + mask |= EPOLLIN | EPOLLRDNORM;udp_poll() has this extra logic around first_packet_length() which drops all bad csum'ed skbs. How does this stand in relation to sk_msg_is_readable()? Is this a concern as well there? Maybe makes sense to elaborate a bit more in the commit message for context / future reference.We don't validate UDP checksums on sockmap RX path, so it is okay to leave it as it is, but it is worth a comment like you suggest. I will add a comment in this code. If we really need to validate the checksum, it should be addressed in a separate patch(set), not in this one. Thanks.
We should validate the checksum before creating the sk_msg so that any parsers running on top of UDP don't parse a bad checksum payload or pass a bad checksum up to user space. I thought there would be a check in the read_sock side, but I didn't see it.