Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6440376ybl; Wed, 15 Jan 2020 04:48:24 -0800 (PST) X-Google-Smtp-Source: APXvYqw4S6ittr+AkF0RvttXWLcC2HyWAro0Vg2ZaPOHVakNNvMzHRxkfLTqZ+pP/+Y1KKnqw1cm X-Received: by 2002:a9d:7d99:: with SMTP id j25mr2424724otn.226.1579092504808; Wed, 15 Jan 2020 04:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579092504; cv=none; d=google.com; s=arc-20160816; b=eDXzfp7E0yxgiwoQJ2TZV4tAyVYE+L6zOkZ6UBuviFAye8Y7lZBgw/HXWWt4txWC2e nYdLXQRHG2eegjz29Lme1YNL8KTZENRvB94QAxg1BHAmxdp9WjCeUwB0vOc0D4lUeFHi EZAAC8dan2GkA2cgx+jzw9KihUW05/OZqS+Z9G+yqWRNFuWCkBLd40EAfm3XFMCSDbCO sbHtjnP9nIOIeGX6hxb812fDNLa9TlO1Cz1DULplRbJ9glIW7F3PXRzRQdFhqn9Ug+Oe 9KqfXVQLEg5OO0Jq2Q7sHrojv0Xhj9pb0SCvGZvfn5Wx6FQKIFaFSX/vDZT8tAM15m8I viaA== 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:from:subject:cc:to:message-id:date; bh=KCSNLiHCK+Eiavoc0Gh/bHoml+hNdaZ7oA857dMjsiE=; b=c2qbAAVIvns3ssRTjo/v3cuZnmMye7jPDSnrgd7fosE5173G5KQsohxcfFQRPgKo55 p/rfTR0J68dhiYonnINLk5+v8R/8dAHj2z5YQu9Bw4shIp7/REYg8w+s6xG8s+yNI5In SK6OXkFEPBg26qhbuV47YHJrXK46WX9T2YS9gcCOpKh8NGSRjetUrUdfN3DgJc7AbzVB 2UQw5uVxrLvk0eInjb5U3i3/NEwXknWdFjVwzWhYGSg95Y3ozfy3+oP/VxdjKuv0RJ3u OsHL5myuze/X+/pGeZPONnvI81m3/J6or9YvfZeISHY5Kp7NwphSzM62Va7I/HUckKvO UY3w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26si10924898otp.239.2020.01.15.04.48.12; Wed, 15 Jan 2020 04:48:24 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729106AbgAOMrT (ORCPT + 99 others); Wed, 15 Jan 2020 07:47:19 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:55484 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729030AbgAOMrT (ORCPT ); Wed, 15 Jan 2020 07:47:19 -0500 Received: from localhost (unknown [62.21.130.100]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id CA176159E75BD; Wed, 15 Jan 2020 04:47:16 -0800 (PST) Date: Tue, 14 Jan 2020 11:51:27 -0800 (PST) Message-Id: <20200114.115127.2012708883911771822.davem@davemloft.net> To: sunilmut@microsoft.com Cc: netdev@vger.kernel.org, decui@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net]: hv_sock: Remove the accept port restriction From: David Miller In-Reply-To: References: X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Wed, 15 Jan 2020 04:47:18 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sunil Muthuswamy Date: Tue, 14 Jan 2020 00:52:14 +0000 > Currently, hv_sock restricts the port the guest socket can accept > connections on. hv_sock divides the socket port namespace into two parts > for server side (listening socket), 0-0x7FFFFFFF & 0x80000000-0xFFFFFFFF > (there are no restrictions on client port namespace). The first part > (0-0x7FFFFFFF) is reserved for sockets where connections can be accepted. > The second part (0x80000000-0xFFFFFFFF) is reserved for allocating ports > for the peer (host) socket, once a connection is accepted. > This reservation of the port namespace is specific to hv_sock and not > known by the generic vsock library (ex: af_vsock). This is problematic > because auto-binds/ephemeral ports are handled by the generic vsock > library and it has no knowledge of this port reservation and could > allocate a port that is not compatible with hv_sock (and legitimately so). > The issue hasn't surfaced so far because the auto-bind code of vsock > (__vsock_bind_stream) prior to the change 'VSOCK: bind to random port for > VMADDR_PORT_ANY' would start walking up from LAST_RESERVED_PORT (1023) and > start assigning ports. That will take a large number of iterations to hit > 0x7FFFFFFF. But, after the above change to randomize port selection, the > issue has started coming up more frequently. > There has really been no good reason to have this port reservation logic > in hv_sock from the get go. Reserving a local port for peer ports is not > how things are handled generally. Peer ports should reflect the peer port. > This fixes the issue by lifting the port reservation, and also returns the > right peer port. Since the code converts the GUID to the peer port (by > using the first 4 bytes), there is a possibility of conflicts, but that > seems like a reasonable risk to take, given this is limited to vsock and > that only applies to all local sockets. > > Signed-off-by: Sunil Muthuswamy Applied.