From 5080905535c3c977a96a0ef7faaa5095dafd7760 Mon Sep 17 00:00:00 2001 From: Harry Lin Date: Thu, 9 Jul 2015 13:00:54 +1000 Subject: udp: fix behavior of wrong checksums We have two problems in UDP stack related to bogus checksums : 1 ) We return -EGAIN to application even if receive queue is not empty. This breaks applications using edge trigger epoll() 2 ) Under UDP flood, we can loop forever without yielding to other processes, potentially hanging the host, especially on non SMP. This patch is an attempt to make things better. We might in the future add extra support for rt applications wanting to better control time spent doing a recv() in a hostile environment. For example we could validate checksums before queuing packets in socket receive queue. Change-Id: Ic25820228fd735e25a850951e059bf75ae39b653 Signed-off-by: Eruc Dumazet Cc: Willem de Brujin Signed-off-by: David S. Miller --- net/ipv4/udp.c | 6 ++---- net/ipv6/udp.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'net') diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 966c3e16486..2f00d320750 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1249,10 +1249,8 @@ csum_copy_err: UDP_INC_STATS_USER(sock_net(sk), UDP_MIB_INERRORS, is_udplite); unlock_sock_fast(sk, slow); - if (noblock) - return -EAGAIN; - - /* starting over for a new packet */ + /* starting over for a new packet, but check if we need to yield */ + cond_resched(); msg->msg_flags &= ~MSG_TRUNC; goto try_again; } diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 5c363cd5c55..823d1ef301f 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -453,10 +453,8 @@ csum_copy_err: } unlock_sock_fast(sk, slow); - if (noblock) - return -EAGAIN; - - /* starting over for a new packet */ + /* starting over for a new packet, but check if we need to yield */ + cond_resched(); msg->msg_flags &= ~MSG_TRUNC; goto try_again; } -- cgit v1.2.3