net/packet: fix 4gb buffer limit due to overflow check
authorKal Conley <kal.conley@dectris.com>
Sun, 10 Feb 2019 08:57:11 +0000 (09:57 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 12 Feb 2019 18:37:23 +0000 (13:37 -0500)
When calculating rb->frames_per_block * req->tp_block_nr the result
can overflow. Check it for overflow without limiting the total buffer
size to UINT_MAX.

This change fixes support for packet ring buffers >= UINT_MAX.

Fixes: 8f8d28e4d6d8 ("net/packet: fix overflow in check for tp_frame_nr")
Signed-off-by: Kal Conley <kal.conley@dectris.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/packet/af_packet.c

index 3b1a78906bc0cddbff58b1c098aa3ae59b50723d..1cd1d83a4be081e2d67f3fda5fbc1267e1464654 100644 (file)
@@ -4292,7 +4292,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                rb->frames_per_block = req->tp_block_size / req->tp_frame_size;
                if (unlikely(rb->frames_per_block == 0))
                        goto out;
-               if (unlikely(req->tp_block_size > UINT_MAX / req->tp_block_nr))
+               if (unlikely(rb->frames_per_block > UINT_MAX / req->tp_block_nr))
                        goto out;
                if (unlikely((rb->frames_per_block * req->tp_block_nr) !=
                                        req->tp_frame_nr))