From: Daniel Borkmann <daniel@iogearbox.net>
To: Jakub Kicinski <jakub.kicinski@netronome.com>, netdev@vger.kernel.org
Cc: alexei.starovoitov@gmail.com, oss-drivers@netronome.com
Subject: Re: [PATCH net-next 5/5] bpf: write back the verifier log buffer as it gets filled
Date: Thu, 05 Oct 2017 23:10:03 +0200 [thread overview]
Message-ID: <59D69FAB.1020605@iogearbox.net> (raw)
In-Reply-To: <20171005153422.8947-6-jakub.kicinski@netronome.com>
On 10/05/2017 05:34 PM, Jakub Kicinski wrote:
> Verifier log buffer can be quite large (up to 16MB currently).
> As Eric Dumazet points out if we allow multiple verification
> requests to proceed simultaneously, malicious user may use the
> verifier as a way of allocating large amounts of unswappable
> memory to OOM the host.
>
> Switch to a strategy of allocating a smaller buffer (a page)
> and writing it out into the user buffer whenever it fills up.
> To simplify the code assume that prints will never be longer
> than 1024 bytes.
>
> This is in preparation of the global verifier lock removal.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> Reviewed-by: Simon Horman <simon.horman@netronome.com>
Set looks good in general, thanks for working on this! Just two
comments further below.
> ---
> include/linux/bpf_verifier.h | 7 +++--
> kernel/bpf/verifier.c | 64 +++++++++++++++++++++++++++++++-------------
> 2 files changed, 50 insertions(+), 21 deletions(-)
>
> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> index 598802dd1897..c0f0e210c3f8 100644
> --- a/include/linux/bpf_verifier.h
> +++ b/include/linux/bpf_verifier.h
> @@ -140,10 +140,13 @@ struct bpf_verifier_env {
> bool seen_direct_write;
> struct bpf_insn_aux_data *insn_aux_data; /* array of per-insn state */
>
> - u32 log_level;
> + char __user *log_ubuf;
> + u32 log_usize;
> + u32 log_ulen;
> + char *log_buf;
> u32 log_size;
> u32 log_len;
> - char *log_buf;
> + u32 log_level;
Small request: given we'd now have log_{level,ubuf,usize,ulen,buf,size,len}
in struct bpf_verifier_env, could we abstract that a bit e.g. into something
like struct bpf_verifier_log, which has level and kbuf and ubuf as members
of which {k,u}buf would be something like struct bpf_verifier_buf with three
members (mem or buf, len_total, len_used) or such. I think most of patch 1
is on passing env into verbose, so likely wouldn't be too much change required
for this, but would be nice to make that a bit more structured if we need to
touch it anyway.
> };
>
[...]
>
> ret = -ENOMEM;
> - env->log_buf = vmalloc(env->log_size);
> + env->log_buf = page_address(alloc_page(GFP_USER));
alloc_page() can return NULL, if I spot this correctly, then page_address()
cannot handle NULL and would try to deref it, no? Am I missing something?
> if (!env->log_buf)
> goto err_unlock;
> + env->log_size = PAGE_SIZE;
> }
[...]
Thanks,
Daniel
next prev parent reply other threads:[~2017-10-05 21:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-05 15:34 [PATCH net-next 0/5] bpf: get rid of global verifier state and reuse instruction printer Jakub Kicinski
2017-10-05 15:34 ` [PATCH net-next 1/5] bpf: remove global verifier log Jakub Kicinski
2017-10-05 15:34 ` [PATCH net-next 2/5] bpf: move instruction printing into a separate file Jakub Kicinski
2017-10-05 15:34 ` [PATCH net-next 3/5] tools: bpftool: use the kernel's instruction printer Jakub Kicinski
2017-10-05 15:34 ` [PATCH net-next 4/5] bpf: don't rely on the verifier lock for metadata_dst allocation Jakub Kicinski
2017-10-05 15:34 ` [PATCH net-next 5/5] bpf: write back the verifier log buffer as it gets filled Jakub Kicinski
2017-10-05 21:10 ` Daniel Borkmann [this message]
2017-10-05 21:26 ` Jakub Kicinski
2017-10-05 21:45 ` Daniel Borkmann
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=59D69FAB.1020605@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=alexei.starovoitov@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.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).