[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZ7Yhc8Lt2X9_cMkBHBsxj+G8qnpORG3sT-p6HbjYftVA@mail.gmail.com>
Date: Mon, 25 May 2020 13:34:06 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
Networking <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Kernel Team <kernel-team@...com>,
"Paul E . McKenney" <paulmck@...nel.org>,
Jonathan Lemon <jonathan.lemon@...il.com>
Subject: Re: [PATCH v2 bpf-next 1/7] bpf: implement BPF ring buffer and
verifier support for it
On Thu, May 21, 2020 at 6:07 PM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> On Sun, May 17, 2020 at 12:57:21PM -0700, Andrii Nakryiko wrote:
> > - if (off < 0 || size < 0 || (size == 0 && !zero_size_allowed) ||
> > - off + size > map->value_size) {
> > - verbose(env, "invalid access to map value, value_size=%d off=%d size=%d\n",
> > - map->value_size, off, size);
> > - return -EACCES;
> > - }
> > - return 0;
> > + if (off >= 0 && size_ok && off + size <= mem_size)
> > + return 0;
> > +
> > + verbose(env, "invalid access to memory, mem_size=%u off=%d size=%d\n",
> > + mem_size, off, size);
> > + return -EACCES;
>
> iirc invalid access to map value is one of most common verifier errors that
> people see when they're use unbounded access. Generalizing it to memory is
> technically correct, but it makes the message harder to decipher.
> What is 'mem_size' ? Without context it is difficult to guess that
> it's actually size of map value element.
> Could you make this error message more human friendly depending on
> type of pointer?
I realized that __check_pkt_access is essentially identical and
unified map value, packet, and memory access checks, with custom log
per type of register.
>
> > if (err) {
> > - verbose(env, "R%d min value is outside of the array range\n",
> > + verbose(env, "R%d min value is outside of the memory region\n",
> > regno);
> > return err;
> > }
> > @@ -2518,18 +2527,38 @@ static int check_map_access(struct bpf_verifier_env *env, u32 regno,
> > * If reg->umax_value + off could overflow, treat that as unbounded too.
> > */
> > if (reg->umax_value >= BPF_MAX_VAR_OFF) {
> > - verbose(env, "R%d unbounded memory access, make sure to bounds check any array access into a map\n",
> > + verbose(env, "R%d unbounded memory access, make sure to bounds check any memory region access\n",
> > regno);
> > return -EACCES;
> > }
> > - err = __check_map_access(env, regno, reg->umax_value + off, size,
> > + err = __check_mem_access(env, reg->umax_value + off, size, mem_size,
> > zero_size_allowed);
> > - if (err)
> > - verbose(env, "R%d max value is outside of the array range\n",
> > + if (err) {
> > + verbose(env, "R%d max value is outside of the memory region\n",
> > regno);
>
> I'm not that worried about above three generalizations of errors,
> but if you can make it friendly by describing type of memory region
> I think it will be a plus.
These I left as is (i.e., generic "memory region"), because they were
wrong before (it's more general than just array access), but also
didn't want to clutter code with extra switches or mappings to string,
given that these messages will go right after custom message from
__check_mem_access. Hope that's fine.
Powered by blists - more mailing lists