]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, lpm: fix lookup bug in map_delete_elem
authorAlban Crequy <alban@kinvolk.io>
Fri, 22 Feb 2019 13:19:08 +0000 (14:19 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 22 Feb 2019 15:17:53 +0000 (16:17 +0100)
commit678dff99294ec55f1df6a1a3794dee77d5b1ae83
tree33c363871acaa11f887127e85c03c072677a555b
parentaec3680c9d61755ed6669bc6fe35a5b93f9dceb1
bpf, lpm: fix lookup bug in map_delete_elem

trie_delete_elem() was deleting an entry even though it was not matching
if the prefixlen was correct. This patch adds a check on matchlen.

Reproducer:

$ sudo bpftool map create /sys/fs/bpf/mylpm type lpm_trie key 8 value 1 entries 128 name mylpm flags 1
$ sudo bpftool map update pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 aa bb cc dd value hex 01
$ sudo bpftool map dump pinned /sys/fs/bpf/mylpm
key: 10 00 00 00 aa bb cc dd  value: 01
Found 1 element
$ sudo bpftool map delete pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 ff ff ff ff
$ echo $?
0
$ sudo bpftool map dump pinned /sys/fs/bpf/mylpm
Found 0 elements

A similar reproducer is added in the selftests.

Without the patch:

$ sudo ./tools/testing/selftests/bpf/test_lpm_map
test_lpm_map: test_lpm_map.c:485: test_lpm_delete: Assertion `bpf_map_delete_elem(map_fd, key) == -1 && errno == ENOENT' failed.
Aborted

With the patch: test_lpm_map runs without errors.

Fixes: 77f1747d1e63 ("bpf: Implement map_delete_elem for BPF_MAP_TYPE_LPM_TRIE")
Cc: Craig Gallek <kraig@google.com>
Signed-off-by: Alban Crequy <alban@kinvolk.io>
Acked-by: Craig Gallek <kraig@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/lpm_trie.c
tools/testing/selftests/bpf/test_lpm_map.c