Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3309551ybn; Fri, 27 Sep 2019 04:32:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfBIYgItz58dNGYPp01R5GpOCV5grOtzmsqUC1Ma9yQDdEdMPwoo9IbQULuuxlQH/Jl5sG X-Received: by 2002:a17:906:3db2:: with SMTP id y18mr7445817ejh.68.1569583935294; Fri, 27 Sep 2019 04:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569583935; cv=none; d=google.com; s=arc-20160816; b=GXOP4i3JELVuBWLG7gf6E6oJuzGABB0UvCMoHpXUAWSTS6eJOL6sYV9dxcH36Hf3KV 8f5O1hu0zG/47iZdvXUAeRPIUhP5tg8Spbl0BoaNZk1jZohPUkpKRhh6B0zjgj2l5Il5 mLRj8q0N1h6ocWfoTgQO/1As7MnToOe/pmZZqnuFFvg1Epn/h5oLyvjQ9oCfoPDPLzSd 4xY6dWzxpqQXBWWHoqJuelnc0NP6PKBdnRFLNDM3iBcKk9ZNp8yJxYXx4RPaMfbI6dqO 4twFQ/+ROyTPQkMOdVmFEh2y9TVU+4mRvtR2qO5kFyR8m/HLN5fBtmDgDKa9ystmxMkV JZ4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ekn5jG2YF0JQRoFyOLKeY83haX9Y8WT8GI107pbZ484=; b=m8I1j+huiP38GmfRhT7jcQJ8s8gachT01oh73G+ZTGR7ZBVxvIWHETPx+BBaWqPxJV 9xQEt4qEsORQ7/9nrjb9KAN9jniLfeCSRzoKFWsUMdLPt+g4Bx6FQFGZytzTTNWc+lYn sIhHhTpypnkA5bZUyeXSP2neM4IiORyTxUv4+Oqa5zAmRPMQ8CDwa6zVM7nuCoT+UCig FJDS3BSBEyh+LaZN62hVuvh9ZHoKZLknRT89WKsQpuFCVVEuLo3rxAqhXEFrs5e/YloE XZKky7WC6qkf0CEO1tjzokweASYEnlX778H8CYZceoVbgO4Z5Cubl7QCfzl2NSaeqKRv avGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si2532449eju.351.2019.09.27.04.31.50; Fri, 27 Sep 2019 04:32:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727869AbfI0L2n (ORCPT + 99 others); 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