Received: by 10.213.65.68 with SMTP id h4csp358483imn; Tue, 13 Mar 2018 06:42:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELv4FLavluMT7iHJ758ixfd7INpwsCNdw/m0UzI7Fg8xqQKgW8A9iYRpNOF1/+imFBWqSLHV X-Received: by 2002:a17:902:9a4a:: with SMTP id x10-v6mr658639plv.256.1520948548099; Tue, 13 Mar 2018 06:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520948548; cv=none; d=google.com; s=arc-20160816; b=lwV3mAmIO9w6WNtyoX6wzl8W6s/3mXOUrxUCtTAZ869063O6/M4bKXyHND8VwYFMmd bv6Ta2Vrm92dtkcubujeoCCrG+I7LGx//xIlRY9JcfqnL6lxe7lzR/rp8NtUHdz1IkxK vLvWP1D9zpnaYFekQZursl8a1NHbfAM15OZLMh0z2eDNSzqlu0OGFeUveeYHVo4BQUvn sJC9Yji8cjTMXSPDi3f3cVlqYgPYKsusVyfKxAVkh8dIQGyvm6JsDOQuN2GPQ21yLoKQ b+VHCSDAv5Hf74rZcTWPCS4KksYOuMoSr4eGXnMDAJXy2UuSkkmykB0NUZrPeNbqqNer 28QQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=7Vyp/N4v+VSra54oOSuq51Uh9Wdue5emoJfzJdzB8rM=; b=ixMBGkCAxMIn6KXYJ2KgXXbvGv95cGBS2W1/1l+dMca8iOqzALaiWVUdr17ERUSz8W 4WmHVQbC1h5Ht7+mRkxEUe/u4Wd4A0jQQaxGQJQSWDgr+qL8lAPB+94lhjGmB7N2fR3r vNvLImKR2oPVCnIIeUSIVMqyyOZ4RIL6x0+2jbyZ9IamjkfjzXDVeFSCT0JSQv1AYqpB b3hKQFZ4TJjO1NEuExqHJUyzqkUET4YiPIvmEUs0otawegal1jqVRJBOoWY27ra/p85W AQKTWoCqMWDFZgsnTbd8jUYiLhyZaLkT2op82UHCC224Egny8R/Z2FeQbcfE8HVC7J2U YS5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Xx+0atty; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si110682pgp.89.2018.03.13.06.42.13; Tue, 13 Mar 2018 06:42:28 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b=Xx+0atty; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933020AbeCMNj7 (ORCPT + 99 others); Tue, 13 Mar 2018 09:39:59 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:13231 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752381AbeCMNjy (ORCPT ); Tue, 13 Mar 2018 09:39:54 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w2DDdaEk002151; Tue, 13 Mar 2018 08:39:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1520948376; bh=tH9Y6zNm5pUfgogq0pOALi82pa6qxPGodyHZ0YnrOds=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=Xx+0atty1OS+d/pmVMsAv7obbY0EYo4xERuWRMnm9D+yHlabqGQ7aiNAAYuzJRDZT xVIFU2K3DO3jpJ8++rJ0ZWH7rSVZN4YPxS3V9v/hE8KQj7HMG2588hp/u6QIpOqlD7 G8O2bi/PVPMS1qjVsQC0GItiuETzZ5yPL7F7PbXU= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2DDdaN6013137; Tue, 13 Mar 2018 08:39:36 -0500 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Tue, 13 Mar 2018 08:39:35 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Tue, 13 Mar 2018 08:39:35 -0500 Received: from [172.24.190.117] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2DDdXuf008716; Tue, 13 Mar 2018 08:39:34 -0500 Subject: Re: [3/3] irqchip/gic-v3: Bounds check redistributor accesses To: Punit Agrawal , CC: , , "Menon, Nishanth" References: <20171011094148.15674-4-punit.agrawal@arm.com> From: Lokesh Vutla Message-ID: <28f9c1cd-e1df-f4db-32b4-c9ca0f0f256a@ti.com> Date: Tue, 13 Mar 2018 19:08:46 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20171011094148.15674-4-punit.agrawal@arm.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi All, On Wednesday 11 October 2017 03:11 PM, Punit Agrawal wrote: > The kernel crashes while iterating over a redistributor that is > in-correctly sized by the platform firmware or doesn't contain the last > record. > > Prevent the crash by checking accesses against the size of the region > provided by the firmware. While we are at it, warn the user about > incorrect region size. > > Signed-off-by: Punit Agrawal > Cc: Marc Zyngier Sorry to bring up an old thread. Just wanted to check what is the status on this series. This will also be useful when we try to boot linux + hypervisor with less number of cores than the SoC supports. For example: - SoC has 4 cores and Linux tries to boot with 2 cores. - then a type-2 hypervisor gets installed. - Hypervisor tries to boot a VM with linux on core 1. Now the VM boot will fail while it iterates over all the GICR regions till GICR_TYPER is found. Hypervisor will trap any accesses to GICR regions of any invalid cpus(cpu 2, cpu 3 in this case). If the $patch is not the right approach, can you suggest on how to handle the above scenario? Thanks and regards, Lokesh > --- > drivers/irqchip/irq-gic-v3.c | 48 ++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 40 insertions(+), 8 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c > index 881d327c53fa..754d936c95e5 100644 > --- a/drivers/irqchip/irq-gic-v3.c > +++ b/drivers/irqchip/irq-gic-v3.c > @@ -429,11 +429,21 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *)) > int i; > > for (i = 0; i < gic_data.nr_redist_regions; i++) { > - void __iomem *ptr = gic_data.redist_regions[i].redist_base; > struct resource *res = &gic_data.redist_regions[i].res; > - u64 typer; > + void __iomem *ptr, *base; > + u64 typer, size, stride; > u32 reg; > > + ptr = base = gic_data.redist_regions[i].redist_base; > + size = resource_size(res); > + > + stride = gic_data.redist_stride ?: SZ_64K * 2; > + if (ptr + stride > base + size) { > + pr_warn("Insufficient size for redistributor region @%llx. Skipping\n", > + res->start); > + continue; > + } > + > reg = readl_relaxed(ptr + GICR_PIDR2) & GIC_PIDR2_ARCH_MASK; > if (reg != GIC_PIDR2_ARCH_GICv3 && > reg != GIC_PIDR2_ARCH_GICv4) { /* We're in trouble... */ > @@ -442,7 +452,28 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *)) > } > > do { > + /* > + * We can access GICR_TYPER as we have already > + * checked that we have atleast 128kB or > + * redist_stride > + */ > typer = gic_read_typer(ptr + GICR_TYPER); > + if (!gic_data.redist_stride && > + (typer & GICR_TYPER_VLPIS)) { > + /* VLPI_base + reserved page */ > + stride += SZ_64K * 2; > + > + /* > + * We are larger than we thought, do > + * we still fit? > + */ > + if (ptr + stride > base + size) { > + pr_warn("No last record found in redistributor region @%llx\n", > + gic_data.redist_regions[i].res.start); > + break; > + } > + } > + > ret = fn(gic_data.redist_regions + i, ptr); > if (!ret) > return 0; > @@ -450,12 +481,13 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *)) > if (gic_data.redist_regions[i].single_redist) > break; > > - if (gic_data.redist_stride) { > - ptr += gic_data.redist_stride; > - } else { > - ptr += SZ_64K * 2; /* Skip RD_base + SGI_base */ > - if (typer & GICR_TYPER_VLPIS) > - ptr += SZ_64K * 2; /* Skip VLPI_base + reserved page */ > + ptr += stride; > + > + stride = gic_data.redist_stride ?: SZ_64K * 2; > + if (ptr + stride > base + size) { > + pr_warn("No last record found in redistributor region @%llx\n", > + gic_data.redist_regions[i].res.start); > + break; > } > } while (!(typer & GICR_TYPER_LAST)); > } >