selftests/bpf: Make sure optvals > PAGE_SIZE are bypassed
authorStanislav Fomichev <sdf@google.com>
Wed, 17 Jun 2020 01:04:15 +0000 (18:04 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 17 Jun 2020 17:54:05 +0000 (10:54 -0700)
commita0cb12b03132befbdb29d835ca330c18792e8134
treec7fc8a91361a361fb6a56bb024203c834bb9d5b3
parentd8fe449a9c51a37d844ab607e14e2f5c657d3cf2
selftests/bpf: Make sure optvals > PAGE_SIZE are bypassed

We are relying on the fact, that we can pass > sizeof(int) optvals
to the SOL_IP+IP_FREEBIND option (the kernel will take first 4 bytes).
In the BPF program we check that we can only touch PAGE_SIZE bytes,
but the real optlen is PAGE_SIZE * 2. In both cases, we override it to
some predefined value and trim the optlen.

Also, let's modify exiting IP_TOS usecase to test optlen=0 case
where BPF program just bypasses the data as is.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200617010416.93086-2-sdf@google.com
tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
tools/testing/selftests/bpf/progs/sockopt_sk.c