Skip to content

Commit 8d0015a

Browse files
congwangummakynes
authored andcommitted
netfilter: xt_hashlimit: limit the max size of hashtable
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: [email protected] Signed-off-by: Cong Wang <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent c4a3922 commit 8d0015a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

net/netfilter/xt_hashlimit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
837837
return hashlimit_mt_common(skb, par, hinfo, &info->cfg, 3);
838838
}
839839

840+
#define HASHLIMIT_MAX_SIZE 1048576
841+
840842
static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,
841843
struct xt_hashlimit_htable **hinfo,
842844
struct hashlimit_cfg3 *cfg,
@@ -847,6 +849,14 @@ static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,
847849

848850
if (cfg->gc_interval == 0 || cfg->expire == 0)
849851
return -EINVAL;
852+
if (cfg->size > HASHLIMIT_MAX_SIZE) {
853+
cfg->size = HASHLIMIT_MAX_SIZE;
854+
pr_info_ratelimited("size too large, truncated to %u\n", cfg->size);
855+
}
856+
if (cfg->max > HASHLIMIT_MAX_SIZE) {
857+
cfg->max = HASHLIMIT_MAX_SIZE;
858+
pr_info_ratelimited("max too large, truncated to %u\n", cfg->max);
859+
}
850860
if (par->family == NFPROTO_IPV4) {
851861
if (cfg->srcmask > 32 || cfg->dstmask > 32)
852862
return -EINVAL;

0 commit comments

Comments
 (0)