From: Andrey Konovalov Date: Wed, 29 Mar 2017 14:11:21 +0000 (+0200) Subject: net/packet: fix overflow in check for tp_frame_nr X-Git-Tag: archive/raspbian/4.15.4-1+rpi1~1^2^2^2^2^2^2^2^2^2^2^2^2^2~39 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ef0a862f13fa6fc30379df0746f98ab722a29c20;p=linux.git net/packet: fix overflow in check for tp_frame_nr When calculating rb->frames_per_block * req->tp_block_nr the result can overflow. Add a check that tp_block_size * tp_block_nr <= UINT_MAX. Since frames_per_block <= tp_block_size, the expression would never overflow. Signed-off-by: Andrey Konovalov Acked-by: Eric Dumazet Signed-off-by: David S. Miller Gbp-Pq: Topic bugfix/all Gbp-Pq: Name net-packet-fix-overflow-in-check-for-tp_frame_nr.patch --- diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 8ab0974f4ee..e064e334282 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4247,6 +4247,8 @@ 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)) + goto out; if (unlikely((rb->frames_per_block * req->tp_block_nr) != req->tp_frame_nr)) goto out;