Commit d96bfb68 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'vsock-fix-so_zerocopy-on-accept-ed-vsocks'

Michal Luczaj says:

====================
vsock: Fix SO_ZEROCOPY on accept()ed vsocks

vsock has its own handling of setsockopt(SO_ZEROCOPY). Which works just
fine unless socket comes from a call to accept(). Because
SOCK_CUSTOM_SOCKOPT flag is missing, attempting to set the option always
results in errno EOPNOTSUPP.
====================

Link: https://patch.msgid.link/20251229-vsock-child-sock-custom-sockopt-v2-0-64778d6c4f88@rbox.co


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 1806d210 caa20e9e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1787,6 +1787,10 @@ static int vsock_accept(struct socket *sock, struct socket *newsock,
		} else {
			newsock->state = SS_CONNECTED;
			sock_graft(connected, newsock);

			set_bit(SOCK_CUSTOM_SOCKOPT,
				&connected->sk_socket->flags);

			if (vsock_msgzerocopy_allow(vconnected->transport))
				set_bit(SOCK_SUPPORT_ZC,
					&connected->sk_socket->flags);
+32 −0
Original line number Diff line number Diff line
@@ -2192,6 +2192,33 @@ static void test_stream_nolinger_server(const struct test_opts *opts)
	close(fd);
}

static void test_stream_accepted_setsockopt_client(const struct test_opts *opts)
{
	int fd;

	fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
	if (fd < 0) {
		perror("connect");
		exit(EXIT_FAILURE);
	}

	close(fd);
}

static void test_stream_accepted_setsockopt_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);
	}

	enable_so_zerocopy_check(fd);
	close(fd);
}

static struct test_case test_cases[] = {
	{
		.name = "SOCK_STREAM connection reset",
@@ -2371,6 +2398,11 @@ static struct test_case test_cases[] = {
		.run_client = test_seqpacket_unread_bytes_client,
		.run_server = test_seqpacket_unread_bytes_server,
	},
	{
		.name = "SOCK_STREAM accept()ed socket custom setsockopt()",
		.run_client = test_stream_accepted_setsockopt_client,
		.run_server = test_stream_accepted_setsockopt_server,
	},
	{},
};