From patchwork Fri Aug 12 10:35:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9276701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D0B8E60CDC for ; Fri, 12 Aug 2016 10:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0C3A28957 for ; Fri, 12 Aug 2016 10:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5AD82896A; Fri, 12 Aug 2016 10:38:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3617928969 for ; Fri, 12 Aug 2016 10:38:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bY9oM-0007yj-Ur; Fri, 12 Aug 2016 10:35:34 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bY9oL-0007xn-JX for xen-devel@lists.xen.org; Fri, 12 Aug 2016 10:35:33 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id B4/D4-12874-C66ADA75; Fri, 12 Aug 2016 10:35:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42JxWrrBXjdn2dp wg5lnWC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyGF2UFu2Uqlja8YW9gnC3excjBISHgL/Hj X3EXIycHm4C+xO4Xn5hAbBEBdYnTHRdZQUqYBfwkDj3wBQkLCwRLbLiwFqyERUBVYuWceywgN q+Ap8S/z8+ZQWwJATmJ88d/gtmcAl4SN6/vZQWxhYBqZkyaywxhq0lc67/EDtErKHFy5hOwOc wCEhIHX7xghriMW+Jvt/0ERr5ZSKpmIalawMi0ilGjOLWoLLVI19BEL6koMz2jJDcxM0fX0MB ULze1uDgxPTUnMalYLzk/dxMjMJgYgGAH49nTnocYJTmYlER5V01eGy7El5SfUpmRWJwRX1Sa k1p8iFGGg0NJgld0KVBOsCg1PbUiLTMHGNYwaQkOHiUR3iiQNG9xQWJucWY6ROoUo6KUOC87S EIAJJFRmgfXBoulS4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLmjQOZwpOZVwI3/RXQYiagxS fM1oAsLklESEk1MG5+4++zjjc12DE+oMze4f7qtn+5CnJhsumPL9zW9ZbLEBXubzrF829hSH3 OJJnmB75JWf5qlxZ/ytuq7J79dpubWTLbzNNLphsYi084/EA+pK+vJ9U1av7liY+EtX5rfzHY tvmn0X65jK8N7/V28B/o4z4yY8vVlDkvNv+foGPUwBO39NT5SUosxRmJhlrMRcWJANnL0k2gA gAA X-Env-Sender: prvs=025853ab4=Andrew.Cooper3@citrix.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1470998122!42148004!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32997 invoked from network); 12 Aug 2016 10:35:23 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 12 Aug 2016 10:35:23 -0000 X-IronPort-AV: E=Sophos;i="5.28,510,1464652800"; d="scan'208";a="379698969" From: Andrew Cooper To: Xen-devel Date: Fri, 12 Aug 2016 11:35:19 +0100 Message-ID: <1470998119-14965-2-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1470998119-14965-1-git-send-email-andrew.cooper3@citrix.com> References: <1470998119-14965-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 2/2] x86/cpufreq: Avoid using processor_pminfo[cpu] when it is NULL X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The undefined behaviour sanitiser shows that it really is NULL via the pre_initcall path. (XEN) ================================================================================ (XEN) UBSAN: Undefined behaviour in cpufreq.c:158:66 (XEN) member access within null pointer of type 'struct processor_pminfo' (XEN) ----[ Xen-4.8-unstable x86_64 debug=y Not tainted ]---- (XEN) [] cpufreq_add_cpu+0x161/0xdc0 (XEN) [] cpufreq.c#cpu_callback+0x20/0x30 (XEN) [] cpufreq.c#cpufreq_presmp_init+0x2d/0x50 (XEN) [] do_presmp_initcalls+0x22/0x30 (XEN) [] __start_xen+0x378d/0x42f0 (XEN) [] __high_start+0x53/0x60 Fix two other occurances of the same buggy logic. The processor_pminfo[] objects are only allocated as a result of XENPF_set_processor_pminfo hypercalls, which means that this early cpu callback will always hit the early NULL check, and is therefore pointless. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich --- xen/drivers/cpufreq/cpufreq.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index f19b403..fd82ef5 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -126,7 +126,7 @@ int __init cpufreq_register_governor(struct cpufreq_governor *governor) int cpufreq_limit_change(unsigned int cpu) { - struct processor_performance *perf = &processor_pminfo[cpu]->perf; + struct processor_performance *perf; struct cpufreq_policy *data; struct cpufreq_policy policy; @@ -134,6 +134,8 @@ int cpufreq_limit_change(unsigned int cpu) !processor_pminfo[cpu]) return -ENODEV; + perf = &processor_pminfo[cpu]->perf; + if (perf->platform_limit >= perf->state_count) return -EINVAL; @@ -155,12 +157,15 @@ int cpufreq_add_cpu(unsigned int cpu) struct cpufreq_dom *cpufreq_dom = NULL; struct cpufreq_policy new_policy; struct cpufreq_policy *policy; - struct processor_performance *perf = &processor_pminfo[cpu]->perf; + struct processor_performance *perf; /* to protect the case when Px was not controlled by xen */ - if (!processor_pminfo[cpu] || - !(perf->init & XEN_PX_INIT) || - !cpu_online(cpu)) + if ( !processor_pminfo[cpu] || !cpu_online(cpu) ) + return -EINVAL; + + perf = &processor_pminfo[cpu]->perf; + + if ( !(perf->init & XEN_PX_INIT) ) return -EINVAL; if (!cpufreq_driver) @@ -310,12 +315,15 @@ int cpufreq_del_cpu(unsigned int cpu) struct list_head *pos; struct cpufreq_dom *cpufreq_dom = NULL; struct cpufreq_policy *policy; - struct processor_performance *perf = &processor_pminfo[cpu]->perf; + struct processor_performance *perf; /* to protect the case when Px was not controlled by xen */ - if (!processor_pminfo[cpu] || - !(perf->init & XEN_PX_INIT) || - !cpu_online(cpu)) + if ( !processor_pminfo[cpu] || !cpu_online(cpu) ) + return -EINVAL; + + perf = &processor_pminfo[cpu]->perf; + + if ( !(perf->init & XEN_PX_INIT) ) return -EINVAL; if (!per_cpu(cpufreq_cpu_policy, cpu)) @@ -637,8 +645,6 @@ static struct notifier_block cpu_nfb = { static int __init cpufreq_presmp_init(void) { - void *cpu = (void *)(long)smp_processor_id(); - cpu_callback(&cpu_nfb, CPU_ONLINE, cpu); register_cpu_notifier(&cpu_nfb); return 0; }