Thread (33 messages) flat view 33 messages, 6 authors, 2020-05-26

Re: [PATCH v2 bpf-next 1/7] bpf: implement BPF ring buffer and verifier support for it

From: Andrii Nakryiko <hidden>
Date: 2020-05-22 18:48:23
Also in: bpf

On Thu, May 21, 2020 at 6:07 PM Alexei Starovoitov
[off-list ref] wrote:
On Sun, May 17, 2020 at 12:57:21PM -0700, Andrii Nakryiko wrote:
quoted
-     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?
yep, sure, better verifier errors are extremely important, I think
quoted
      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.
I agree, will update
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help