Skip to content

Commit 2b33d6f

Browse files
vaverinummakynes
authored andcommitted
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: Vasily Averin <vvs@virtuozzo.com> Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 443d6e8 commit 2b33d6f

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
@@ -640,7 +640,7 @@ mtype_resize(struct ip_set *set, bool retried)
640640
struct htype *h = set->data;
641641
struct htable *t, *orig;
642642
u8 htable_bits;
643-
size_t dsize = set->dsize;
643+
size_t hsize, dsize = set->dsize;
644644
#ifdef IP_SET_HASH_WITH_NETS
645645
u8 flags;
646646
struct mtype_elem *tmp;
@@ -664,14 +664,12 @@ mtype_resize(struct ip_set *set, bool retried)
664664
retry:
665665
ret = 0;
666666
htable_bits++;
667-
if (!htable_bits) {
668-
/* In case we have plenty of memory :-) */
669-
pr_warn("Cannot increase the hashsize of set %s further\n",
670-
set->name);
671-
ret = -IPSET_ERR_HASH_FULL;
672-
goto out;
673-
}
674-
t = ip_set_alloc(htable_size(htable_bits));
667+
if (!htable_bits)
668+
goto hbwarn;
669+
hsize = htable_size(htable_bits);
670+
if (!hsize)
671+
goto hbwarn;
672+
t = ip_set_alloc(hsize);
675673
if (!t) {
676674
ret = -ENOMEM;
677675
goto out;
@@ -813,6 +811,12 @@ mtype_resize(struct ip_set *set, bool retried)
813811
if (ret == -EAGAIN)
814812
goto retry;
815813
goto out;
814+
815+
hbwarn:
816+
/* In case we have plenty of memory :-) */
817+
pr_warn("Cannot increase the hashsize of set %s further\n", set->name);
818+
ret = -IPSET_ERR_HASH_FULL;
819+
goto out;
816820
}
817821

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

0 commit comments

Comments
 (0)