Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp131467ybc; Mon, 18 Nov 2019 21:51:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwSrkFY9q7n6cuZmd0MCUSb/vyTac8ItOEP8CXpbwzethGmCrFazvQm1JKLXNSeLyHjS8qR X-Received: by 2002:a17:906:958b:: with SMTP id r11mr32533414ejx.332.1574142717205; Mon, 18 Nov 2019 21:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574142717; cv=none; d=google.com; s=arc-20160816; b=DfXrz0e0p5ZV1tpilSqpbpeUYlRT1tAdFgI4EyS54TfXE/6IS0zd+MpSZSJk5HM6mI 3cC3Wvp8BqNDecVeIV/DVKf4KFzN6oIDK2sbawOg1HGPAcWafNNWJCNY17EBMO0Mz2po b2SGRCdLh0hH6YqyUcZPBrIZ9Rl6s1uPiT5ek0XwZF/Lkxhghz2naeqGT+MY7+iEt9P1 HXqe789Cuvy1VShYOofBqDVGV6sSc+vzBmVDvcN4VReuN5p171aWxhNOzrbcj0R8oIhT Uxor9j9fDZfVhb5bwZzuKPa9QPJyjFFS84z+7o3XfcNvly/QeC3b3IJ+vdejlWGHBhX1 3wjA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s/vuDRsXFC2v1fVXVloz6415wfwvUaP2OXPjTPnzQfo=; b=XhJyKRtFw4+HCzRmhmSUzKj10YPgJAWpHMJt5ZsmjiC3rd4Cu/eOPrOH/IAirhVktl 46APmxP3rkA+jn8YjoodAgaFRx7qRq7GA+I2qyfxHYdzJ7FE8KpNOKFrv1pB8SuoVpED aCu7+tyWykGmho8j6Xmnt6YptdyZUnDSY9omOUnYQvHjeFt/NV5+k2D75G2RItNqJ+qv n44Mle4D+WTx+JU5a2vRBkKv5sas2bNacLDuMPMVsgTskd/lZpdMLPv8uB6YrC6JXzAB ryXt+lxzpWuXvXpJA9xK+z78VLPgVLuG4I2ABKSWWMu8lhtsKGSH4IIc49VAhcWXLO1I KMEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MXSWj9Ju; 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 k14si12280275eji.255.2019.11.18.21.51.32; Mon, 18 Nov 2019 21:51:57 -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=MXSWj9Ju; 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 S1731077AbfKSFs3 (ORCPT + 99 others); Tue, 19 Nov 2019 00:48:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:44996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730809AbfKSFsZ (ORCPT ); Tue, 19 Nov 2019 00:48:25 -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 B78052075E; Tue, 19 Nov 2019 05:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574142505; bh=hmx5Rpbn7yfuwK7i95I3Vro9XyTui2okvZWKHzrJrQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MXSWj9Juywn5LtPsZAxCflpIwWd5K0R1BW9O2AdCFCoW3Dqh5H+Eg5+uU5yhSB3JZ rErcg9kKCNJ8QLT3ER6AEFs5jg3QndsbWz3qmfKlg4LCDjWAflzMklSfhybXchtwnH 78CCFcs0iIS/0xa1Ik2ayrBpabzoTXZoUWhF+lxo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kelley , Dan Carpenter , "K. Y. Srinivasan" , Sasha Levin Subject: [PATCH 4.14 104/239] Drivers: hv: vmbus: Fix synic per-cpu context initialization Date: Tue, 19 Nov 2019 06:18:24 +0100 Message-Id: <20191119051325.796790982@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191119051255.850204959@linuxfoundation.org> References: <20191119051255.850204959@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: Michael Kelley [ Upstream commit f25a7ece08bdb1f2b3c4bbeae942682fc3a99dde ] If hv_synic_alloc() errors out, the state of the per-cpu context for some CPUs is unknown since the zero'ing is done as each CPU is iterated over. In such case, hv_synic_cleanup() may try to free memory based on uninitialized values. Fix this by zero'ing the per-cpu context for all CPUs before doing any memory allocations that might fail. Signed-off-by: Michael Kelley Reported-by: Dan Carpenter Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/hv/hv.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index fe041f22521da..23f312b4c6aa2 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -148,6 +148,17 @@ static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu) int hv_synic_alloc(void) { int cpu; + struct hv_per_cpu_context *hv_cpu; + + /* + * First, zero all per-cpu memory areas so hv_synic_free() can + * detect what memory has been allocated and cleanup properly + * after any failures. + */ + for_each_present_cpu(cpu) { + hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); + memset(hv_cpu, 0, sizeof(*hv_cpu)); + } hv_context.hv_numa_map = kzalloc(sizeof(struct cpumask) * nr_node_ids, GFP_ATOMIC); @@ -157,10 +168,8 @@ int hv_synic_alloc(void) } for_each_present_cpu(cpu) { - struct hv_per_cpu_context *hv_cpu - = per_cpu_ptr(hv_context.cpu_context, cpu); + hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); - memset(hv_cpu, 0, sizeof(*hv_cpu)); tasklet_init(&hv_cpu->msg_dpc, vmbus_on_msg_dpc, (unsigned long) hv_cpu); -- 2.20.1