Skip to contentSkip to conversation

udp: fix integer overflow while computing available space in sk_rcvbuf

PATCH In review Antonio Messina 2 participants 2 messages Dec 19, 2019 – Dec 24, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp: fix integer overflow while computing available space in sk_rcvbuf

When the size of the receive buffer for a socket is close to 2^31 when computing if we have enough space in the buffer to copy a packet from the queue to the buffer we might hit an integer overflow.

When an user set net.core.rmem_default to a value close to 2^31 UDP packets are dropped because of this overflow. This can be visible, for instance, with failure to resolve hostnames.

This can be fixed by casting sk_rcvbuf (which is an int) to unsigned int, similarly to how it is done in TCP.

---
 net/ipv4/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp.c +1 -1
index 4da5758cc718..93a355b6b092 100644
@@ -1475,7 +1475,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 	 * queue contains some other skb
 	 */
 	rmem = atomic_add_return(size, &sk->sk_rmem_alloc);
-	if (rmem > (size + sk->sk_rcvbuf))
+	if (rmem > (size + (unsigned int)sk->sk_rcvbuf))
 		goto uncharge_drop;
 
 	spin_lock(&list->lock);
Signature · 1 line
2.24.1.735.g03f4e72817-goog
maintainer
#1 lore raw

From: Antonio Messina <[email protected]>
Date: Thu, 19 Dec 2019 15:08:03 +0100

Quoted 4 lines

When the size of the receive buffer for a socket is close to 2^31 when computing if we have enough space in the buffer to copy a packet from the queue to the buffer we might hit an integer overflow.

Quoted 8 lines

When an user set net.core.rmem_default to a value close to 2^31 UDP packets are dropped because of this overflow. This can be visible, for instance, with failure to resolve hostnames.

This can be fixed by casting sk_rcvbuf (which is an int) to unsigned int, similarly to how it is done in TCP.

Applied and queued up for -stable, thanks.