]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
netfilter: ipset: enable memory accounting for ipset allocations
authorVasily Averin <vvs@virtuozzo.com>
Thu, 19 Nov 2020 13:59:51 +0000 (14:59 +0100)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Thu, 19 Nov 2020 13:59:51 +0000 (14:59 +0100)
Currently netadmin inside non-trusted container can quickly allocate
whole node's memory via request of huge ipset hashtable.
Other ipset-related memory allocations should be restricted too.

v2: fixed typo ALLOC -> ACCOUNT

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
kernel/net/netfilter/ipset/ip_set_core.c

index eb8741309178a713864b4c98f6cd23fd61aec0d9..dcbc4008c00d7b9623ce09f3262c78cf38e51d81 100644 (file)
@@ -250,22 +250,7 @@ EXPORT_SYMBOL_GPL(ip_set_type_unregister);
 void *
 ip_set_alloc(size_t size)
 {
-       void *members = NULL;
-
-       if (size < KMALLOC_MAX_SIZE)
-               members = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
-
-       if (members) {
-               pr_debug("%p: allocated with kmalloc\n", members);
-               return members;
-       }
-
-       members = vzalloc(size);
-       if (!members)
-               return NULL;
-       pr_debug("%p: allocated with vmalloc\n", members);
-
-       return members;
+       return kvzalloc(size, GFP_KERNEL_ACCOUNT);
 }
 EXPORT_SYMBOL_GPL(ip_set_alloc);