]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vsock/test: Add test for sk_error_queue memory leak
authorMichal Luczaj <mhal@rbox.co>
Thu, 19 Dec 2024 09:49:33 +0000 (10:49 +0100)
committerJakub Kicinski <kuba@kernel.org>
Mon, 23 Dec 2024 18:28:01 +0000 (10:28 -0800)
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 fbf7085b3ad1 ("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>
tools/testing/vsock/vsock_test.c

index 2a8fcb062d9d207be988da5dd350e503ca20a143..2dec6290b075fb5f7be3a24a4d1372a980389c6a 100644 (file)
@@ -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,
+       },
        {},
 };