bpf, selftests: Fix racing issue in btf_skc_cls_ingress test
authorMartin KaFai Lau <kafai@fb.com>
Thu, 16 Dec 2021 19:16:30 +0000 (11:16 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Dec 2021 08:30:56 +0000 (09:30 +0100)
commitfcf9194d366c5c2e903c4f0f594d6bffbd92da8e
treeff9a5c367f53819d4b6aaaf841428f70d6da155f
parent6f46c59e60b64620d5d386c8ee2eaa11ebe3b595
bpf, selftests: Fix racing issue in btf_skc_cls_ingress test

[ Upstream commit c2fcbf81c332b42382a0c439bfe2414a241e4f5b ]

The libbpf CI reported occasional failure in btf_skc_cls_ingress:

  test_syncookie:FAIL:Unexpected syncookie states gen_cookie:80326634 recv_cookie:0
  bpf prog error at line 97

"error at line 97" means the bpf prog cannot find the listening socket
when the final ack is received.  It then skipped processing
the syncookie in the final ack which then led to "recv_cookie:0".

The problem is the userspace program did not do accept() and went
ahead to close(listen_fd) before the kernel (and the bpf prog) had
a chance to process the final ack.

The fix is to add accept() call so that the userspace will wait for
the kernel to finish processing the final ack first before close()-ing
everything.

Fixes: 9a856cae2217 ("bpf: selftest: Add test_btf_skc_cls_ingress")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211216191630.466151-1-kafai@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/prog_tests/btf_skc_cls_ingress.c