Skip to contentSkip to conversation

udp: validate checksum in udp_read_sock()

PATCH RESEND Applied Cong Wang 2 participants 2 messages Nov 15, 2021 – Nov 16, 2021

Subsystems (4)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH RESEND 1/1 udp: validate checksum in udp_read_sock()

From: Cong Wang <[email protected]>

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")
Cc Lorenz Bauer <[email protected]>
Cc Jakub Sitnicki <[email protected]>
---
 net/ipv4/udp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/ipv4/udp.c +11 -0
index 319dd7bbfe33..8bcecdd6aeda 100644
@@ -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)
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Sun, 14 Nov 2021 20:40:06 -0800 you wrote:

From: Cong Wang <[email protected]>

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html