public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-next] tests: test async_data double-free with sendzc
@ 2022-09-26 13:33 Pavel Begunkov
  2022-09-26 13:36 ` Pavel Begunkov
  2022-09-26 14:34 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Begunkov @ 2022-09-26 13:33 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Similar to send_recv.c:test_invalid().

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/send-zerocopy.c | 59 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index 80723de..1c4e5f2 100644
--- a/test/send-zerocopy.c
+++ b/test/send-zerocopy.c
@@ -533,6 +533,55 @@ static bool io_check_zc_sendmsg(struct io_uring *ring)
 	return p->ops_len > IORING_OP_SENDMSG_ZC;
 }
 
+/* see also send_recv.c:test_invalid */
+static int test_invalid_zc(void)
+{
+	struct io_uring ring;
+	int ret, fds[2];
+	struct io_uring_cqe *cqe;
+	struct io_uring_sqe *sqe;
+	bool notif = false;
+
+	if (!has_sendmsg)
+		return 0;
+
+	ret = t_create_ring(8, &ring, 0);
+	if (ret)
+		return ret;
+	ret = t_create_socket_pair(fds, true);
+	if (ret)
+		return ret;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_sendmsg(sqe, fds[0], NULL, MSG_WAITALL);
+	sqe->opcode = IORING_OP_SENDMSG_ZC;
+	sqe->flags |= IOSQE_ASYNC;
+
+	ret = io_uring_submit(&ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit failed %i\n", ret);
+		return ret;
+	}
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret)
+		return 1;
+	if (cqe->flags & IORING_CQE_F_MORE)
+		notif = true;
+	io_uring_cqe_seen(&ring, cqe);
+
+	if (notif) {
+		ret = io_uring_wait_cqe(&ring, &cqe);
+		if (ret)
+			return 1;
+		io_uring_cqe_seen(&ring, cqe);
+	}
+
+	io_uring_queue_exit(&ring);
+	close(fds[0]);
+	close(fds[1]);
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	struct io_uring ring;
@@ -602,7 +651,7 @@ int main(int argc, char *argv[])
 	ret = test_async_addr(&ring);
 	if (ret) {
 		fprintf(stderr, "test_async_addr() failed\n");
-		return ret;
+		return T_EXIT_FAIL;
 	}
 
 	ret = t_register_buffers(&ring, buffers_iov, ARRAY_SIZE(buffers_iov));
@@ -617,7 +666,13 @@ int main(int argc, char *argv[])
 	ret = test_inet_send(&ring);
 	if (ret) {
 		fprintf(stderr, "test_inet_send() failed\n");
-		return ret;
+		return T_EXIT_FAIL;
+	}
+
+	ret = test_invalid_zc();
+	if (ret) {
+		fprintf(stderr, "test_invalid_zc() failed\n");
+		return T_EXIT_FAIL;
 	}
 out:
 	io_uring_queue_exit(&ring);
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-26 15:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-26 13:33 [PATCH for-next] tests: test async_data double-free with sendzc Pavel Begunkov
2022-09-26 13:36 ` Pavel Begunkov
2022-09-26 14:34 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox