* [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers
@ 2017-03-29 14:11 Andrey Konovalov
2017-03-29 14:11 ` [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size Andrey Konovalov
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Andrey Konovalov @ 2017-03-29 14:11 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek
Cc: netdev, Dmitry Vyukov, Kostya Serebryany, Andrey Konovalov
This patchset addresses multiple overflows and signedness-related issues
in packet socket ring buffers.
Changes in v2:
- remove cleanup patches, will send in a separate patchset
- use a > UINT_MAX / b to check for a * b overflow
Andrey Konovalov (3):
net/packet: fix overflow in check for priv area size
net/packet: fix overflow in check for tp_frame_nr
net/packet: fix overflow in check for tp_reserve
net/packet/af_packet.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--
2.12.2.564.g063fe858b8-goog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size
2017-03-29 14:11 [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers Andrey Konovalov
@ 2017-03-29 14:11 ` Andrey Konovalov
2017-03-29 15:50 ` Eric Dumazet
2017-03-29 14:11 ` [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr Andrey Konovalov
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2017-03-29 14:11 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek
Cc: netdev, Dmitry Vyukov, Kostya Serebryany, Andrey Konovalov
Subtracting tp_sizeof_priv from tp_block_size and casting to int
to check whether one is less then the other doesn't always work
(both of them are unsigned ints).
Compare them as is instead.
Also cast tp_sizeof_priv to u64 before using BLK_PLUS_PRIV, as
it can overflow inside BLK_PLUS_PRIV otherwise.
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
net/packet/af_packet.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index a0dbe7ca8f72..2323ee35dc09 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4193,8 +4193,8 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
if (unlikely(!PAGE_ALIGNED(req->tp_block_size)))
goto out;
if (po->tp_version >= TPACKET_V3 &&
- (int)(req->tp_block_size -
- BLK_PLUS_PRIV(req_u->req3.tp_sizeof_priv)) <= 0)
+ req->tp_block_size <=
+ BLK_PLUS_PRIV((u64)req_u->req3.tp_sizeof_priv))
goto out;
if (unlikely(req->tp_frame_size < po->tp_hdrlen +
po->tp_reserve))
--
2.12.2.564.g063fe858b8-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr
2017-03-29 14:11 [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers Andrey Konovalov
2017-03-29 14:11 ` [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size Andrey Konovalov
@ 2017-03-29 14:11 ` Andrey Konovalov
2017-03-29 15:51 ` Eric Dumazet
2017-03-29 14:11 ` [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve Andrey Konovalov
2017-03-30 18:04 ` [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers David Miller
3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2017-03-29 14:11 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek
Cc: netdev, Dmitry Vyukov, Kostya Serebryany, Andrey Konovalov
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 <andreyknvl@google.com>
---
net/packet/af_packet.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 2323ee35dc09..3ac286ebb2f4 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4205,6 +4205,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;
--
2.12.2.564.g063fe858b8-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve
2017-03-29 14:11 [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers Andrey Konovalov
2017-03-29 14:11 ` [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size Andrey Konovalov
2017-03-29 14:11 ` [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr Andrey Konovalov
@ 2017-03-29 14:11 ` Andrey Konovalov
2017-03-29 15:51 ` Eric Dumazet
2017-03-30 18:04 ` [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers David Miller
3 siblings, 1 reply; 8+ messages in thread
From: Andrey Konovalov @ 2017-03-29 14:11 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek
Cc: netdev, Dmitry Vyukov, Kostya Serebryany, Andrey Konovalov
When calculating po->tp_hdrlen + po->tp_reserve the result can overflow.
Fix by checking that tp_reserve <= INT_MAX on assign.
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
net/packet/af_packet.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 3ac286ebb2f4..8489beff5c25 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3665,6 +3665,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
return -EBUSY;
if (copy_from_user(&val, optval, sizeof(val)))
return -EFAULT;
+ if (val > INT_MAX)
+ return -EINVAL;
po->tp_reserve = val;
return 0;
}
--
2.12.2.564.g063fe858b8-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size
2017-03-29 14:11 ` [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size Andrey Konovalov
@ 2017-03-29 15:50 ` Eric Dumazet
0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2017-03-29 15:50 UTC (permalink / raw)
To: Andrey Konovalov
Cc: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek,
netdev, Dmitry Vyukov, Kostya Serebryany
On Wed, 2017-03-29 at 16:11 +0200, Andrey Konovalov wrote:
> Subtracting tp_sizeof_priv from tp_block_size and casting to int
> to check whether one is less then the other doesn't always work
> (both of them are unsigned ints).
>
> Compare them as is instead.
>
> Also cast tp_sizeof_priv to u64 before using BLK_PLUS_PRIV, as
> it can overflow inside BLK_PLUS_PRIV otherwise.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr
2017-03-29 14:11 ` [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr Andrey Konovalov
@ 2017-03-29 15:51 ` Eric Dumazet
0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2017-03-29 15:51 UTC (permalink / raw)
To: Andrey Konovalov
Cc: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek,
netdev, Dmitry Vyukov, Kostya Serebryany
On Wed, 2017-03-29 at 16:11 +0200, Andrey Konovalov wrote:
> 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 <andreyknvl@google.com>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve
2017-03-29 14:11 ` [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve Andrey Konovalov
@ 2017-03-29 15:51 ` Eric Dumazet
0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2017-03-29 15:51 UTC (permalink / raw)
To: Andrey Konovalov
Cc: David S . Miller, Eric Dumazet, Willem de Bruijn, Craig Gallek,
netdev, Dmitry Vyukov, Kostya Serebryany
On Wed, 2017-03-29 at 16:11 +0200, Andrey Konovalov wrote:
> When calculating po->tp_hdrlen + po->tp_reserve the result can overflow.
>
> Fix by checking that tp_reserve <= INT_MAX on assign.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
Thanks !
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers
2017-03-29 14:11 [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers Andrey Konovalov
` (2 preceding siblings ...)
2017-03-29 14:11 ` [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve Andrey Konovalov
@ 2017-03-30 18:04 ` David Miller
3 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2017-03-30 18:04 UTC (permalink / raw)
To: andreyknvl; +Cc: edumazet, willemb, cgallek, netdev, dvyukov, kcc
From: Andrey Konovalov <andreyknvl@google.com>
Date: Wed, 29 Mar 2017 16:11:19 +0200
> This patchset addresses multiple overflows and signedness-related issues
> in packet socket ring buffers.
>
> Changes in v2:
> - remove cleanup patches, will send in a separate patchset
> - use a > UINT_MAX / b to check for a * b overflow
All applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-03-30 18:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 14:11 [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers Andrey Konovalov
2017-03-29 14:11 ` [PATCH net v2 1/3] net/packet: fix overflow in check for priv area size Andrey Konovalov
2017-03-29 15:50 ` Eric Dumazet
2017-03-29 14:11 ` [PATCH net v2 2/3] net/packet: fix overflow in check for tp_frame_nr Andrey Konovalov
2017-03-29 15:51 ` Eric Dumazet
2017-03-29 14:11 ` [PATCH net v2 3/3] net/packet: fix overflow in check for tp_reserve Andrey Konovalov
2017-03-29 15:51 ` Eric Dumazet
2017-03-30 18:04 ` [PATCH net v2 0/3] net/packet: fix multiple overflow issues in ring buffers David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.