Skip to content

Commit defced7

Browse files
edumazetHashcode
authored andcommitted
udp: fix behavior of wrong checksums
commit beb39db59d14990e401e235faf66a6b9b31240b0 upstream. 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 <edumazet@google.com> Cc: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Zefan Li <lizefan@huawei.com>
1 parent 9659c51 commit defced7

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

net/ipv4/udp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,8 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
12531253
UDP_INC_STATS_USER(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
12541254
unlock_sock_fast(sk, slow);
12551255

1256-
if (noblock)
1257-
return -EAGAIN;
1258-
1259-
/* starting over for a new packet */
1256+
/* starting over for a new packet, but check if we need to yield */
1257+
cond_resched();
12601258
msg->msg_flags &= ~MSG_TRUNC;
12611259
goto try_again;
12621260
}

net/ipv6/udp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
454454
}
455455
unlock_sock_fast(sk, slow);
456456

457-
if (noblock)
458-
return -EAGAIN;
459-
460-
/* starting over for a new packet */
457+
/* starting over for a new packet, but check if we need to yield */
458+
cond_resched();
461459
msg->msg_flags &= ~MSG_TRUNC;
462460
goto try_again;
463461
}

0 commit comments

Comments
 (0)