Thread (16 messages) read the whole thread 16 messages, 2 authors, 2024-12-17

Re: [PATCH net-next v2 5/6] vsock/test: Add test for sk_error_queue memory leak

From: Stefano Garzarella <sgarzare@redhat.com>
Date: 2024-12-16 14:36:11

On Mon, Dec 16, 2024 at 01:01:01PM +0100, Michal Luczaj wrote:
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").

Signed-off-by: Michal Luczaj <redacted>
---
tools/testing/vsock/vsock_test.c | 45 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 1a9bd81758675a0f2b9b6b0ad9271c45f89a4860..d2970198967e3a2d02ac461921b946e3b0498837 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -1520,6 +1520,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",
@@ -1655,6 +1695,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,
+	},
	{},
};


-- 
2.47.1
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help