Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4560064pja; Thu, 21 Nov 2019 21:52:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyQVlRrgRmHqPz2tUQQILk/k4Hvke86Xp1//VVvuaOvKQ7CBcDUkVwj8tsvyTHLcczqZTPn X-Received: by 2002:a17:906:32d0:: with SMTP id k16mr18935528ejk.155.1574401955318; Thu, 21 Nov 2019 21:52:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574401955; cv=none; d=google.com; s=arc-20160816; b=GJGRxcvBkQZd/Mi/G/tQbUSR/bWojw28xZEyLupPtFYmYITnAUyKPNtMZ+smaJe1kp QakwDjBsRZGM9/U1qwUq7oOdSpNpqj996E2b7ZWwxNoft9r2uyX2JJTUxaddqBwKXKCc 8LcCuRKoO1KES51V8UbdxKNcdJRrVAWcK7dXbUKdNkZT290/fxTT2rJuuq9l0b3NS3XT AUgjqI1dJWTNH4xOTGblylFNN4U6e1cTLt9mo1h1S0nzxQSO1lJbuNwbT+NsspGMlLhC to9Nu4WWhE7T4cemg+Cxu4C69lmo+IS03A06QsBjKJVDUgc1zrQevkqv4AxHtN4uPxfO tR9Q== 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 :dkim-signature; bh=omrYyPCw7wsCzYupyQz9lsD8Wk3aZIapCzYWN8J+8qM=; b=Ndu6KdQbzp1lFBdCU5D4/SH3XGzqJSTT2WLKKvSSp9RnEHssb8K3T1WgBsVP3BUTW1 OZD8Ma0TC+Xq8uSbD+Yi7MeDXIR4DOjEHLLAJsSqDzucXPrsPab0Zjjg2JWlJ9hNlq6H BNoalGvoPx+m1Af6+o4R04m/c/61DJGLUPuu59tUKs9gF9wyiC1AaZZUyVqQdIDZ6uYn 6kPs6CXfhik8GHtyNR5JUbR8xD8H47iEsiYYVptGwUqHvAmzL44BcN4LGMNmiFm8Msjp AaPqmwGXsbSm83vNGfMyFYOpCc8ftlfZYCkPMyCCfAglpUWva3P2p1kVchvaTmT6HVyS vZnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t1WeQAAK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si4121723edb.341.2019.11.21.21.52.11; Thu, 21 Nov 2019 21:52:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b=t1WeQAAK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727721AbfKVFu2 (ORCPT + 99 others); Fri, 22 Nov 2019 00:50:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:54924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbfKVFuZ (ORCPT ); Fri, 22 Nov 2019 00:50:25 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B60DB2070A; Fri, 22 Nov 2019 05:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401824; bh=KvXmXgsOBUm4pN/y4t22krllwunUSh8WzMwx6xR7Cok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t1WeQAAKnGDLNRej4TrRZX1G6jafd/Ay+jUUNmwE1zrVz+REDCr1usPME47Poyq/2 LFFCe0q0oaIJKzpHtoX5ClBjaqP2gWNpffjXvPIEiO3Gwumf+iaajmX2EuMMbDKTVB 7N+6adoIbH/Px0ojOZHh9OHAMux49SPwUuYH8Lp0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lepton Wu , Jorgen Hansen , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 067/219] VSOCK: bind to random port for VMADDR_PORT_ANY Date: Fri, 22 Nov 2019 00:46:39 -0500 Message-Id: <20191122054911.1750-60-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lepton Wu [ Upstream commit 8236b08cf50f85bbfaf48910a0b3ee68318b7c4b ] The old code always starts from fixed port for VMADDR_PORT_ANY. Sometimes when VMM crashed, there is still orphaned vsock which is waiting for close timer, then it could cause connection time out for new started VM if they are trying to connect to same port with same guest cid since the new packets could hit that orphaned vsock. We could also fix this by doing more in vhost_vsock_reset_orphans, but any way, it should be better to start from a random local port instead of a fixed one. Signed-off-by: Lepton Wu Reviewed-by: Jorgen Hansen Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/af_vsock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index b2724fb06bbbb..62ec9182f234d 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -107,6 +107,7 @@ #include #include #include +#include #include #include #include @@ -480,9 +481,13 @@ static void vsock_pending_work(struct work_struct *work) static int __vsock_bind_stream(struct vsock_sock *vsk, struct sockaddr_vm *addr) { - static u32 port = LAST_RESERVED_PORT + 1; + static u32 port = 0; struct sockaddr_vm new_addr; + if (!port) + port = LAST_RESERVED_PORT + 1 + + prandom_u32_max(U32_MAX - LAST_RESERVED_PORT); + vsock_addr_init(&new_addr, addr->svm_cid, addr->svm_port); if (addr->svm_port == VMADDR_PORT_ANY) { -- 2.20.1