Skip to content

Commit beb39db

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
udp: fix behavior of wrong checksums
We have two problems in UDP stack related to bogus checksums : 1) We return -EAGAIN 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. Signed-off-by: Eric Dumazet <[email protected]> Cc: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9eb0a5d commit beb39db

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

net/ipv4/udp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,8 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
13451345
}
13461346
unlock_sock_fast(sk, slow);
13471347

1348-
if (noblock)
1349-
return -EAGAIN;
1350-
1351-
/* starting over for a new packet */
1348+
/* starting over for a new packet, but check if we need to yield */
1349+
cond_resched();
13521350
msg->msg_flags &= ~MSG_TRUNC;
13531351
goto try_again;
13541352
}

net/ipv6/udp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
525525
}
526526
unlock_sock_fast(sk, slow);
527527

528-
if (noblock)
529-
return -EAGAIN;
530-
531-
/* starting over for a new packet */
528+
/* starting over for a new packet, but check if we need to yield */
529+
cond_resched();
532530
msg->msg_flags &= ~MSG_TRUNC;
533531
goto try_again;
534532
}

0 commit comments

Comments
 (0)