Skip to content

Commit d5807dd

Browse files
ummakynesgregkh
authored andcommitted
netfilter: conntrack: clamp maximum hashtable size to INT_MAX
[ Upstream commit b541ba7 ] Use INT_MAX as maximum size for the conntrack hashtable. Otherwise, it is possible to hit WARN_ON_ONCE in __kvmalloc_node_noprof() when resizing hashtable because __GFP_NOWARN is unset. See: 0708a0a ("mm: Consider __GFP_NOWARN flag for oversized kvmalloc() calls") Note: hashtable resize is only possible from init_netns. Fixes: 9cc1c73 ("netfilter: conntrack: avoid integer overflow when resizing") Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1e3f563 commit d5807dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2568,12 +2568,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
25682568
struct hlist_nulls_head *hash;
25692569
unsigned int nr_slots, i;
25702570

2571-
if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
2571+
if (*sizep > (INT_MAX / sizeof(struct hlist_nulls_head)))
25722572
return NULL;
25732573

25742574
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
25752575
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
25762576

2577+
if (nr_slots > (INT_MAX / sizeof(struct hlist_nulls_head)))
2578+
return NULL;
2579+
25772580
hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);
25782581

25792582
if (hash && nulls)

0 commit comments

Comments
 (0)