From: Geliang Tang Date: Thu, 23 May 2024 06:50:03 +0000 (+0800) Subject: selftests/bpf: Check length of recv in test_sockmap X-Git-Tag: v6.11-rc1~163^2~222^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de1b5ea789dc28066cc8dc634b6825bd6148f38b;p=thirdparty%2Fkernel%2Flinux.git selftests/bpf: Check length of recv in test_sockmap The value of recv in msg_loop may be negative, like EWOULDBLOCK, so it's necessary to check if it is positive before accumulating it to bytes_recvd. Fixes: 16962b2404ac ("bpf: sockmap, add selftests") Signed-off-by: Geliang Tang Signed-off-by: Daniel Borkmann Tested-by: Jakub Sitnicki Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/5172563f7c7b2a2e953cef02e89fc34664a7b190.1716446893.git.tanggeliang@kylinos.cn --- diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index e29f8203bd4f1..9cba4ec844a53 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -681,7 +681,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, } } - s->bytes_recvd += recv; + if (recv > 0) + s->bytes_recvd += recv; if (opt->check_recved_len && s->bytes_recvd > total_bytes) { errno = EMSGSIZE;