From: Yiran Qiu <eritque-arcus@ikuyo.dev>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
"Bobby Eshleman" <bobbyeshleman@meta.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
kvm@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Yiran Qiu" <eritque-arcus@ikuyo.dev>
Subject: [PATCH RFC net v2 1/3] vsock/virtio: refuse connect() from a CID the transport does not own
Date: Fri, 30 Oct 2026 02:44:16 -0400 [thread overview]
Message-ID: <20261030064418.133349-2-eritque-arcus@ikuyo.dev> (raw)
In-Reply-To: <20261030064418.133349-1-eritque-arcus@ikuyo.dev>
Since commit c0cfa2d8a788 ("vsock: add multi-transports support"),
bind() accepts any local CID, but connect() picks the transport from the
remote CID only. The virtio transports send from the transport's CID,
so a socket bound to another local CID sends as if it were bound to
the same port on the transport's CID, and its connect() never
completes.
Over vsock_loopback, one process can use this against another that is
bound to (VMADDR_CID_LOCAL, P):
1. it binds to (guest CID, P) and connects to a local listener; the
request arrives from (VMADDR_CID_LOCAL, P) and leaves behind a
child socket for that address, which stays until the listener
accepts and closes it;
2. the other process's connect() to the same listener matches that
child and fails with ECONNRESET.
Refuse such a connect() with EADDRNOTAVAIL, as bind() does for a CID
that is not local. And whenever the virtio connect() fails, set the
socket to TCP_CLOSE, as vmci_transport_connect() does, instead of
leaving it in TCP_SYN_SENT.
Found by an LLM-driven code audit. I reproduced it on unmodified
kernels with the two processes running as different users, without
error injection, and tested the fix with the reproducer and vsock_test
in guests and on a host. Drafted with Claude.
Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
---
net/vmw_vsock/virtio_transport_common.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a480df4..8f524d073ae1 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1219,8 +1219,20 @@ int virtio_transport_connect(struct vsock_sock *vsk)
.vsk = vsk,
.net = sock_net(sk_vsock(vsk)),
};
+ u32 local_cid;
+ int ret;
- return virtio_transport_send_pkt_info(vsk, &info);
+ local_cid = vsk->transport->get_local_cid();
+ if (local_cid != VMADDR_CID_ANY &&
+ vsk->local_addr.svm_cid != VMADDR_CID_ANY &&
+ vsk->local_addr.svm_cid != local_cid)
+ ret = -EADDRNOTAVAIL;
+ else
+ ret = virtio_transport_send_pkt_info(vsk, &info);
+
+ if (ret < 0)
+ sk_vsock(vsk)->sk_state = TCP_CLOSE;
+ return ret;
}
EXPORT_SYMBOL_GPL(virtio_transport_connect);
--
2.56.0
next prev parent reply other threads:[~2026-10-30 6:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 6:44 [PATCH RFC net v2 0/3] vsock/virtio: don't let sockets send from another local CID Yiran Qiu
2026-10-30 6:44 ` Yiran Qiu [this message]
2026-10-30 6:44 ` [PATCH RFC net v2 2/3] vsock/virtio: send credit updates only while connecting or connected Yiran Qiu
2026-10-30 6:44 ` [PATCH RFC net v2 3/3] vsock/virtio: only update a socket's local CID to the transport's CID Yiran Qiu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261030064418.133349-2-eritque-arcus@ikuyo.dev \
--to=eritque-arcus@ikuyo.dev \
--cc=bobbyeshleman@meta.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®