[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <150842903200.12537.10765604428561566031.stgit@john-XPS-13-9360>
Date: Thu, 19 Oct 2017 09:03:52 -0700
From: John Fastabend <john.r.fastabend@...il.com>
To: richard@....at, alexei.starovoitov@...il.com, davem@...emloft.net
Cc: netdev@...r.kernel.org, borkmann@...earbox.net
Subject: [net PATCH] bpf: devmap fix arithmetic overflow in bitmap_size
calculation
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@....at>
Acked-by: Daniel Borkmann <daniel@...earbox.net>
Signed-off-by: John Fastabend <john.fastabend@...il.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)
Powered by blists - more mailing lists