diff mbox series

[bpf-next] selftests: bpf: Less strict size check in sockopt_sk

Message ID 6f569cca2e45473f9a724d54d03fdfb45f29e35f.1643129402.git.fmaurer@redhat.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series [bpf-next] selftests: bpf: Less strict size check in sockopt_sk | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: linux-kselftest@vger.kernel.org kpsingh@kernel.org daniel@iogearbox.net john.fastabend@gmail.com shuah@kernel.org songliubraving@fb.com yhs@fb.com netdev@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Felix Maurer Jan. 25, 2022, 4:58 p.m. UTC
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>
---
 tools/testing/selftests/bpf/progs/sockopt_sk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stanislav Fomichev Jan. 25, 2022, 5:14 p.m. UTC | #1
On 01/25, Felix Maurer wrote:
> 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.

Looks good, thank you!

Reviewed-by: Stanislav Fomichev <sdf@google.com>

> Fixes: 9cacf81f81611 ("bpf: Remove extra lock_sock for  
> TCP_ZEROCOPY_RECEIVE")
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> ---
>   tools/testing/selftests/bpf/progs/sockopt_sk.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

> 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)
> --
> 2.34.1
diff mbox series

Patch

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)