netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jozsef Kadlecsik <kadlec@netfilter.org>
To: Vasily Averin <vvs@virtuozzo.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
	Florian Westphal <fw@strlen.de>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org
Subject: Re: [PATCH] netfilter: ipset: fixes possible oops in mtype_resize
Date: Thu, 17 Dec 2020 18:12:03 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.23.453.2012171810580.2216@blackhole.kfki.hu> (raw)
In-Reply-To: <bfeee41d-65f0-40b2-1139-b888627e34ef@virtuozzo.com>

Hi Vasily, Pablo,

On Thu, 17 Dec 2020, Vasily Averin wrote:

> 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>

Good catch, thank you Vasily.

Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>

Best regards,
Jozsef

> ---
>  net/netfilter/ipset/ip_set_hash_gen.h | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> index 7d01086..7cd1d31 100644
> --- a/net/netfilter/ipset/ip_set_hash_gen.h
> +++ b/net/netfilter/ipset/ip_set_hash_gen.h
> @@ -630,7 +630,7 @@ struct mtype_resize_ad {
>  	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;
> @@ -654,14 +654,12 @@ struct mtype_resize_ad {
>  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;
> @@ -803,6 +801,12 @@ struct mtype_resize_ad {
>  	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  */
> -- 
> 1.8.3.1
> 
> 

-
E-mail  : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.hu
PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
          H-1525 Budapest 114, POB. 49, Hungary

  reply	other threads:[~2020-12-17 17:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17  8:53 [PATCH] netfilter: ipset: fixes possible oops in mtype_resize Vasily Averin
2020-12-17 17:12 ` Jozsef Kadlecsik [this message]
2020-12-17 18:44 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.23.453.2012171810580.2216@blackhole.kfki.hu \
    --to=kadlec@netfilter.org \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=vvs@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).