From patchwork Wed Jan 8 15:06:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11323879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 715721395 for ; Wed, 8 Jan 2020 15:08:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5754820705 for ; Wed, 8 Jan 2020 15:08:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5754820705 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipCud-0001WX-VE; Wed, 08 Jan 2020 15:06:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipCuc-0001WS-23 for xen-devel@lists.xenproject.org; Wed, 08 Jan 2020 15:06:22 +0000 X-Inumbo-ID: 68e0caaa-3228-11ea-b1f0-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 68e0caaa-3228-11ea-b1f0-bc764e2007e4; Wed, 08 Jan 2020 15:06:13 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5E124ADE0; Wed, 8 Jan 2020 15:06:12 +0000 (UTC) To: "xen-devel@lists.xenproject.org" From: Jan Beulich Message-ID: Date: Wed, 8 Jan 2020 16:06:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 Content-Language: en-US Subject: [Xen-devel] [PATCH] x86/MCE: avoid leaking stack data X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Ilja Van Sprundel , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" While HYPERVISOR_mca is a privileged operation, we still shouldn't leak stack contents (the tail of every array entry's mc_msrvalues[] of XEN_MC_physcpuinfo output). Simply use a zeroing allocation here. Take the occasion and also restrict the involved local variable's scope. Reported-by: Ilja Van Sprundel Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -1352,7 +1352,6 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_m } mc_physcpuinfo; uint32_t flags, cmdflags; int nlcpu; - xen_mc_logical_cpu_t *log_cpus = NULL; mctelem_cookie_t mctc; mctelem_class_t which; unsigned int target; @@ -1445,11 +1444,13 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_m ? !guest_handle_is_null(mc_physcpuinfo.nat->info) : !compat_handle_is_null(mc_physcpuinfo.cmp->info) ) { + xen_mc_logical_cpu_t *log_cpus; + if ( mc_physcpuinfo.nat->ncpus <= 0 ) return x86_mcerr("do_mca cpuinfo: ncpus <= 0", -EINVAL); nlcpu = min(nlcpu, (int)mc_physcpuinfo.nat->ncpus); - log_cpus = xmalloc_array(xen_mc_logical_cpu_t, nlcpu); + log_cpus = xzalloc_array(xen_mc_logical_cpu_t, nlcpu); if ( log_cpus == NULL ) return x86_mcerr("do_mca cpuinfo", -ENOMEM); on_each_cpu(do_mc_get_cpu_info, log_cpus, 1);