Return-Path: Received: from mail-bn3nam01on0133.outbound.protection.outlook.com ([104.47.33.133]:58170 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754236AbeARVAa (ORCPT ); Thu, 18 Jan 2018 16:00:30 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Vitaly Kuznetsov , KY Srinivasan , Greg Kroah-Hartman , Sasha Levin Subject: [added to the 4.1 stable tree] Drivers: hv: balloon: don't crash when memory is added in non-sorted order Date: Thu, 18 Jan 2018 20:59:52 +0000 Message-ID: <20180118205908.3220-54-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Vitaly Kuznetsov This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 77c0c9735bc0ba5898e637a3a20d6bcb50e3f67d ] When we iterate through all HA regions in handle_pg_range() we have an assumption that all these regions are sorted in the list and the 'start_pfn >=3D has->end_pfn' check is enough to find the proper region. Unfortunately it's not the case with WS2016 where host can hot-add regions in a different order. We end up modifying the wrong HA region and crashing later on pages online. Modify the check to make sure we found the region we were searching for while iterating. Fix the same check in pfn_covered() as well. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/hv/hv_balloon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 9e7f93bcd3ea..15031b46c9c4 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -748,7 +748,7 @@ static int pfn_covered(unsigned long start_pfn, unsigne= d long pfn_cnt) * If the pfn range we are dealing with is not in the current * "hot add block", move on. */ - if ((start_pfn >=3D has->end_pfn)) + if (start_pfn < has->start_pfn || start_pfn >=3D has->end_pfn) continue; =20 /* @@ -811,7 +811,7 @@ static unsigned long handle_pg_range(unsigned long pg_s= tart, * If the pfn range we are dealing with is not in the current * "hot add block", move on. */ - if ((start_pfn >=3D has->end_pfn)) + if (start_pfn < has->start_pfn || start_pfn >=3D has->end_pfn) continue; =20 old_covered_state =3D has->covered_end_pfn; --=20 2.11.0