Skip to content

Commit cc77e4a

Browse files
vaveringregkh
authored andcommitted
netfilter: ipset: fixes possible oops in mtype_resize
[ 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 <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>
1 parent c871060 commit cc77e4a

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎net/netfilter/ipset/ip_set_hash_gen.h‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ mtype_resize(struct ip_set *set, bool retried)
630630
struct htype *h = set->data;
631631
struct htable *t, *orig;
632632
u8 htable_bits;
633-
size_t dsize = set->dsize;
633+
size_t hsize, dsize = set->dsize;
634634
#ifdef IP_SET_HASH_WITH_NETS
635635
u8 flags;
636636
struct mtype_elem *tmp;
@@ -654,14 +654,12 @@ mtype_resize(struct ip_set *set, bool retried)
654654
retry:
655655
ret = 0;
656656
htable_bits++;
657-
if (!htable_bits) {
658-
/* In case we have plenty of memory :-) */
659-
pr_warn("Cannot increase the hashsize of set %s further\n",
660-
set->name);
661-
ret = -IPSET_ERR_HASH_FULL;
662-
goto out;
663-
}
664-
t = ip_set_alloc(htable_size(htable_bits));
657+
if (!htable_bits)
658+
goto hbwarn;
659+
hsize = htable_size(htable_bits);
660+
if (!hsize)
661+
goto hbwarn;
662+
t = ip_set_alloc(hsize);
665663
if (!t) {
666664
ret = -ENOMEM;
667665
goto out;
@@ -803,6 +801,12 @@ mtype_resize(struct ip_set *set, bool retried)
803801
if (ret == -EAGAIN)
804802
goto retry;
805803
goto out;
804+
805+
hbwarn:
806+
/* In case we have plenty of memory :-) */
807+
pr_warn("Cannot increase the hashsize of set %s further\n", set->name);
808+
ret = -IPSET_ERR_HASH_FULL;
809+
goto out;
806810
}
807811

808812
/* Get the current number of elements and ext_size in the set */

0 commit comments

Comments
 (0)