netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation
@ 2017-10-19 16:03 John Fastabend
  2017-10-19 22:12 ` Alexei Starovoitov
  2017-10-21 23:54 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: John Fastabend @ 2017-10-19 16:03 UTC (permalink / raw)
  To: richard, alexei.starovoitov, davem; +Cc: netdev, borkmann

An integer overflow is possible in dev_map_bitmap_size() when
calculating the BITS_TO_LONG logic which becomes, after macro
replacement,

	(((n) + (d) - 1)/ (d))

where 'n' is a __u32 and 'd' is (8 * sizeof(long)). To avoid
overflow cast to u64 before arithmetic.

Reported-by: Richard Weinberger <richard@nod.at>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 kernel/bpf/devmap.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 7d9f32f..6d3ec97 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -69,7 +69,7 @@ static LIST_HEAD(dev_map_list);
 
 static u64 dev_map_bitmap_size(const union bpf_attr *attr)
 {
-	return BITS_TO_LONGS(attr->max_entries) * sizeof(unsigned long);
+	return BITS_TO_LONGS((u64) attr->max_entries) * sizeof(unsigned long);
 }
 
 static struct bpf_map *dev_map_alloc(union bpf_attr *attr)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation
  2017-10-19 16:03 [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation John Fastabend
@ 2017-10-19 22:12 ` Alexei Starovoitov
  2017-10-21 23:54 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2017-10-19 22:12 UTC (permalink / raw)
  To: John Fastabend; +Cc: richard, davem, netdev, borkmann

On Thu, Oct 19, 2017 at 09:03:52AM -0700, John Fastabend wrote:
> An integer overflow is possible in dev_map_bitmap_size() when
> calculating the BITS_TO_LONG logic which becomes, after macro
> replacement,
> 
> 	(((n) + (d) - 1)/ (d))
> 
> where 'n' is a __u32 and 'd' is (8 * sizeof(long)). To avoid
> overflow cast to u64 before arithmetic.
> 
> Reported-by: Richard Weinberger <richard@nod.at>
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation
  2017-10-19 16:03 [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation John Fastabend
  2017-10-19 22:12 ` Alexei Starovoitov
@ 2017-10-21 23:54 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-10-21 23:54 UTC (permalink / raw)
  To: john.r.fastabend; +Cc: richard, alexei.starovoitov, netdev, borkmann

From: John Fastabend <john.r.fastabend@gmail.com>
Date: Thu, 19 Oct 2017 09:03:52 -0700

> An integer overflow is possible in dev_map_bitmap_size() when
> calculating the BITS_TO_LONG logic which becomes, after macro
> replacement,
> 
> 	(((n) + (d) - 1)/ (d))
> 
> where 'n' is a __u32 and 'd' is (8 * sizeof(long)). To avoid
> overflow cast to u64 before arithmetic.
> 
> Reported-by: Richard Weinberger <richard@nod.at>
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-21 23:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-19 16:03 [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size calculation John Fastabend
2017-10-19 22:12 ` Alexei Starovoitov
2017-10-21 23:54 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).