mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-03 01:28:04 +00:00
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:0708a0afe2
("mm: Consider __GFP_NOWARN flag for oversized kvmalloc() calls") Note: hashtable resize is only possible from init_netns. Fixes:9cc1c73ad6
("netfilter: conntrack: avoid integer overflow when resizing") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
parent
13210fc63f
commit
b541ba7d1f
@ -2517,12 +2517,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
|
|||||||
struct hlist_nulls_head *hash;
|
struct hlist_nulls_head *hash;
|
||||||
unsigned int nr_slots, i;
|
unsigned int nr_slots, i;
|
||||||
|
|
||||||
if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
|
if (*sizep > (INT_MAX / sizeof(struct hlist_nulls_head)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
|
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
|
||||||
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
|
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
|
||||||
|
|
||||||
|
if (nr_slots > (INT_MAX / sizeof(struct hlist_nulls_head)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);
|
hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);
|
||||||
|
|
||||||
if (hash && nulls)
|
if (hash && nulls)
|
||||||
|
Loading…
Reference in New Issue
Block a user