Skip to contentSkip to conversation

net/packet: fix 4gb buffer limit due to overflow check

PATCH Superseded Kal Conley 2 participants 4 messages Feb 9, 2019 – Feb 12, 2019

Subsystems (3)
lore
Share & tools
lore

Kal Conley

author
#0 lore raw

PATCH 1/1 net/packet: fix 4gb buffer limit due to overflow check

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.

---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
index d0945253f43b..d603a430378e 100644
@@ -4291,7 +4291,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))
Signature · 1 line
2.20.1
maintainer
#1 lore raw

From: Kal Conley <[email protected]>
Date: Sat, 9 Feb 2019 21:37:00 +0100

Quoted 5 lines

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.

Please resubmit with a proper signoff and also an appropriate Fixes:
tag.

author
#2 lore raw

PATCH v2 1/1 net/packet: fix 4gb buffer limit due to overflow check

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")

---
Changes in v2:
- Add Signed-off-by and Fixes tag

 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
index 3b1a78906bc0..1cd1d83a4be0 100644
@@ -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))
Signature · 1 line
2.20.1
maintainer
#3 lore raw

From: Kal Conley <[email protected]>
Date: Sun, 10 Feb 2019 09:57:11 +0100

Quoted 11 lines

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")

---
Changes in v2:
- Add Signed-off-by and Fixes tag

Applied and queued up for -stable, thanks.