[Devel] [PATCH rh7 16/16] ms/vhost/vsock: refuse CID assigned to the guest->host transport

Konstantin Khorenko khorenko at virtuozzo.com
Wed Apr 21 15:50:34 MSK 2021


From: Stefano Garzarella <sgarzare at redhat.com>

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 at redhat.com>
Signed-off-by: David S. Miller <davem at davemloft.net>

https://jira.sw.ru/browse/PSBM-128702
(cherry picked from commit ed8640a9612cfd01e1dac31255cea53023353681)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 drivers/vhost/vsock.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index a49d16cc8c62..b31c658f3741 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -677,6 +677,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 */
 	spin_lock_bh(&vhost_vsock_lock);
 	other = vhost_vsock_get(guest_cid);
-- 
2.24.3



More information about the Devel mailing list