Skip to content

Commit

Permalink
netfilter: ipset: fixes possible oops in mtype_resize
Browse files Browse the repository at this point in the history
[ Upstream commit 2b33d6f ]

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: Vasily Averin <[email protected]>
Acked-by: Jozsef Kadlecsik <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
vaverin authored and gregkh committed Jan 19, 2021
1 parent c871060 commit cc77e4a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions net/netfilter/ipset/ip_set_hash_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ mtype_resize(struct ip_set *set, bool retried)
struct htype *h = set->data;
struct htable *t, *orig;
u8 htable_bits;
size_t dsize = set->dsize;
size_t hsize, dsize = set->dsize;
#ifdef IP_SET_HASH_WITH_NETS
u8 flags;
struct mtype_elem *tmp;
Expand All @@ -654,14 +654,12 @@ mtype_resize(struct ip_set *set, bool retried)
retry:
ret = 0;
htable_bits++;
if (!htable_bits) {
/* 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;
}
t = ip_set_alloc(htable_size(htable_bits));
if (!htable_bits)
goto hbwarn;
hsize = htable_size(htable_bits);
if (!hsize)
goto hbwarn;
t = ip_set_alloc(hsize);
if (!t) {
ret = -ENOMEM;
goto out;
Expand Down Expand Up @@ -803,6 +801,12 @@ mtype_resize(struct ip_set *set, bool retried)
if (ret == -EAGAIN)
goto retry;
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 */
Expand Down

0 comments on commit cc77e4a

Please sign in to comment.