mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <shc_work@mail.ru>
To: barebox@lists.infradead.org
Subject: [PATCH] ARM: bootm: Add lower bound check of kernel in SDRAM
Date: Tue, 27 Oct 2020 09:17:54 +0300	[thread overview]
Message-ID: <20201027061754.29111-1-shc_work@mail.ru> (raw)

In get_kernel_addresses(), we add the lower bound check of kernel position.
Kernel address cannot be lower than SDRAM start.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 arch/arm/lib32/bootm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index ad807fb1d..28a645a9d 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -114,10 +114,11 @@ static int get_kernel_addresses(size_t image_size,
 		kaddr = mem_start + image_decomp_size;
 
 		/*
-		 * Make sure we do not place the image past the end of the
+		 * Make sure we do not place the image outside of the
 		 * available memory.
 		 */
-		if (kaddr + image_size + spacing >= mem_end)
+		if (((kaddr + image_size + spacing) > mem_end) &&
+		    ((mem_end - image_size - spacing) >= mem_start))
 			kaddr = mem_end - image_size - spacing;
 
 		*load_address = PAGE_ALIGN_DOWN(kaddr);
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2020-10-27  6:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27  6:17 Alexander Shiyan [this message]
2020-10-28  8:24 ` Sascha Hauer

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=20201027061754.29111-1-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --cc=barebox@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