]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit - kernel/bpf/verifier.c
bpf: Fix and simplifications on inline map lookup
authorMartin KaFai Lau <kafai@fb.com>
Wed, 22 Mar 2017 17:00:32 +0000 (10:00 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 22 Mar 2017 22:45:45 +0000 (15:45 -0700)
commitfad73a1a35ea61f13607a391aca669caad8c04ca
tree1070c51ee7354ee35ef1e23f17b7ce483c316144
parentb4f0a66155564aaf7e98492e027efad9f797c244
bpf: Fix and simplifications on inline map lookup

Fix in verifier:
For the same bpf_map_lookup_elem() instruction (i.e. "call 1"),
a broken case is "a different type of map could be used for the
same lookup instruction". For example, an array in one case and a
hashmap in another.  We have to resort to the old dynamic call behavior
in this case.  The fix is to check for collision on insn_aux->map_ptr.
If there is collision, don't inline the map lookup.

Please see the "do_reg_lookup()" in test_map_in_map_kern.c in the later
patch for how-to trigger the above case.

Simplifications on array_map_gen_lookup():
1. Calculate elem_size from map->value_size.  It removes the
   need for 'struct bpf_array' which makes the later map-in-map
   implementation easier.
2. Remove the 'elem_size == 1' test

Fixes: 81ed18ab3098 ("bpf: add helper inlining infra and optimize map_array lookup")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/arraymap.c
kernel/bpf/verifier.c