Skip to contentSkip to conversation

netfilter: ipset: Fix oversized kvmalloc() calls

PATCH Applied Jozsef Kadlecsik 2 participants 2 messages Sep 6, 2021 – Sep 13, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ipset: Fix oversized kvmalloc() calls

The commit

commit 7661809d493b426e979f39ab512e3adf41fbcc69

Author: Linus Torvalds <[email protected]>
Date:   Wed Jul 14 09:45:49 2021 -0700

mm: don't allow oversized kvmalloc() calls

limits the max allocatable memory via kvmalloc() to MAX_INT. Apply the same limit in ipset.

---
 net/netfilter/ipset/ip_set_hash_gen.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +2 -2
index 6186358eac7c..6e391308431d 100644
@@ -130,11 +130,11 @@ htable_size(u8 hbits)
 {
 	size_t hsize;
 
-	/* We must fit both into u32 in jhash and size_t */
+	/* We must fit both into u32 in jhash and INT_MAX in kvmalloc_node() */
 	if (hbits > 31)
 		return 0;
 	hsize = jhash_size(hbits);
-	if ((((size_t)-1) - sizeof(struct htable)) / sizeof(struct hbucket *)
+	if ((INT_MAX - sizeof(struct htable)) / sizeof(struct hbucket *)
 	    < hsize)
 		return 0;
 
Signature · 9 lines
2.20.1

Best regards,
Jozsef
-
E-mail  : [email protected], [email protected]
PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
          H-1525 Budapest 114, POB. 49, Hungary
maintainer Applied
#1 lore raw
Quoted 10 lines · Jozsef Kadlecsik

The commit

commit 7661809d493b426e979f39ab512e3adf41fbcc69

Author: Linus Torvalds <[email protected]>
Date:   Wed Jul 14 09:45:49 2021 -0700

mm: don't allow oversized kvmalloc() calls

limits the max allocatable memory via kvmalloc() to MAX_INT. Apply the same limit in ipset.

Applied, thanks Jozsef.