Re: [PATCH 1/2] x86/boot/compressed/64: Remove .bss/.pgtable from bzImage

From: Kees Cook
Date: Thu Feb 06 2020 - 06:18:43 EST


On Thu, Jan 09, 2020 at 10:02:17AM -0500, Arvind Sankar wrote:
> Commit 5b11f1cee579 ("x86, boot: straighten out ranges to copy/zero in
> compressed/head*.S") introduced a separate .pgtable section, splitting
> it out from the rest of .bss. This section was added without the
> writeable flag, marking it as read-only. This results in the linker
> putting the .rela.dyn section (containing bogus dynamic relocations from
> head_64.o) after the .bss and .pgtable sections.

Thank you! As you know from the fg-kaslr thread[1], I ran into this (10
year old!) bug while helping there. I could not figure out why .bss was
getting allocated into the on-disk image.

> When we use objcopy to convert compressed/vmlinux into a binary for the
> bzImage, the .bss and .pgtable sections get materialized as ~176KiB of
> zero bytes in the binary in order to place .rela.dyn at the correct
> location.
>
> Fix this by marking .pgtable as writeable. This moves the .rela.dyn
> section earlier so that .bss and .pgtable are the last allocated
> sections and so don't appear in bzImage.
>
> Signed-off-by: Arvind Sankar <nivedita@xxxxxxxxxxxx>

Acked-by: Kees Cook <keescook@xxxxxxxxxxxx>

-Kees

[1] 202002060251.681292DE63@keescook/">https://lore.kernel.org/lkml/202002060251.681292DE63@keescook/

--
Kees Cook