Skip to content

Commit f49236a

Browse files
nivedita76ingomolnar
authored andcommitted
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
1 parent 0eb1a8a commit f49236a

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

arch/x86/boot/compressed/kaslr.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ static void process_e820_entries(unsigned long minimum,
803803
static unsigned long find_random_phys_addr(unsigned long minimum,
804804
unsigned long image_size)
805805
{
806+
u64 phys_addr;
807+
806808
/* Bail out early if it's impossible to succeed. */
807809
if (minimum + image_size > mem_limit)
808810
return 0;
@@ -816,7 +818,15 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
816818
if (!process_efi_entries(minimum, image_size))
817819
process_e820_entries(minimum, image_size);
818820

819-
return slots_fetch_random();
821+
phys_addr = slots_fetch_random();
822+
823+
/* Perform a final check to make sure the address is in range. */
824+
if (phys_addr < minimum || phys_addr + image_size > mem_limit) {
825+
warn("Invalid physical address chosen!\n");
826+
return 0;
827+
}
828+
829+
return (unsigned long)phys_addr;
820830
}
821831

822832
static unsigned long find_random_virt_addr(unsigned long minimum,

0 commit comments

Comments
 (0)