From patchwork Thu Feb 25 14:49:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 8423821 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A04CC0554 for ; Thu, 25 Feb 2016 14:51:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC8EC20268 for ; Thu, 25 Feb 2016 14:51:50 +0000 (UTC) Received: from lists.xen.org (unknown [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9CA6202B8 for ; Thu, 25 Feb 2016 14:51:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aYxEH-000873-N6; Thu, 25 Feb 2016 14:49:21 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aYxEF-000849-LV for xen-devel@lists.xen.org; Thu, 25 Feb 2016 14:49:19 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 41/D7-03814-F641FC65; Thu, 25 Feb 2016 14:49:19 +0000 X-Env-Sender: prvs=856900a8f=George.Dunlap@citrix.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1456411755!25026850!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31523 invoked from network); 25 Feb 2016 14:49:18 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 25 Feb 2016 14:49:18 -0000 X-IronPort-AV: E=Sophos;i="5.22,498,1449532800"; d="scan'208";a="334488878" From: George Dunlap To: Date: Thu, 25 Feb 2016 14:49:01 +0000 Message-ID: <1456411743-17741-7-git-send-email-george.dunlap@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456411743-17741-1-git-send-email-george.dunlap@eu.citrix.com> References: <1456411743-17741-1-git-send-email-george.dunlap@eu.citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: George Dunlap , Ian Jackson , Wei Liu , George Dunlap Subject: [Xen-devel] [PATCH 6/8] tools/xenalyze: Fix off-by-one in MAX_CPUS range checks 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-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Skip action / throw error if cpu/vcpu >= MAX_CPUS rather than >. Also add an assertion to vcpu_find, to make future errors of this kind not out-of-bounds. CID 1306871 CID 1306870 CID 1306869 CID 1306867 Signed-off-by: George Dunlap Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu --- tools/xentrace/xenalyze.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/xentrace/xenalyze.c b/tools/xentrace/xenalyze.c index 249bebd..3e26a4c 100644 --- a/tools/xentrace/xenalyze.c +++ b/tools/xentrace/xenalyze.c @@ -6860,6 +6860,13 @@ struct vcpu_data * vcpu_find(int did, int vid) struct domain_data *d; struct vcpu_data *v; + /* "Graceful" handling of vid >= MAX_CPUS should be handled elsewhere */ + if ( vid >= MAX_CPUS ) { + fprintf(stderr, "%s: vcpu %d exceeds MAX_CPUS %d!\n", + __func__, vid, MAX_CPUS); + error(ERR_ASSERT, NULL); + } + d = domain_find(did); v = d->vcpu[vid]; @@ -7131,7 +7138,7 @@ void sched_runstate_process(struct pcpu_info *p) } } - if(r->vcpu > MAX_CPUS) + if(r->vcpu >= MAX_CPUS) { fprintf(warn, "%s: vcpu %u > MAX_VCPUS %d!\n", __func__, r->vcpu, MAX_CPUS); @@ -7441,14 +7448,14 @@ void sched_switch_process(struct pcpu_info *p) r->prev_dom, r->prev_vcpu, r->next_dom, r->next_vcpu); - if(r->prev_vcpu > MAX_CPUS) + if(r->prev_vcpu >= MAX_CPUS) { fprintf(warn, "%s: prev_vcpu %u > MAX_VCPUS %d!\n", __func__, r->prev_vcpu, MAX_CPUS); return; } - if(r->next_vcpu > MAX_CPUS) + if(r->next_vcpu >= MAX_CPUS) { fprintf(warn, "%s: next_vcpu %u > MAX_VCPUS %d!\n", __func__, r->next_vcpu, MAX_CPUS); @@ -8518,7 +8525,7 @@ off_t scan_for_new_pcpu(off_t offset) { cd = (typeof(cd))rec.u.notsc.data; - if ( cd->cpu > MAX_CPUS ) + if ( cd->cpu >= MAX_CPUS ) { fprintf(stderr, "%s: cpu %d exceeds MAX_CPU %d!\n", __func__, cd->cpu, MAX_CPUS); @@ -8738,7 +8745,7 @@ void process_cpu_change(struct pcpu_info *p) { (unsigned long long)p->file_offset); } - if(r->cpu > MAX_CPUS) + if(r->cpu >= MAX_CPUS) { fprintf(stderr, "FATAL: cpu %d > MAX_CPUS %d.\n", r->cpu, MAX_CPUS);