summary refs log tree commit diff
path: root/drivers/vhost/vsock.c
diff options
context:
space:
mode:
authorStefano Garzarella <sgarzare@redhat.com>2019-11-14 10:57:50 +0100
committerDavid S. Miller <davem@davemloft.net>2019-11-14 18:12:18 -0800
commited8640a9612cfd01e1dac31255cea53023353681 (patch)
treea1b3646ed5ce6b6db5c1f4c5e3db8bc704caa948 /drivers/vhost/vsock.c
parent36c5b48b91ac56762ef87e4af76350ed50f119b5 (diff)
downloadlinux-ed8640a9612cfd01e1dac31255cea53023353681.tar.gz
vhost/vsock: refuse CID assigned to the guest->host transport
In a nested VM environment, we have to refuse to assign to a nested
guest the same CID assigned to our guest->host transport.
In this way, the user can use the local CID for loopback.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/vhost/vsock.c')
-rw-r--r--drivers/vhost/vsock.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index fdda9ec625ad..dde392b91bb3 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -718,6 +718,12 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)
 	if (guest_cid > U32_MAX)
 		return -EINVAL;
 
+	/* Refuse if CID is assigned to the guest->host transport (i.e. nested
+	 * VM), to make the loopback work.
+	 */
+	if (vsock_find_cid(guest_cid))
+		return -EADDRINUSE;
+
 	/* Refuse if CID is already in use */
 	mutex_lock(&vhost_vsock_mutex);
 	other = vhost_vsock_get(guest_cid);