From patchwork Fri Jan 19 06:56:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandrasekhar L X-Patchwork-Id: 10174667 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 7BAB360392 for ; Fri, 19 Jan 2018 06:57:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B053285B5 for ; Fri, 19 Jan 2018 06:57:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F928285D1; Fri, 19 Jan 2018 06:57:24 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E0F94285B5 for ; Fri, 19 Jan 2018 06:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=hW240jIAsBywY01+UH3cOlOU85JyW3tub4eU57YLxCc=; b=uGE PCov9jZ2w8dQQ3WqrHyGr7k7GNLHMRapYsN2cEZUR42gKOuTvzvF+wvty5WVNCW/+bUZPMJCTtFmf RKC0RrIQw2Mg0WfABufffhxfu+kqG+O99QCoyan8cWNwH+y2n1oWvpAuobA7ruPHmSQRj262B+4VY NWfwNuMK+cpajbGrMSgX1UTZD28w+AF1yLec9+hi3SqmtlpD7V3KI786/Xx9kdoTVV36kZJMn2974 epq17M8O7nT1wNC2ehjZ0nJOkegqOuDvoCmbdaXpwKM8kQRCsnFY/N2ERl65KukAQTW9EHQEWigeU FzVGfa58erIFfT9eiNond3oSVm885hw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ecQc4-0005NW-AT; Fri, 19 Jan 2018 06:57:20 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ecQc1-0005M8-1p for linux-arm-kernel@lists.infradead.org; Fri, 19 Jan 2018 06:57:18 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A6C68609FD; Fri, 19 Jan 2018 06:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516345024; bh=Nzcf2166iBMEri9sNHV7AL52rtPZag2VA6efEdHqPjg=; h=From:To:Cc:Subject:Date:From; b=KdvxNyP0yQyWAFrBhOKRdYpTRedK/LavQvYX7saVtcVIaqLiT3NwllOxZVhvpUD6U ZVHztd6XvWjqWEStNHRfLvkn/lgtwnacz91n0yvDY/VJjG787W+Iu2JEtjazoOvtHA feMH5dD9jdhw4Owm6P+EkA6pzwNith08AY6KmLvA= Received: from lingutla-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: clingutla@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E2EE76050D; Fri, 19 Jan 2018 06:57:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516345024; bh=Nzcf2166iBMEri9sNHV7AL52rtPZag2VA6efEdHqPjg=; h=From:To:Cc:Subject:Date:From; b=KdvxNyP0yQyWAFrBhOKRdYpTRedK/LavQvYX7saVtcVIaqLiT3NwllOxZVhvpUD6U ZVHztd6XvWjqWEStNHRfLvkn/lgtwnacz91n0yvDY/VJjG787W+Iu2JEtjazoOvtHA feMH5dD9jdhw4Owm6P+EkA6pzwNith08AY6KmLvA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E2EE76050D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=clingutla@codeaurora.org From: Lingutla Chandrasekhar To: mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH] arm64: setup: Check for overlapping dtb and Image load addresses Date: Fri, 19 Jan 2018 12:26:37 +0530 Message-Id: <20180119065637.12789-1-clingutla@codeaurora.org> X-Mailer: git-send-email 2.14.1 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gkohli@codeaurora.org, linux-arm-msm@vger.kernel.org, Lingutla Chandrasekhar , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Sometime kernel image and dtb load offsets can overlap due to dynamically increased Image or dtb size if both load addresses are near to each other, which leads to bootup failures. So validate dtb load address and kernel image, if they overlap do not proceed to boot. Signed-off-by: Lingutla Chandrasekhar diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 30ad2f085d1f..c9dd699f09ab 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -181,11 +181,17 @@ static void __init smp_build_mpidr_hash(void) static void __init setup_machine_fdt(phys_addr_t dt_phys) { void *dt_virt = fixmap_remap_fdt(dt_phys); + u64 end_phys = __pa_symbol(_end); + u64 start_phys = __pa_symbol(_text); const char *name; - if (!dt_virt || !early_init_dt_scan(dt_virt)) { + if (!dt_virt || ((dt_phys < start_phys) && + ((dt_phys + fdt_totalsize(dt_virt)) > start_phys)) || + ((dt_phys > start_phys) && (dt_phys < end_phys)) || + !early_init_dt_scan(dt_virt)) { pr_crit("\n" "Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n" + "The dtb load address should not overlap with kernel image\n" "The dtb must be 8-byte aligned and must not exceed 2 MB in size\n" "\nPlease check your bootloader.", &dt_phys, dt_virt);