From patchwork Fri Dec 6 18:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13897560 X-Patchwork-Delegate: kuba@kernel.org Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 530BC2206B2 for ; Fri, 6 Dec 2024 18:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510163; cv=none; b=V65KMT+pX6gP5pmxBqoiP6JSeriRkF9mFNvbilKwXdhVTfgy2ro5FHq/zD/scEwc7OX3uTvmL4BLLrslW/E+MXjV/CmGLwhdZ/F+XTeV+yG/H/lbRQmYpC+qH8JJ10YVCB3pdaNTMl5b41iIh7rVXhgLBz6fuuu/2xwcp3hGVZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510163; c=relaxed/simple; bh=tSczHC8zpyoIY3iqu4LdXulEkjhCzQOuHl+tISPzKs0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AgU72hNQAN5OGDvLCgPdW2w1zMA0BmwDR866vYWoVdmwn+sJglax5sR2OthIKJ6B3s2zAm0kiEY1JYBj35Wf2aZUuAw0NYUUgFGVNzvY+x6yRNjbMC/uAX1UddS+SqlcGwvwIQgQ1NXI/cjMjRJcr+5PgPwVEWPr1yD6ljMgXKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=fInc+A9g; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="fInc+A9g" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1tJdB7-004OrH-N8; Fri, 06 Dec 2024 19:35:49 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector2; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=wBN7/ol7TUrDrXw5usJz5pglJHSJtQFy2mBXrPf0tJw=; b=fInc+A9gVBd3xiAfCPzxrYGKTD OACaZjLRsQdSAT40e6AMeofj4Z/Aqras4Ilh93a52H+60e/70P/LlbtAp95YDorTRw0GVHsnZ1+Ph 96bpOhzxsaV3FEIwuQOFZ+oQRe2SRB2yAlXg7twKnWfuYuPdQNSoxyWAryGbf+FeXKBErSAnPOlRi e8U+OQSzgTGlN8aBpatSLeC1lkOZjnkMV7uKYST41i+Oy9mpQZ4vVMXjgpGMNNdvbnwwvlVnCKDsA CaQAvmYhIdklDOthLV4yVfXM01fID5TFXC280u3FWJC667JufKQ93TfdYmq9Y/iqqjGnPy3DA4d+j Zyuxv9yg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1tJdB7-0008Fx-CE; Fri, 06 Dec 2024 19:35:49 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1tJdAo-007yMC-SB; Fri, 06 Dec 2024 19:35:30 +0100 From: Michal Luczaj Date: Fri, 06 Dec 2024 19:34:51 +0100 Subject: [PATCH net-next 1/4] vsock/test: Use NSEC_PER_SEC Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-test-vsock-leaks-v1-1-c31e8c875797@rbox.co> References: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> In-Reply-To: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> To: Stefano Garzarella Cc: netdev@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org Replace 1000000000ULL with NSEC_PER_SEC. No functional change intended. Signed-off-by: Michal Luczaj Reviewed-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 48f17641ca504316d1199926149c9bd62eb2921d..38fd8d96eb83ef1bd45728cfaac6adb3c1e07cfe 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "vsock_test_zerocopy.h" #include "timeout.h" @@ -559,7 +560,7 @@ static time_t current_nsec(void) exit(EXIT_FAILURE); } - return (ts.tv_sec * 1000000000ULL) + ts.tv_nsec; + return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec; } #define RCVTIMEO_TIMEOUT_SEC 1 @@ -599,7 +600,7 @@ static void test_seqpacket_timeout_client(const struct test_opts *opts) } read_overhead_ns = current_nsec() - read_enter_ns - - 1000000000ULL * RCVTIMEO_TIMEOUT_SEC; + NSEC_PER_SEC * RCVTIMEO_TIMEOUT_SEC; if (read_overhead_ns > READ_OVERHEAD_NSEC) { fprintf(stderr, From patchwork Fri Dec 6 18:34:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13897562 X-Patchwork-Delegate: kuba@kernel.org Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FD1B1D54E9 for ; Fri, 6 Dec 2024 18:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510164; cv=none; b=gIG7q2G55au0+yoIYs7+h0ytCpayIgSOBF9h5t9NSR88anSubAWzacH4/W4+TyvGXXyZeQrsu89ovTrOfjCpoFrTKwny1sN1puASneNo+NEv4YFCNca8AKptrAJLINfYLMbrN+Ge+faljmPX3JLuZ9sbyCrCKx+ZICea0VLHy+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510164; c=relaxed/simple; bh=GuL9IZPlB88bC5UnrYah42ffJjbrxS7VQAQy21IiOVs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=djBNGdIu6fE+6789qSSzXXF07ZCZD5g+gUup5JOpC0nn+AYJn0dEs/4vBsiNaAbsJeV6iNuPDxwD/a32mClYw7Tga+ETwuMFoaPnNr/Ec2+Mycz1cRC9LK0ZnDUHaJC2XdNKaQkteSQbWyfFSA4yb4UHQO5cfhD4Qwtrw9rbWro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=hB8S72tR; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="hB8S72tR" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1tJdBB-004OrY-9q for netdev@vger.kernel.org; Fri, 06 Dec 2024 19:35:53 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector2; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=3GUQyC2fj9R1fHqov0PL6k7C483BiZ76h8xmnsnDFNA=; b=hB8S72tRDbS/qFPYGNy2yTKf3C 7q8gbQwoT42rkQ9/Kh8O5WwnlfmdXXOF48ulT5tpOcQpXfXDA/BtXRaa1Y4Gb6aRSHDrEB1maMhpr dmhWPdLY7Lt+clSN7brnQyxOahr5Iom1tq6LsgNxH4r1zqCFampY9gLDsKDMtAXa10qfRWcrIypC2 IVOWflQSOJpF5I5IqOK0OHjRKEHJTLKoUoF3O9+hFQBcEw40LF/NbJvfymd38esEd56aEpKEccNt3 NhtdKn6zRI6o+daFeOyPqUAT27NUf+2LRiolnsRT6xrmBbaoTLRZD6EEL9s+vhA2XZLzjXAnIDr5B sJjVE8Iw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1tJdBA-00074I-Tf; Fri, 06 Dec 2024 19:35:53 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1tJdAp-007yMC-3S; Fri, 06 Dec 2024 19:35:31 +0100 From: Michal Luczaj Date: Fri, 06 Dec 2024 19:34:52 +0100 Subject: [PATCH net-next 2/4] vsock/test: Add test for accept_queue memory leak Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-test-vsock-leaks-v1-2-c31e8c875797@rbox.co> References: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> In-Reply-To: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> To: Stefano Garzarella Cc: netdev@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org Attempt to enqueue a child after the queue was flushed, but before SOCK_DONE flag has been set. Fixed by commit d7b0ff5a8667 ("virtio/vsock: Fix accept_queue memory leak"). Signed-off-by: Michal Luczaj --- tools/testing/vsock/vsock_test.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 38fd8d96eb83ef1bd45728cfaac6adb3c1e07cfe..48b6d970bcfa95f957facb7ba2e729a32d256b4a 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1474,6 +1474,45 @@ static void test_stream_cred_upd_on_set_rcvlowat(const struct test_opts *opts) test_stream_credit_update_test(opts, false); } +#define ACCEPTQ_LEAK_RACE_TIMEOUT 2 /* seconds */ + +static void test_stream_leak_acceptq_client(const struct test_opts *opts) +{ + struct sockaddr_vm addr = { + .svm_family = AF_VSOCK, + .svm_port = opts->peer_port, + .svm_cid = opts->peer_cid + }; + time_t tout; + int fd; + + tout = current_nsec() + ACCEPTQ_LEAK_RACE_TIMEOUT * NSEC_PER_SEC; + do { + control_writeulong(1); + + fd = socket(AF_VSOCK, SOCK_STREAM, 0); + if (fd < 0) { + perror("socket"); + exit(EXIT_FAILURE); + } + + connect(fd, (struct sockaddr *)&addr, sizeof(addr)); + close(fd); + } while (current_nsec() < tout); + + control_writeulong(0); +} + +static void test_stream_leak_acceptq_server(const struct test_opts *opts) +{ + int fd; + + while (control_readulong()) { + fd = vsock_stream_listen(VMADDR_CID_ANY, opts->peer_port); + close(fd); + } +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -1604,6 +1643,11 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_unsent_bytes_client, .run_server = test_seqpacket_unsent_bytes_server, }, + { + .name = "SOCK_STREAM leak accept queue", + .run_client = test_stream_leak_acceptq_client, + .run_server = test_stream_leak_acceptq_server, + }, {}, }; From patchwork Fri Dec 6 18:34:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13897563 X-Patchwork-Delegate: kuba@kernel.org Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 061241D54F2 for ; Fri, 6 Dec 2024 18:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510165; cv=none; b=nmFa0YAepM0+eLuCQwM8RKkV75JB6SP7OZUqVzwid7ff1MIHbdLyfl1Z2cbgdsILnw4sZ4iHfF6XzKdTf610i//XGLe65u7xEY/29uBT1wxKxjuk/05ddwTPb4W7Ln89haoNxXdTDh9guPgRmsbTfIXf+ALlrhpnDksErIJ36BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510165; c=relaxed/simple; bh=wsKp3uqS8Ov1CEyMnU9L9U+kSqSydHz+G/75QJSgRV4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nw5iYzApkRE+aMXgL70Tb49LwU760Pt9+t8IuwyVLjf1673sgVqMNjIwvhT+jB5XckcxjyBZhnpxDo9Spy24x5K6ahpmLF3uQZCKqf7sRmuEL1K1Dq6zwkVj3YB6bjYbNo9rr3gyrMOi5cYcRzBOpmFaOKs5xUjASIhVNCW/OP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=X400tChL; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="X400tChL" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1tJdBC-004Ore-9k for netdev@vger.kernel.org; Fri, 06 Dec 2024 19:35:54 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector2; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=AxjTr2jFb+ZBM6cEB1PXWVwtMF0jyXQNRIDwRMMyA4I=; b=X400tChLX418sfLggKzceGBnoJ vLDQBEL6LwdswPRAEDFcn8iuVb2YUAwBIN4L/ToYlLTbyATgolUQmh8JZiguQBiJ2WFbCmg4yf2Je BWZbSNrGV80+3mI8WPNs7c3D9zKZfl2+/eBturRxpLeLIro2X5JRrHocnXdgK8YbaUCGTo9EaKcfn qMW1Tzs1jcLUF7wAV5djE3Zvgu9s9mQ1uzKrXCbNC41BME830ODInAOifRP1+EAjajJ6MiJcc8Gcq LVMthVzZ8qWH8QbZtMzM34/uG3BcrWl+VcTrsSmww2/EMZa3PMYhCKfW4ujQjVPFucCqvPB27rByD o+g+S5eg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1tJdBB-00074O-Vb; Fri, 06 Dec 2024 19:35:54 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1tJdAp-007yMC-BS; Fri, 06 Dec 2024 19:35:31 +0100 From: Michal Luczaj Date: Fri, 06 Dec 2024 19:34:53 +0100 Subject: [PATCH net-next 3/4] vsock/test: Add test for sk_error_queue memory leak Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-test-vsock-leaks-v1-3-c31e8c875797@rbox.co> References: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> In-Reply-To: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> To: Stefano Garzarella Cc: netdev@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org Ask for MSG_ZEROCOPY completion notification, but never actually recv() it. Fixed by commit fbf7085b3ad1 ("vsock: Fix sk_error_queue memory leak"). Signed-off-by: Michal Luczaj --- tools/testing/vsock/vsock_test.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 48b6d970bcfa95f957facb7ba2e729a32d256b4a..f92c62b25a25d35ae63a77a0122a194051719169 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1513,6 +1513,45 @@ static void test_stream_leak_acceptq_server(const struct test_opts *opts) } } +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", @@ -1648,6 +1687,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, + }, {}, }; From patchwork Fri Dec 6 18:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13897561 X-Patchwork-Delegate: kuba@kernel.org Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C387E1D515D for ; Fri, 6 Dec 2024 18:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510164; cv=none; b=m3fmBdKk5tsc9Ex/N9ZZAGGA7eLPQJcy37ffQW96Y7myk9MC2AEYN+/UmjJKjjE6Y9xzAG9Dz19QAI3gguFQd2PQCxEAByz6/eulQ6ny1naNfigq+r4gev14ZZfG7oiVhMpz0dkNcOH+PUpulLTcarZYCGV5mx3mN0NeB34ZkQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733510164; c=relaxed/simple; bh=pEGUBin/LsorY0ZPDZld9BOJ/tu57s2EIBTk/O6y/Tg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S60+AFtQe8RndLviG9qKFtrV+zHU4kRlGZyBi+VXet4zdOu0MAnMAcZTVM+lLza6APfPzh+X0YtBGvFRga/lzqAjLEJsaeQN7LBsfGl51j4yOmN6na+3APyT3ak/cWZhO4FnYSYVsgmRTKIQIS9O7LyFoE9vVBThFIGKR9iunFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=NhHAKFYI; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="NhHAKFYI" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1tJdBA-004OrT-7K; Fri, 06 Dec 2024 19:35:52 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector2; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=nxh02L6aDFisPrlSN5GEXJNL2ZIK2xxyPJNshoQVDFQ=; b=NhHAKFYI2rMuyAM6C04H+8dEKV fR7vv+OgTioL7WgHbSLAdShb3KcW25TFDV1t4+pX8N0Ol7nx2url/so/+Bj0IKx+fD7jaLyvYOozA iRK1r/ThVcWJjs/oechFAB8qAKEbMwnQzN+CBeeyskB69jwY/RufZ6wL1LzXHpu/X1+fYZ5IvFIFQ y9uCGMBm0OdSGAgkBZ99eNVvkTTbvLkrWWowfTlp5h82we5VYYP3tA0O2EO0FX6crSt/PrKXgRicI bwD6mbvWKWfY/Rl90IYOd95YdKwhl1rEbV5ugT8Mj34ZXHPsZQzdNopAY40cZIZrnquvlCbomB26h zj9TtFoQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1tJdB9-0008G2-Od; Fri, 06 Dec 2024 19:35:51 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1tJdAp-007yMC-Jh; Fri, 06 Dec 2024 19:35:31 +0100 From: Michal Luczaj Date: Fri, 06 Dec 2024 19:34:54 +0100 Subject: [PATCH net-next 4/4] vsock/test: Add test for MSG_ZEROCOPY completion memory leak Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-test-vsock-leaks-v1-4-c31e8c875797@rbox.co> References: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> In-Reply-To: <20241206-test-vsock-leaks-v1-0-c31e8c875797@rbox.co> To: Stefano Garzarella Cc: netdev@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org Exercise the ENOMEM error path by attempting to hit net.core.optmem_max limit on send(). Fixed by commit 60cf6206a1f5 ("virtio/vsock: Improve MSG_ZEROCOPY error handling"). Signed-off-by: Michal Luczaj Signed-off-by: Michal Luczaj --- tools/testing/vsock/vsock_test.c | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index f92c62b25a25d35ae63a77a0122a194051719169..6973e681490b363e3b9cedcf195844ba56da6f1d 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1552,6 +1552,67 @@ static void test_stream_msgzcopy_leak_errq_server(const struct test_opts *opts) close(fd); } +static void test_stream_msgzcopy_leak_zcskb_client(const struct test_opts *opts) +{ + char buf[1024] = { 0 }; + ssize_t optmem_max; + int fd, res; + FILE *f; + + f = fopen("/proc/sys/net/core/optmem_max", "r"); + if (!f) { + perror("fopen(optmem_max)"); + exit(EXIT_FAILURE); + } + + if (fscanf(f, "%zd", &optmem_max) != 1 || optmem_max > ~0U / 2) { + fprintf(stderr, "fscanf(optmem_max) failed\n"); + exit(EXIT_FAILURE); + } + + fclose(f); + + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + enable_so_zerocopy_check(fd); + + /* The idea is to fail virtio_transport_init_zcopy_skb() by hitting + * core.sysctl_optmem_max (sysctl net.core.optmem_max) limit check in + * sock_omalloc(). + */ + optmem_max *= 2; + errno = 0; + do { + res = send(fd, buf, sizeof(buf), MSG_ZEROCOPY); + optmem_max -= res; + } while (res > 0 && optmem_max > 0); + + if (errno != ENOMEM) { + fprintf(stderr, "expected ENOMEM on send()\n"); + exit(EXIT_FAILURE); + } + + close(fd); +} + +static void test_stream_msgzcopy_leak_zcskb_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); + } + + vsock_wait_remote_close(fd); + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -1692,6 +1753,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_msgzcopy_leak_errq_client, .run_server = test_stream_msgzcopy_leak_errq_server, }, + { + .name = "SOCK_STREAM MSG_ZEROCOPY leak completion skb", + .run_client = test_stream_msgzcopy_leak_zcskb_client, + .run_server = test_stream_msgzcopy_leak_zcskb_server, + }, {}, };