Skip to content

Commit b541ba7

Browse files
committed
netfilter: conntrack: clamp maximum hashtable size to INT_MAX
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]>
1 parent 13210fc commit b541ba7

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
@@ -2517,12 +2517,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
25172517
struct hlist_nulls_head *hash;
25182518
unsigned int nr_slots, i;
25192519

2520-
if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
2520+
if (*sizep > (INT_MAX / sizeof(struct hlist_nulls_head)))
25212521
return NULL;
25222522

25232523
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
25242524
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
25252525

2526+
if (nr_slots > (INT_MAX / sizeof(struct hlist_nulls_head)))
2527+
return NULL;
2528+
25262529
hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);
25272530

25282531
if (hash && nulls)

0 commit comments

Comments
 (0)