From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC50FC432C3 for ; Thu, 14 Nov 2019 09:59:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 989922070E for ; Thu, 14 Nov 2019 09:59:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aGh47xNq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727438AbfKNJ7b (ORCPT ); Thu, 14 Nov 2019 04:59:31 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:30501 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727500AbfKNJ7Y (ORCPT ); Thu, 14 Nov 2019 04:59:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573725563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f6p99asKfS17+1LG2xwN+D8QSOUVOyNnDSLD47Fl13g=; b=aGh47xNqfzE9HVzs0pywmRl9zAvBrLZr5l0oVvMtsiJXFkz0Zu7zPQJX6fEXvm8YBf61Qv 6SNxXZBD9KTVuQlyrnmp5B0fSyVzABV49aswz5kgxCpAOjU8zho7dnRDb4C2XXJ/CPU4JG pq2nxoXerhmb9wWjOwFBSzvOxgQdeW0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-e3OCytPZPqa2rbdTCFHZcQ-1; Thu, 14 Nov 2019 04:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F308E800052; Thu, 14 Nov 2019 09:59:19 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-81.ams2.redhat.com [10.36.117.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D826165DB; Thu, 14 Nov 2019 09:59:14 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Stephen Hemminger , Arnd Bergmann , Jorgen Hansen , Jason Wang , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Haiyang Zhang , Stefan Hajnoczi , "David S. Miller" , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Sasha Levin , "K. Y. Srinivasan" , Dexuan Cui , linux-hyperv@vger.kernel.org Subject: [PATCH net-next v2 15/15] vhost/vsock: refuse CID assigned to the guest->host transport Date: Thu, 14 Nov 2019 10:57:50 +0100 Message-Id: <20191114095750.59106-16-sgarzare@redhat.com> In-Reply-To: <20191114095750.59106-1-sgarzare@redhat.com> References: <20191114095750.59106-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: e3OCytPZPqa2rbdTCFHZcQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-hyperv-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org 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 --- drivers/vhost/vsock.c | 6 ++++++ 1 file changed, 6 insertions(+) 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 *vso= ck, u64 guest_cid) =09if (guest_cid > U32_MAX) =09=09return -EINVAL; =20 +=09/* Refuse if CID is assigned to the guest->host transport (i.e. nested +=09 * VM), to make the loopback work. +=09 */ +=09if (vsock_find_cid(guest_cid)) +=09=09return -EADDRINUSE; + =09/* Refuse if CID is already in use */ =09mutex_lock(&vhost_vsock_mutex); =09other =3D vhost_vsock_get(guest_cid); --=20 2.21.0