]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
vhost/vsock: refuse CID assigned to the guest->host transport
authorStefano Garzarella <sgarzare@redhat.com>
Thu, 14 Nov 2019 09:57:50 +0000 (10:57 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Nov 2019 02:12:18 +0000 (18:12 -0800)
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>
drivers/vhost/vsock.c

index fdda9ec625adc5f98e7dfa2536c6f8a60bec41c8..dde392b91bb3a0411aba32333624967a19ab8903 100644 (file)
@@ -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);