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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 B2C3FC432C3 for ; Tue, 3 Dec 2019 23:05:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CC8A20656 for ; Tue, 3 Dec 2019 23:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575414334; bh=OmvSs1Np4+6XuiF7LCH4axUwDfhxTQASCp99v57gX8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kLX8FqjJudgse+ZYHpyY6wumyylVweGLL7OaTnF8gBxNMJyfLnFQEwCSom8eeclyt cY+Ada19MfDV+AQYXVqAGwv57SnXb7uFc40UTzcWfP2eg5S3kNGAXzWcGmKDREOELC vlo3AC6B6qD3kCXswmM2YVE/Bn3o4J31+5ytWwPo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729556AbfLCWuN (ORCPT ); Tue, 3 Dec 2019 17:50:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:41438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729694AbfLCWuD (ORCPT ); Tue, 3 Dec 2019 17:50:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6692420862; Tue, 3 Dec 2019 22:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575413402; bh=OmvSs1Np4+6XuiF7LCH4axUwDfhxTQASCp99v57gX8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EavFciJAyy7mcRfZGT95m6O4dBeD7p80yIgEoS73kvSMqzUwRpui1vQdbT87EHJ4A V+SHTSBKDW3/9wo3gwriw7R0N4/iFxuJKhVjE9lMAQWwxOfSrqBag/KQhaffu9kvlD YMdClfA+p10isvGCFkXB7uqozNP2ssQNs8Uh4mrE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lepton Wu , Jorgen Hansen , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 113/321] VSOCK: bind to random port for VMADDR_PORT_ANY Date: Tue, 3 Dec 2019 23:32:59 +0100 Message-Id: <20191203223433.029358892@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191203223427.103571230@linuxfoundation.org> References: <20191203223427.103571230@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 @@ out: 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