From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf] netfilter: conntrack: avoid integer overflow when resizing
Date: Fri, 29 Apr 2016 11:59:02 +0200 [thread overview]
Message-ID: <20160429095902.GA15406@salvia> (raw)
In-Reply-To: <1461453501-4428-1-git-send-email-fw@strlen.de>
On Sun, Apr 24, 2016 at 01:18:21AM +0200, Florian Westphal wrote:
> Can overflow so we might allocate very small table when bucket count is
> high on a 32bit platform.
>
> Note: resize is only possible from init_netns.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> net/netfilter/nf_conntrack_core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
> index 2bbb962..11daca5 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -1563,8 +1563,15 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
> unsigned int nr_slots, i;
> size_t sz;
>
> + if (*sizep > (UINT_MAX / sizeof(struct hlist_nulls_head)))
> + return NULL;
*sizep gets initially set to the number of buckets.
> BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
> nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
Then, this value is divided by the number of hlist heads that fit into
a page.
> +
> + if (nr_slots > (UINT_MAX / sizeof(struct hlist_nulls_head)))
> + return NULL;
So, isn't is enough with this sole check? I might be missing anything.
> +
> sz = nr_slots * sizeof(struct hlist_nulls_head);
> hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
> get_order(sz));
> --
> 2.7.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-04-29 9:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-23 23:18 [PATCH nf] netfilter: conntrack: avoid integer overflow when resizing Florian Westphal
2016-04-29 9:59 ` Pablo Neira Ayuso [this message]
2016-05-01 19:48 ` Florian Westphal
2016-05-03 22:45 ` 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=20160429095902.GA15406@salvia \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/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).