]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
netfilter: x_tables: add counters allocation wrapper
authorFlorian Westphal <fw@strlen.de>
Tue, 27 Feb 2018 18:42:33 +0000 (19:42 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 5 Mar 2018 22:15:43 +0000 (23:15 +0100)
allows to have size checks in a single spot.
This is supposed to reduce oom situations when fuzz-testing xtables.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/linux/netfilter/x_tables.h
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv6/netfilter/ip6_tables.c
net/netfilter/x_tables.c

index fa0c19c328f1de701512c746d1862849d90a2ac7..0bd93c589a8c1a6843d2d4788f21928dd27bfbf8 100644 (file)
@@ -301,6 +301,7 @@ int xt_data_to_user(void __user *dst, const void *src,
 
 void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
                                 struct xt_counters_info *info, bool compat);
+struct xt_counters *xt_counters_alloc(unsigned int counters);
 
 struct xt_table *xt_register_table(struct net *net,
                                   const struct xt_table *table,
index be5821215ea0e9cde7eb5a94e794365b36b2b07b..82ba09b50fdb7d3082d22207c6bd8e55d0f83d41 100644 (file)
@@ -883,7 +883,7 @@ static int __do_replace(struct net *net, const char *name,
        struct arpt_entry *iter;
 
        ret = 0;
-       counters = vzalloc(num_counters * sizeof(struct xt_counters));
+       counters = xt_counters_alloc(num_counters);
        if (!counters) {
                ret = -ENOMEM;
                goto out;
index 29bda9484a33282a5aee0ba1c0d3bc79d6591f56..4901ca6c3e09a4a00a515538d9b7cafbda2ab184 100644 (file)
@@ -1045,7 +1045,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
        struct ipt_entry *iter;
 
        ret = 0;
-       counters = vzalloc(num_counters * sizeof(struct xt_counters));
+       counters = xt_counters_alloc(num_counters);
        if (!counters) {
                ret = -ENOMEM;
                goto out;
index ba3776a4d30553f52db644d4c3bcb3c6c6cf7bef..e84cec49b60f9accb27e09183ea69e9bc321b524 100644 (file)
@@ -1063,7 +1063,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
        struct ip6t_entry *iter;
 
        ret = 0;
-       counters = vzalloc(num_counters * sizeof(struct xt_counters));
+       counters = xt_counters_alloc(num_counters);
        if (!counters) {
                ret = -ENOMEM;
                goto out;
index 01f8e122e74ee3cd62afaa84bb6ebfe3d938d43d..82b1f8f52ac6b0cb5011688a461e64a89dd761c4 100644 (file)
@@ -1290,6 +1290,21 @@ static int xt_jumpstack_alloc(struct xt_table_info *i)
        return 0;
 }
 
+struct xt_counters *xt_counters_alloc(unsigned int counters)
+{
+       struct xt_counters *mem;
+
+       if (counters == 0 || counters > INT_MAX / sizeof(*mem))
+               return NULL;
+
+       counters *= sizeof(*mem);
+       if (counters > XT_MAX_TABLE_SIZE)
+               return NULL;
+
+       return vzalloc(counters);
+}
+EXPORT_SYMBOL(xt_counters_alloc);
+
 struct xt_table_info *
 xt_replace_table(struct xt_table *table,
              unsigned int num_counters,