Skip to content

Commit

Permalink
selftests/bpf: Check length of recv in test_sockmap
Browse files Browse the repository at this point in the history
[ Upstream commit de1b5ea ]

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: 16962b2 ("bpf: sockmap, add selftests")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/5172563f7c7b2a2e953cef02e89fc34664a7b190.1716446893.git.tanggeliang@kylinos.cn
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Geliang Tang authored and gregkh committed Aug 3, 2024
1 parent 801a590 commit 0340b8f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/test_sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,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;
Expand Down

0 comments on commit 0340b8f

Please sign in to comment.