Skip to content

Commit ec50efe

Browse files
mmhalkuba-moo
authored andcommitted
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 fbf7085 ("vsock: Fix sk_error_queue memory leak"). Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f66ef46 commit ec50efe

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tools/testing/vsock/vsock_test.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,46 @@ static void test_stream_leak_acceptq_server(const struct test_opts *opts)
15211521
}
15221522
}
15231523

1524+
/* Test for a memory leak. User is expected to run kmemleak scan, see README. */
1525+
static void test_stream_msgzcopy_leak_errq_client(const struct test_opts *opts)
1526+
{
1527+
struct pollfd fds = { 0 };
1528+
int fd;
1529+
1530+
fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
1531+
if (fd < 0) {
1532+
perror("connect");
1533+
exit(EXIT_FAILURE);
1534+
}
1535+
1536+
enable_so_zerocopy_check(fd);
1537+
send_byte(fd, 1, MSG_ZEROCOPY);
1538+
1539+
fds.fd = fd;
1540+
fds.events = 0;
1541+
if (poll(&fds, 1, -1) < 0) {
1542+
perror("poll");
1543+
exit(EXIT_FAILURE);
1544+
}
1545+
1546+
close(fd);
1547+
}
1548+
1549+
static void test_stream_msgzcopy_leak_errq_server(const struct test_opts *opts)
1550+
{
1551+
int fd;
1552+
1553+
fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
1554+
if (fd < 0) {
1555+
perror("accept");
1556+
exit(EXIT_FAILURE);
1557+
}
1558+
1559+
recv_byte(fd, 1, 0);
1560+
vsock_wait_remote_close(fd);
1561+
close(fd);
1562+
}
1563+
15241564
static struct test_case test_cases[] = {
15251565
{
15261566
.name = "SOCK_STREAM connection reset",
@@ -1656,6 +1696,11 @@ static struct test_case test_cases[] = {
16561696
.run_client = test_stream_leak_acceptq_client,
16571697
.run_server = test_stream_leak_acceptq_server,
16581698
},
1699+
{
1700+
.name = "SOCK_STREAM MSG_ZEROCOPY leak MSG_ERRQUEUE",
1701+
.run_client = test_stream_msgzcopy_leak_errq_client,
1702+
.run_server = test_stream_msgzcopy_leak_errq_server,
1703+
},
16591704
{},
16601705
};
16611706

0 commit comments

Comments
 (0)