Re: [PATCH v2 6/8] x86/kaslr: Simplify process_gb_huge_pages

From: Kees Cook
Date: Tue Jul 28 2020 - 15:27:21 EST


On Mon, Jul 27, 2020 at 07:07:59PM -0400, Arvind Sankar wrote:
> Short-circuit the whole function on 32-bit.
>
> Replace the loop to determine the number of 1Gb pages with arithmetic.
>
> Fix one minor bug: if the end of the region is aligned on a 1Gb
> boundary, the current code will not use the last available 1Gb page due
> to an off-by-one error.
>
> Signed-off-by: Arvind Sankar <nivedita@xxxxxxxxxxxx>

Can you add some KUnit tests could be written to do validation of the
refactorings? Touching this code is so painful. :)

-Kees

> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -546,49 +546,43 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size)
> static void
> process_gb_huge_pages(struct mem_vector *region, unsigned long image_size)
> {
> - unsigned long addr, size = 0;
> + unsigned long pud_start, pud_end, gb_huge_pages;
> struct mem_vector tmp;
> - int i = 0;
>
> - if (!max_gb_huge_pages) {
> + if (IS_ENABLED(CONFIG_X86_32) || !max_gb_huge_pages) {
> store_slot_info(region, image_size);
> return;
> }

Won't max_gb_huge_pages always be false for 32-bit?

--
Kees Cook