linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: joelf@ti.com (Joel Fernandes)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: kernel: Detect DTB overwrite and error out
Date: Wed, 20 Nov 2013 22:04:04 -0600	[thread overview]
Message-ID: <1385006644-16024-1-git-send-email-joelf@ti.com> (raw)

Kernel can silenty fail for DT-boot after the decompression stage, if DTB is
overwritten. Instead of simply failing, we detect the condition and print an
error.

One may think that it is sufficient for the bootloader to place the DTB away
from kernel, but this is not the right fix because: (1) We add more dependence
to the bootloader's stupidity (2) the decompressed kernel end address is not
known to the loader. Also, we shouldn't depend on bootloader for silently
failing us, so we detect the condition and error out.

Signed-off-by: Joel Fernandes <joelf@ti.com>
---
 arch/arm/kernel/devtree.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index f35906b..96c6964 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -21,6 +21,7 @@
 
 #include <asm/cputype.h>
 #include <asm/setup.h>
+#include <asm/sections.h>
 #include <asm/page.h>
 #include <asm/smp_plat.h>
 #include <asm/mach/arch.h>
@@ -201,6 +202,13 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
 
 	devtree = phys_to_virt(dt_phys);
 
+	if ((char *)devtree <= _end) {
+		early_print("Error: Device tree overwritten by kernel image\n");
+		early_print("Please check your kernel config and/or bootloader\n");
+		while (true)
+			;
+	}
+
 	/* check device tree validity */
 	if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
 		return NULL;
-- 
1.8.1.2

             reply	other threads:[~2013-11-21  4:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-21  4:04 Joel Fernandes [this message]
2013-11-21 16:48 ` [PATCH] ARM: kernel: Detect DTB overwrite and error out Stephen Warren
2013-11-21 19:48   ` Joel Fernandes
2013-11-21 19:56     ` Stephen Warren

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=1385006644-16024-1-git-send-email-joelf@ti.com \
    --to=joelf@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).