netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH 08/11] netfilter: ipset: enable memory accounting for ipset allocations
Date: Sun,  4 Oct 2020 21:49:37 +0200	[thread overview]
Message-ID: <20201004194940.7368-9-pablo@netfilter.org> (raw)
In-Reply-To: <20201004194940.7368-1-pablo@netfilter.org>

From: Vasily Averin <vvs@virtuozzo.com>

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>
---
 net/netfilter/ipset/ip_set_core.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 920b7c4331f0..6f35832f0de3 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -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);
 
-- 
2.20.1


  parent reply	other threads:[~2020-10-04 19:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-04 19:49 [PATCH 00/11] Netfilter updates for net-next Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 01/11] netfilter: conntrack: proc: rename stat column Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 02/11] netfilter: nf_tables: Remove ununsed function nft_data_debug Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 03/11] ipvs: Remove unused macros Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 04/11] netfilter: nf_tables: fix userdata memleak Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 05/11] netfilter: nf_tables: use nla_memdup to copy udata Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 06/11] netfilter: nf_tables: add userdata attributes to nft_chain Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 07/11] netfilter: nf_tables_offload: Remove unused macro FLOW_SETUP_BLOCK Pablo Neira Ayuso
2020-10-04 19:49 ` Pablo Neira Ayuso [this message]
2020-10-04 19:49 ` [PATCH 09/11] netfilter: nfnetlink: place subsys mutexes in distinct lockdep classes Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 10/11] netfilter: nf_tables: Enable fast nft_cmp for inverted matches Pablo Neira Ayuso
2020-10-04 19:49 ` [PATCH 11/11] netfilter: nf_tables: Implement fast bitwise expression Pablo Neira Ayuso
2020-10-04 21:36 ` [PATCH 00/11] Netfilter updates for net-next David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201004194940.7368-9-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).