]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: lpm_trie: check left child of last leftmost node for NULL
authorJonathan Lemon <jonathan.lemon@gmail.com>
Sat, 8 Jun 2019 19:54:19 +0000 (12:54 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 11 Jun 2019 11:52:37 +0000 (13:52 +0200)
commit673bf9a9004fd5596ff8cd9c35d614f26222f833
treec818cc12002f9d99b0b710d496f7c1b84ec379a4
parent2c9376e32e6c05bb2b0be5142de32c926cd26382
bpf: lpm_trie: check left child of last leftmost node for NULL

If the leftmost parent node of the tree has does not have a child
on the left side, then trie_get_next_key (and bpftool map dump) will
not look at the child on the right.  This leads to the traversal
missing elements.

Lookup is not affected.

Update selftest to handle this case.

Reproducer:

 bpftool map create /sys/fs/bpf/lpm type lpm_trie key 6 \
     value 1 entries 256 name test_lpm flags 1
 bpftool map update pinned /sys/fs/bpf/lpm key  8 0 0 0  0   0 value 1
 bpftool map update pinned /sys/fs/bpf/lpm key 16 0 0 0  0 128 value 2
 bpftool map dump   pinned /sys/fs/bpf/lpm

Returns only 1 element. (2 expected)

Fixes: 93e5248d3ebb ("bpf: implement MAP_GET_NEXT_KEY command for LPM_TRIE")
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/lpm_trie.c
tools/testing/selftests/bpf/test_lpm_map.c