Commit 2b33d6ff authored by Vasily Averin's avatar Vasily Averin Committed by Pablo Neira Ayuso

netfilter: ipset: fixes possible oops in mtype_resize

currently mtype_resize() can cause oops

        t = ip_set_alloc(htable_size(htable_bits));
        if (!t) {
                ret = -ENOMEM;
                goto out;
        }
        t->hregion = ip_set_alloc(ahash_sizeof_regions(htable_bits));

Increased htable_bits can force htable_size() to return 0.
In own turn ip_set_alloc(0) returns not 0 but ZERO_SIZE_PTR,
so follwoing access to t->hregion should trigger an OOPS.
Signed-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
Acked-by: default avatarJozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 443d6e86
...@@ -640,7 +640,7 @@ mtype_resize(struct ip_set *set, bool retried) ...@@ -640,7 +640,7 @@ mtype_resize(struct ip_set *set, bool retried)
struct htype *h = set->data; struct htype *h = set->data;
struct htable *t, *orig; struct htable *t, *orig;
u8 htable_bits; u8 htable_bits;
size_t dsize = set->dsize; size_t hsize, dsize = set->dsize;
#ifdef IP_SET_HASH_WITH_NETS #ifdef IP_SET_HASH_WITH_NETS
u8 flags; u8 flags;
struct mtype_elem *tmp; struct mtype_elem *tmp;
...@@ -664,14 +664,12 @@ mtype_resize(struct ip_set *set, bool retried) ...@@ -664,14 +664,12 @@ mtype_resize(struct ip_set *set, bool retried)
retry: retry:
ret = 0; ret = 0;
htable_bits++; htable_bits++;
if (!htable_bits) { if (!htable_bits)
/* In case we have plenty of memory :-) */ goto hbwarn;
pr_warn("Cannot increase the hashsize of set %s further\n", hsize = htable_size(htable_bits);
set->name); if (!hsize)
ret = -IPSET_ERR_HASH_FULL; goto hbwarn;
goto out; t = ip_set_alloc(hsize);
}
t = ip_set_alloc(htable_size(htable_bits));
if (!t) { if (!t) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -813,6 +811,12 @@ mtype_resize(struct ip_set *set, bool retried) ...@@ -813,6 +811,12 @@ mtype_resize(struct ip_set *set, bool retried)
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto retry; goto retry;
goto out; goto out;
hbwarn:
/* In case we have plenty of memory :-) */
pr_warn("Cannot increase the hashsize of set %s further\n", set->name);
ret = -IPSET_ERR_HASH_FULL;
goto out;
} }
/* Get the current number of elements and ext_size in the set */ /* Get the current number of elements and ext_size in the set */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment