From: Lingutla Chandrasekhar <clingutla@codeaurora.org>
To: ard.biesheuvel@linaro.org, mark.rutland@arm.com, will.deacon@arm.com
Cc: Lingutla Chandrasekhar <clingutla@codeaurora.org>,
linux-arm-msm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1] arm64: setup: Check for overlapping dtb and Image load addresses
Date: Wed, 24 Jan 2018 14:53:45 +0530 [thread overview]
Message-ID: <20180124092345.5072-1-clingutla@codeaurora.org> (raw)
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 <clingutla@codeaurora.org>
---
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();
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.
WARNING: multiple messages have this Message-ID (diff)
From: clingutla@codeaurora.org (Lingutla Chandrasekhar)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1] arm64: setup: Check for overlapping dtb and Image load addresses
Date: Wed, 24 Jan 2018 14:53:45 +0530 [thread overview]
Message-ID: <20180124092345.5072-1-clingutla@codeaurora.org> (raw)
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 <clingutla@codeaurora.org>
---
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();
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.
next reply other threads:[~2018-01-24 9:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 9:23 Lingutla Chandrasekhar [this message]
2018-01-24 9:23 ` [PATCH v1] arm64: setup: Check for overlapping dtb and Image load addresses Lingutla Chandrasekhar
2018-01-29 15:48 ` Will Deacon
2018-01-29 15:48 ` Will Deacon
2018-02-05 8:06 ` Chandra Sekhar Lingutla
2018-02-05 8:06 ` Chandra Sekhar Lingutla
2018-02-05 11:13 ` Mark Rutland
2018-02-05 11:13 ` Mark Rutland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180124092345.5072-1-clingutla@codeaurora.org \
--to=clingutla@codeaurora.org \
--cc=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.