All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH bpf] udp: validate checksum in udp_read_sock()
@ 2021-11-15  4:40 Cong Wang
  2021-11-16 12:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2021-11-15  4:40 UTC (permalink / raw)
  To: netdev
  Cc: bpf, Cong Wang, Daniel Borkmann, John Fastabend, Lorenz Bauer,
	Jakub Sitnicki

From: Cong Wang <cong.wang@bytedance.com>

It turns out the skb's in sock receive queue could have
bad checksums, as both ->poll() and ->recvmsg() validate
checksums. We have to do the same for ->read_sock() path
too before they are redirected in sockmap.

Fixes: d7f571188ecf ("udp: Implement ->read_sock() for sockmap")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/ipv4/udp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 319dd7bbfe33..8bcecdd6aeda 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1807,6 +1807,17 @@ int udp_read_sock(struct sock *sk, read_descriptor_t *desc,
 		skb = skb_recv_udp(sk, 0, 1, &err);
 		if (!skb)
 			return err;
+
+		if (udp_lib_checksum_complete(skb)) {
+			__UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS,
+					IS_UDPLITE(sk));
+			__UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
+					IS_UDPLITE(sk));
+			atomic_inc(&sk->sk_drops);
+			kfree_skb(skb);
+			continue;
+		}
+
 		used = recv_actor(desc, skb, 0, skb->len);
 		if (used <= 0) {
 			if (!copied)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH bpf] udp: validate checksum in udp_read_sock()
  2021-11-15  4:40 [RESEND PATCH bpf] udp: validate checksum in udp_read_sock() Cong Wang
@ 2021-11-16 12:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-16 12:30 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, bpf, cong.wang, daniel, john.fastabend, lmb, jakub

Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Sun, 14 Nov 2021 20:40:06 -0800 you wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> It turns out the skb's in sock receive queue could have
> bad checksums, as both ->poll() and ->recvmsg() validate
> checksums. We have to do the same for ->read_sock() path
> too before they are redirected in sockmap.
> 
> [...]

Here is the summary with links:
  - [RESEND,bpf] udp: validate checksum in udp_read_sock()
    https://git.kernel.org/bpf/bpf/c/099f896f498a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-16 12:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  4:40 [RESEND PATCH bpf] udp: validate checksum in udp_read_sock() Cong Wang
2021-11-16 12:30 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.