From: Daniel Borkmann <daniel@iogearbox.net>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, davem@davemloft.net
Cc: Alexei Starovoitov <ast@kernel.org>,
netdev <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
syzkaller <syzkaller@googlegroups.com>,
Kostya Serebryany <kcc@google.com>,
Alexander Potapenko <glider@google.com>,
Eric Dumazet <edumazet@google.com>,
Sasha Levin <sasha.levin@oracle.com>
Subject: Re: [PATCH net] bpf: fix allocation warnings in bpf maps and integer overflow
Date: Mon, 30 Nov 2015 14:52:28 +0100 [thread overview]
Message-ID: <565C549C.5080408@iogearbox.net> (raw)
In-Reply-To: <20151130005934.GA95228@ast-mbp.thefacebook.com>
On 11/30/2015 01:59 AM, Alexei Starovoitov wrote:
[...]
> For large map->value_size the user space can trigger memory allocation warnings like:
[...]
> To avoid never succeeding kmalloc with order >= MAX_ORDER check that
> elem->value_size and computed elem_size are within limits for both hash and
> array type maps.
[...]
> Large value_size can cause integer overflows in elem_size and map.pages
> formulas, so check for that as well.
[...]
> diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
> index 3f4c99e06c6b..b1e53b79c586 100644
> --- a/kernel/bpf/arraymap.c
> +++ b/kernel/bpf/arraymap.c
> @@ -28,11 +28,17 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
> attr->value_size == 0)
> return ERR_PTR(-EINVAL);
>
> + if (attr->value_size >= 1 << (KMALLOC_SHIFT_MAX - 1))
> + /* if value_size is bigger, the user space won't be able to
> + * access the elements.
> + */
> + return ERR_PTR(-E2BIG);
> +
Bit confused, given that in array map, we try kzalloc() with __GFP_NOWARN already
and if that fails, we fall back to vzalloc(), it shouldn't trigger memory allocation
warnings here ...
Then, integer overflow in elem_size with round_up(attr->value_size, 8) could only
result in 0, which is already tested below.
> elem_size = round_up(attr->value_size, 8);
>
> /* check round_up into zero and u32 overflow */
> if (elem_size == 0 ||
> - attr->max_entries > (U32_MAX - sizeof(*array)) / elem_size)
> + attr->max_entries > (U32_MAX - PAGE_SIZE - sizeof(*array)) / elem_size)
> return ERR_PTR(-ENOMEM);
... and this change seems to be needed for the integer overflow in map.pages?
So if the first check above intends to check for some size overflow (?), how is it
then related to KMALLOC_SHIFT_MAX?
Thanks,
Daniel
next prev parent reply other threads:[~2015-11-30 13:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-29 13:18 user-controllable kmalloc size in bpf syscall Dmitry Vyukov
2015-11-29 18:21 ` Alexei Starovoitov
2015-11-30 0:59 ` [PATCH net] bpf: fix allocation warnings in bpf maps and integer overflow Alexei Starovoitov
2015-11-30 13:52 ` Daniel Borkmann [this message]
2015-11-30 13:57 ` Dmitry Vyukov
2015-11-30 14:13 ` Daniel Borkmann
2015-11-30 14:16 ` Dmitry Vyukov
2015-11-30 14:34 ` Daniel Borkmann
2015-11-30 18:13 ` Alexei Starovoitov
2015-11-30 22:16 ` Daniel Borkmann
2015-11-30 23:30 ` Alexei Starovoitov
2015-12-03 4:36 ` David Miller
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=565C549C.5080408@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=glider@google.com \
--cc=kcc@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sasha.levin@oracle.com \
--cc=syzkaller@googlegroups.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).