selftests/bpf: Extend verifier and bpf_sock tests for dst_port loads
authorJakub Sitnicki <jakub@cloudflare.com>
Mon, 1 Aug 2022 14:48:50 +0000 (17:48 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Aug 2022 11:07:50 +0000 (13:07 +0200)
commit119debdb9f25b1b24f6c52aa9b8a4aa4b51e2465
treed39e5fc2996646541ce26e4b3ebfd6ccb7e03b63
parentdf9692b8a31902d8f0ae9e3f81cb4465431e22cc
selftests/bpf: Extend verifier and bpf_sock tests for dst_port loads

commit 8f50f16ff39dd4e2d43d1548ca66925652f8aff7 upstream.

Add coverage to the verifier tests and tests for reading bpf_sock fields to
ensure that 32-bit, 16-bit, and 8-bit loads from dst_port field are allowed
only at intended offsets and produce expected values.

While 16-bit and 8-bit access to dst_port field is straight-forward, 32-bit
wide loads need be allowed and produce a zero-padded 16-bit value for
backward compatibility.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/r/20220130115518.213259-3-jakub@cloudflare.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/include/uapi/linux/bpf.h
tools/testing/selftests/bpf/prog_tests/sock_fields.c
tools/testing/selftests/bpf/progs/test_sock_fields.c
tools/testing/selftests/bpf/verifier/sock.c