vsock/test: Add test for sk_error_queue memory leak
Ask for MSG_ZEROCOPY completion notification, but do not recv() it.
Test attempts to create a memory leak, kmemleak should be employed.
Fixed by commit fbf7085b3a ("vsock: Fix sk_error_queue memory leak").
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Link: https://patch.msgid.link/20241219-test-vsock-leaks-v4-6-a416e554d9d7@rbox.co
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
f66ef469a7
commit
ec50efee8c
@@ -1521,6 +1521,46 @@ static void test_stream_leak_acceptq_server(const struct test_opts *opts)
|
||||
}
|
||||
}
|
||||
|
||||
/* Test for a memory leak. User is expected to run kmemleak scan, see README. */
|
||||
static void test_stream_msgzcopy_leak_errq_client(const struct test_opts *opts)
|
||||
{
|
||||
struct pollfd fds = { 0 };
|
||||
int fd;
|
||||
|
||||
fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
|
||||
if (fd < 0) {
|
||||
perror("connect");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
enable_so_zerocopy_check(fd);
|
||||
send_byte(fd, 1, MSG_ZEROCOPY);
|
||||
|
||||
fds.fd = fd;
|
||||
fds.events = 0;
|
||||
if (poll(&fds, 1, -1) < 0) {
|
||||
perror("poll");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void test_stream_msgzcopy_leak_errq_server(const struct test_opts *opts)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
|
||||
if (fd < 0) {
|
||||
perror("accept");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
recv_byte(fd, 1, 0);
|
||||
vsock_wait_remote_close(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static struct test_case test_cases[] = {
|
||||
{
|
||||
.name = "SOCK_STREAM connection reset",
|
||||
@@ -1656,6 +1696,11 @@ static struct test_case test_cases[] = {
|
||||
.run_client = test_stream_leak_acceptq_client,
|
||||
.run_server = test_stream_leak_acceptq_server,
|
||||
},
|
||||
{
|
||||
.name = "SOCK_STREAM MSG_ZEROCOPY leak MSG_ERRQUEUE",
|
||||
.run_client = test_stream_msgzcopy_leak_errq_client,
|
||||
.run_server = test_stream_msgzcopy_leak_errq_server,
|
||||
},
|
||||
{},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user