Re: [PATCH 7/8] x86/kaslr: Clean up slot handling

From: Ingo Molnar
Date: Tue Jul 28 2020 - 06:59:33 EST



* Arvind Sankar <nivedita@xxxxxxxxxxxx> wrote:

> The number of slots and slot areas can be unsigned int, since on 64-bit,
> the maximum amount of memory is 2^52, the minimum alignment is 2^21, so
> the slot number cannot be greater than 2^31. The slot areas are limited
> by MAX_SLOT_AREA, currently 100. Replace the type used for slot number,
> which is currently a mix of int and unsigned long, with unsigned int
> consistently.
>
> Drop unnecessary check that number of slots is not zero in
> store_slot_info, it's guaranteed to be at least 1 by the calculation.
>
> 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.

Please split this up into a couple of easily bisectable patches as
well:

- first one harmonizes the integer types used

- patch that drops the unnecessary check

- patch that drops the unnecessary alignment operation

Thanks,

Ingo