summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Maurer <fmaurer@redhat.com>2022-01-25 17:58:23 +0100
committerAlexei Starovoitov <ast@kernel.org>2022-01-25 18:25:05 -0800
commitfc1ca95585aa4f51e9776f01dffedc1591458c31 (patch)
treebab95f4c12d7a9566af92a7ae993017ad3a81d4c
parent451c4260443a2a7217f33d1ee361602455059452 (diff)
selftests: bpf: Less strict size check in sockopt_sk
Originally, the kernel strictly checked the size of the optval in getsockopt(TCP_ZEROCOPY_RECEIVE) to be equal to sizeof(struct tcp_zerocopy_receive). With c8856c0514549, this was changed to allow optvals of different sizes. The bpf code in the sockopt_sk test was still performing the strict size check. This fix adapts the kernel behavior from c8856c0514549 in the selftest, i.e., just check if the required fields are there. Fixes: 9cacf81f81611 ("bpf: Remove extra lock_sock for TCP_ZEROCOPY_RECEIVE") Signed-off-by: Felix Maurer <fmaurer@redhat.com> Reviewed-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/r/6f569cca2e45473f9a724d54d03fdfb45f29e35f.1643129402.git.fmaurer@redhat.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--tools/testing/selftests/bpf/progs/sockopt_sk.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c
index d0298dccedcd..c8d810010a94 100644
--- a/tools/testing/selftests/bpf/progs/sockopt_sk.c
+++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c
@@ -72,7 +72,8 @@ int _getsockopt(struct bpf_sockopt *ctx)
* reasons.
*/
- if (optval + sizeof(struct tcp_zerocopy_receive) > optval_end)
+ /* Check that optval contains address (__u64) */
+ if (optval + sizeof(__u64) > optval_end)
return 0; /* bounds check */
if (((struct tcp_zerocopy_receive *)optval)->address != 0)