summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArvind Sankar <nivedita@alum.mit.edu>2020-07-28 18:57:22 -0400
committerIngo Molnar <mingo@kernel.org>2020-07-31 11:08:17 +0200
commitf49236ae424d499d02ee3ce35fb9130ddf95b03f (patch)
treeb29fb9cddefee778da2e4494edf3d846e89e775a
parent0eb1a8af01d6264cf948d67c8bff15e2eb859355 (diff)
x86/kaslr: Add a check that the random address is in range
Check in find_random_phys_addr() that the chosen address is inside the range that was required. Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20200728225722.67457-22-nivedita@alum.mit.edu
-rw-r--r--arch/x86/boot/compressed/kaslr.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 80cdd2071305..735fcb2a8b7b 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -803,6 +803,8 @@ static void process_e820_entries(unsigned long minimum,
static unsigned long find_random_phys_addr(unsigned long minimum,
unsigned long image_size)
{
+ u64 phys_addr;
+
/* Bail out early if it's impossible to succeed. */
if (minimum + image_size > mem_limit)
return 0;
@@ -816,7 +818,15 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
if (!process_efi_entries(minimum, image_size))
process_e820_entries(minimum, image_size);
- return slots_fetch_random();
+ phys_addr = slots_fetch_random();
+
+ /* Perform a final check to make sure the address is in range. */
+ if (phys_addr < minimum || phys_addr + image_size > mem_limit) {
+ warn("Invalid physical address chosen!\n");
+ return 0;
+ }
+
+ return (unsigned long)phys_addr;
}
static unsigned long find_random_virt_addr(unsigned long minimum,