From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 2/9] netfilter: xt_hashlimit: limit the max size of hashtable
Date: Tue, 18 Feb 2020 23:20:54 +0100 [thread overview]
Message-ID: <20200218222101.635808-3-pablo@netfilter.org> (raw)
In-Reply-To: <20200218222101.635808-1-pablo@netfilter.org>
From: Cong Wang <xiyou.wangcong@gmail.com>
The user-specified hashtable size is unbound, this could
easily lead to an OOM or a hung task as we hold the global
mutex while allocating and initializing the new hashtable.
Add a max value to cap both cfg->size and cfg->max, as
suggested by Florian.
Reported-and-tested-by: syzbot+adf6c6c2be1c3a718121@syzkaller.appspotmail.com
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_hashlimit.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index cc475a608f81..7a2c4b8408c4 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -837,6 +837,8 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
return hashlimit_mt_common(skb, par, hinfo, &info->cfg, 3);
}
+#define HASHLIMIT_MAX_SIZE 1048576
+
static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,
struct xt_hashlimit_htable **hinfo,
struct hashlimit_cfg3 *cfg,
@@ -847,6 +849,14 @@ static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,
if (cfg->gc_interval == 0 || cfg->expire == 0)
return -EINVAL;
+ if (cfg->size > HASHLIMIT_MAX_SIZE) {
+ cfg->size = HASHLIMIT_MAX_SIZE;
+ pr_info_ratelimited("size too large, truncated to %u\n", cfg->size);
+ }
+ if (cfg->max > HASHLIMIT_MAX_SIZE) {
+ cfg->max = HASHLIMIT_MAX_SIZE;
+ pr_info_ratelimited("max too large, truncated to %u\n", cfg->max);
+ }
if (par->family == NFPROTO_IPV4) {
if (cfg->srcmask > 32 || cfg->dstmask > 32)
return -EINVAL;
--
2.11.0
next prev parent reply other threads:[~2020-02-18 22:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-18 22:20 [PATCH 0/9] Netfilter fixes for net Pablo Neira Ayuso
2020-02-18 22:20 ` [PATCH 1/9] netfilter: xt_hashlimit: reduce hashlimit_mutex scope for htable_put() Pablo Neira Ayuso
2020-02-18 22:20 ` Pablo Neira Ayuso [this message]
2020-02-18 22:20 ` [PATCH 3/9] netfilter: flowtable: skip offload setup if disabled Pablo Neira Ayuso
2020-02-18 22:20 ` [PATCH 4/9] netfilter: conntrack: remove two args from resolve_clash Pablo Neira Ayuso
2020-02-18 22:20 ` [PATCH 5/9] netfilter: conntrack: place confirm-bit setting in a helper Pablo Neira Ayuso
2020-02-18 22:20 ` [PATCH 6/9] netfilter: conntrack: split resolve_clash function Pablo Neira Ayuso
2020-02-18 22:20 ` [PATCH 7/9] netfilter: conntrack: allow insertion of clashing entries Pablo Neira Ayuso
2020-02-18 22:21 ` [PATCH 8/9] netfilter: nft_set_pipapo: Fix mapping table example in comments Pablo Neira Ayuso
2020-02-18 22:21 ` [PATCH 9/9] netfilter: nft_set_pipapo: Don't abuse unlikely() in pipapo_refill() Pablo Neira Ayuso
2020-02-18 23:45 ` [PATCH 0/9] Netfilter fixes for net 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=20200218222101.635808-3-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--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).