netfilter: ipset: fixes possible oops in mtype_resize
authorVasily Averin <vvs@virtuozzo.com>
Thu, 17 Dec 2020 08:53:40 +0000 (11:53 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:23 +0000 (18:27 +0100)
commitcc77e4a020aa308265a67ed4cb3188100a1787a0
tree49f3403b0db3ccec8af5b35f9c4470ece4301e66
parentc871060d3eaa64946133bfdce0d3d443741ed811
netfilter: ipset: fixes possible oops in mtype_resize

[ Upstream commit 2b33d6ffa9e38f344418976b06057e2fc2aa9e2a ]

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 <vvs@virtuozzo.com>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/ipset/ip_set_hash_gen.h