selftests/bpf: fix race in flow dissector tests
authorPetar Penkov <ppenkov@google.com>
Mon, 12 Aug 2019 23:30:39 +0000 (16:30 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 13 Aug 2019 14:31:10 +0000 (16:31 +0200)
commit9840a4ffcf0b26e08472ed53d176a6a0f1d4c498
tree5b8fa71c24e314f5c38f7ab7bab4212e30f24ecf
parentd66fa3c70e598746a907e5db5ed024035e01817a
selftests/bpf: fix race in flow dissector tests

Since the "last_dissection" map holds only the flow keys for the most
recent packet, there is a small race in the skb-less flow dissector
tests if a new packet comes between transmitting the test packet, and
reading its keys from the map. If this happens, the test packet keys
will be overwritten and the test will fail.

Changing the "last_dissection" map to a hash map, keyed on the
source/dest port pair resolves this issue. Additionally, let's clear the
last test results from the map between tests to prevent previous test
cases from interfering with the following test cases.

Fixes: 0905beec9f52 ("selftests/bpf: run flow dissector tests in skb-less mode")
Signed-off-by: Petar Penkov <ppenkov@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/prog_tests/flow_dissector.c
tools/testing/selftests/bpf/progs/bpf_flow.c