udp: validate checksum in udp_read_sock()
Subsystems (4)
PATCH 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.
--- net/ipv4/udp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/ipv4/udp.c +11 -0
@@ -1808,6 +1808,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
Quoted 23 lines · Cong Wang
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")Reported-by Daniel Borkmann <[email protected]>Reported-by John Fastabend <[email protected]>Cc Lorenz Bauer <[email protected]>Cc Jakub Sitnicki <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/udp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/ipv4/udp.c +0
-0@@ -1808,6 +1808,17 @@ int udp_read_sock(struct sock *sk, read_descriptor_t *desc, skb =skb_recv_udp (sk,0 ,1 , &err);
net/ipv4/udp.c int udp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 1818
Quoted 10 lines
net/ipv4/udp.c +8
-0if (!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);
We could use sock_drop() here? Otherwise looks good thanks.
Quoted 9 lines
net/ipv4/udp.c +3
-0+continue ; + } + used =recv_actor (desc, skb,0 , skb->len);if (used <=0 ) {if (!copied)Signature · 1 line
2.30.2
Quoted 29 lines · John Fastabend
Quoted 27 lines · Cong Wang
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")Reported-by Daniel Borkmann <[email protected]>Reported-by John Fastabend <[email protected]>Cc Lorenz Bauer <[email protected]>Cc Jakub Sitnicki <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/udp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/ipv4/udp.c +2
-0@@ -1808,6 +1808,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)) {
Quoted 8 lines
net/ipv4/udp.c int udp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 1818
Quoted 6 lines
net/ipv4/udp.c +6
-0+__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);We could use
sock_drop()here? Otherwise looks good thanks.
sock_drop() is in include/linux/skmsg.h, I think we need to move it to sock.h before using it here in net/ipv4/udp.c, right?
And there are other similar patterns which can be replaced with sock_drop(), so we can do the replacement for all in a separate patch.
Thanks.
John Fastabend
Acked-byQuoted 40 lines · Cong Wang
Quoted 29 lines · John Fastabend
Quoted 27 lines · Cong Wang
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")Reported-by Daniel Borkmann <[email protected]>Reported-by John Fastabend <[email protected]>Cc Lorenz Bauer <[email protected]>Cc Jakub Sitnicki <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/udp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/ipv4/udp.c +2
-0@@ -1808,6 +1808,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)) {Quoted 8 lines
net/ipv4/udp.c int udp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 1818
Quoted 6 lines
net/ipv4/udp.c +6
-0+__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);We could use
sock_drop()here? Otherwise looks good thanks.
Quoted 2 lines
sock_drop()is ininclude/linux/skmsg.h, I think we need to move it tosock.hbefore using it here innet/ipv4/udp.c, right?
Yes it would be necessary. Lets not do it here otherwise backports will be ugly.
Quoted 6 lines
And there are other similar patterns which can be replaced with
sock_drop(), so we can do the replacement for all in a separate patch.Thanks.