From patchwork Wed Jan 24 09:23:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandrasekhar L X-Patchwork-Id: 10181959 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 46A38601D5 for ; Wed, 24 Jan 2018 09:24:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 364EA286E1 for ; Wed, 24 Jan 2018 09:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AD6428765; Wed, 24 Jan 2018 09:24:26 +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 9D141286E1 for ; Wed, 24 Jan 2018 09:24:25 +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=HSko6BW8MkMlckZEG20OFZ8Uy3SjZLB/WWil7QgyIcU=; b=hcM QS12Jw/VCtiMgJt4kvRi1d2DGbIi8061z4V3WJRcowaDxA46j3/up2h1Ws3WS0/QFeCrcyRn3snIY 6LNJMi0g+QoMaG7nWXuiWnNG3u1xHAlp5pqtUp3RwQKs+pcqQhUbDSE5AHidyM4OUG6/z8OZwTS9N zMzBjWi3nhDNKqK1WBemqxs8eC9Khg17d6+gocptlDx9V05WV5kvbbcMJnFp2I1YWd+piU06ZCLEq iiiLqfMi7CA0ngxdGSCjfahcLKQEUbKWHjzm6oQYuXdvz2t/NgR/b2ZBD+pmWb1jWwruPuFwBcHeh pKTYD7yvCBUvfN/SmfzpB26GTMr1uZA==; 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 1eeHI7-0000CC-Jf; Wed, 24 Jan 2018 09:24:23 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eeHI5-0000AY-2J for linux-arm-kernel@lists.infradead.org; Wed, 24 Jan 2018 09:24:22 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A671B6028B; Wed, 24 Jan 2018 09:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516785849; bh=FFoajRKx9st8yNvUNaqIQ0ToGtgnX0mrcJM06hGgMJw=; h=From:To:Cc:Subject:Date:From; b=Tmem583JEVz9tAiCzorlxjsOr/Wm6OrWFJu/gMiEh8mZtii9lbGKKgs5xl3ze/ovN ARvVDE7Il37z1BzUoWL9B1DzK2oFjL6AwGQNxM8IE0haRoVYgCWENEUWLrof2KF0/o ltEzXp2CKq2s9k7C7m3nTtJJcSnKag6oooP9zWUY= 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 F04616028B; Wed, 24 Jan 2018 09:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516785849; bh=FFoajRKx9st8yNvUNaqIQ0ToGtgnX0mrcJM06hGgMJw=; h=From:To:Cc:Subject:Date:From; b=Tmem583JEVz9tAiCzorlxjsOr/Wm6OrWFJu/gMiEh8mZtii9lbGKKgs5xl3ze/ovN ARvVDE7Il37z1BzUoWL9B1DzK2oFjL6AwGQNxM8IE0haRoVYgCWENEUWLrof2KF0/o ltEzXp2CKq2s9k7C7m3nTtJJcSnKag6oooP9zWUY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F04616028B 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: ard.biesheuvel@linaro.org, mark.rutland@arm.com, will.deacon@arm.com Subject: [PATCH v1] arm64: setup: Check for overlapping dtb and Image load addresses Date: Wed, 24 Jan 2018 14:53:45 +0530 Message-Id: <20180124092345.5072-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: Lingutla Chandrasekhar , linux-arm-msm@vger.kernel.org, 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 --- Changes since v0: - Print overlap bytes. - Simplify ovelap checks. diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 30ad2f085d1f..fd9be0ad4a78 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -181,14 +181,21 @@ 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)) { - pr_crit("\n" - "Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n" + if (!dt_virt || (end_phys > dt_phys && + (dt_phys + fdt_totalsize(dt_virt)) > start_phys) || + !early_init_dt_scan(dt_virt)) { + pr_crit("Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n" "The dtb must be 8-byte aligned and must not exceed 2 MB in size\n" + "The dtb load address overllaped %lld bytes with kernel image\n" "\nPlease check your bootloader.", - &dt_phys, dt_virt); + &dt_phys, dt_virt, + (dt_phys < start_phys) ? + (dt_phys + fdt_totalsize(dt_virt) - start_phys) : + (end_phys - dt_phys)); while (true) cpu_relax();