Skip to content

Commit 9cc1c73

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: avoid integer overflow when resizing
Can overflow so we might allocate very small table when bucket count is high on a 32bit platform. Note: resize is only possible from init_netns. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 62131e5 commit 9cc1c73

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,8 +1601,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
16011601
unsigned int nr_slots, i;
16021602
size_t sz;
16031603

1604+
if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
1605+
return NULL;
1606+
16041607
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
16051608
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
1609+
1610+
if (nr_slots > (UINT_MAX / sizeof(struct hlist_nulls_head)))
1611+
return NULL;
1612+
16061613
sz = nr_slots * sizeof(struct hlist_nulls_head);
16071614
hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
16081615
get_order(sz));

0 commit comments

Comments
 (0)