Skip to content

Commit eb38be6

Browse files
nivedita76ingomolnar
authored andcommitted
x86/kaslr: Drop unnecessary alignment in find_random_virt_addr()
Drop unnecessary alignment of image_size to CONFIG_PHYSICAL_ALIGN in find_random_virt_addr, it cannot change the result: the largest valid slot is the largest n that satisfies minimum + n * CONFIG_PHYSICAL_ALIGN + image_size <= KERNEL_IMAGE_SIZE (since minimum is already aligned) and so n is equal to (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICAL_ALIGN even if image_size is not aligned to CONFIG_PHYSICAL_ALIGN. 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-17-nivedita@alum.mit.edu
1 parent 46a5b29 commit eb38be6

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

arch/x86/boot/compressed/kaslr.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,12 @@ static unsigned long find_random_virt_addr(unsigned long minimum,
825825
{
826826
unsigned long slots, random_addr;
827827

828-
/* Align image_size for easy slot calculations. */
829-
image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
830-
831828
/*
832829
* There are how many CONFIG_PHYSICAL_ALIGN-sized slots
833830
* that can hold image_size within the range of minimum to
834831
* KERNEL_IMAGE_SIZE?
835832
*/
836-
slots = (KERNEL_IMAGE_SIZE - minimum - image_size) /
837-
CONFIG_PHYSICAL_ALIGN + 1;
833+
slots = 1 + (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICAL_ALIGN;
838834

839835
random_addr = kaslr_get_random_long("Virtual") % slots;
840836

0 commit comments

Comments
 (0)