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=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 1CB19C388F3 for ; Fri, 27 Sep 2019 11:28:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E892F21848 for ; Fri, 27 Sep 2019 11:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727890AbfI0L2n (ORCPT ); Fri, 27 Sep 2019 07:28:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64723 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbfI0L2l (ORCPT ); Fri, 27 Sep 2019 07:28:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47D5C18C428E; Fri, 27 Sep 2019 11:28:41 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47A785D9C3; Fri, 27 Sep 2019 11:28:38 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-hyperv@vger.kernel.org, "K. Y. Srinivasan" , Stefan Hajnoczi , Sasha Levin , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "David S. Miller" , virtualization@lists.linux-foundation.org, Stephen Hemminger , Jason Wang , "Michael S. Tsirkin" , Haiyang Zhang , Dexuan Cui , Jorgen Hansen Subject: [RFC PATCH 13/13] vsock: fix bind() behaviour taking care of CID Date: Fri, 27 Sep 2019 13:27:03 +0200 Message-Id: <20190927112703.17745-14-sgarzare@redhat.com> In-Reply-To: <20190927112703.17745-1-sgarzare@redhat.com> References: <20190927112703.17745-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Fri, 27 Sep 2019 11:28:41 +0000 (UTC) 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. 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 750b62711b01..bffa6fa7b8e5 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -230,10 +230,16 @@ static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) { struct vsock_sock *vsk; - list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table) - if (addr->svm_port == vsk->local_addr.svm_port) + list_for_each_entry(vsk, vsock_bound_sockets(addr), bound_table) { + if (vsock_addr_equals_addr(addr, &vsk->local_addr)) return sk_vsock(vsk); + if (addr->svm_port == vsk->local_addr.svm_port && + (vsk->local_addr.svm_cid == VMADDR_CID_ANY || + addr->svm_cid == VMADDR_CID_ANY)) + return sk_vsock(vsk); + } + return NULL; } -- 2.21.0