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 AD00ECA9EB6 for ; Wed, 23 Oct 2019 09:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E35E2064A for ; Wed, 23 Oct 2019 09:58:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QJ+5wu1o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390964AbfJWJ6d (ORCPT ); Wed, 23 Oct 2019 05:58:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:48267 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404264AbfJWJ6a (ORCPT ); Wed, 23 Oct 2019 05:58:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571824709; 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=4hlyQY7efj0/bE9XNJxDmJdAwsinzkA8wmlvgDq7ouo=; b=QJ+5wu1oG4E8sT3YRqBVzpHO/OZ8rhqYljCtOosMUsyLsspIyU1hWDiGfBqodEgZ9G0iTR HHpBIOCgBJpiBBAY4Mu/qnxZyyryaBE8O9jThhmrSWOcEnmmTUCCsU8d85SfrbcVxYLGH6 oKapWpZb/hW7CxBp0a1QQ76CIjfUBAo= 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-2-ra2LyVtEPBinyv25NmhJEg-1; Wed, 23 Oct 2019 05:58:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5DE41005500; Wed, 23 Oct 2019 09:58:25 +0000 (UTC) Received: from steredhat.redhat.com (unknown [10.36.118.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 156735C1B2; Wed, 23 Oct 2019 09:58:19 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: "Michael S. Tsirkin" , kvm@vger.kernel.org, Greg Kroah-Hartman , Jason Wang , "David S. Miller" , Dexuan Cui , Haiyang Zhang , Jorgen Hansen , Sasha Levin , linux-kernel@vger.kernel.org, Arnd Bergmann , Stefan Hajnoczi , linux-hyperv@vger.kernel.org, "K. Y. Srinivasan" , Stephen Hemminger , virtualization@lists.linux-foundation.org Subject: [PATCH net-next 14/14] vsock: fix bind() behaviour taking care of CID Date: Wed, 23 Oct 2019 11:55:54 +0200 Message-Id: <20191023095554.11340-15-sgarzare@redhat.com> In-Reply-To: <20191023095554.11340-1-sgarzare@redhat.com> References: <20191023095554.11340-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: ra2LyVtEPBinyv25NmhJEg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we are looking for a socket bound to a specific address, we also have to take into account the CID. This patch is useful with multi-transports support because it allows the binding of the same port with different CID, and it prevents a connection to a wrong socket bound to the same port, but with different CID. Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 1f2e707cae66..7183de277072 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -228,10 +228,16 @@ static struct sock *__vsock_find_bound_socket(struct = sockaddr_vm *addr) { =09struct vsock_sock *vsk; =20 -=09list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table) -=09=09if (addr->svm_port =3D=3D vsk->local_addr.svm_port) +=09list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table) { +=09=09if (vsock_addr_equals_addr(addr, &vsk->local_addr)) =09=09=09return sk_vsock(vsk); =20 +=09=09if (addr->svm_port =3D=3D vsk->local_addr.svm_port && +=09=09 (vsk->local_addr.svm_cid =3D=3D VMADDR_CID_ANY || +=09=09 addr->svm_cid =3D=3D VMADDR_CID_ANY)) +=09=09=09return sk_vsock(vsk); +=09} + =09return NULL; } =20 --=20 2.21.0