Skip to content

Commit d41aef0

Browse files
ummakynesmehmetb0
authored andcommitted
netfilter: conntrack: clamp maximum hashtable size to INT_MAX
BugLink: https://bugs.launchpad.net/bugs/2106770 [ 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 <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org> CVE-2025-21648 Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent 044bdde commit d41aef0

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
@@ -2558,12 +2558,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
25582558
struct hlist_nulls_head *hash;
25592559
unsigned int nr_slots, i;
25602560

2561-
if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
2561+
if (*sizep > (INT_MAX / sizeof(struct hlist_nulls_head)))
25622562
return NULL;
25632563

25642564
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
25652565
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
25662566

2567+
if (nr_slots > (INT_MAX / sizeof(struct hlist_nulls_head)))
2568+
return NULL;
2569+
25672570
hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);
25682571

25692572
if (hash && nulls)

0 commit comments

Comments
 (0)