stub: allocate and zero enough space in legacy x86 handover protocol
authorLuca Boccassi <bluca@debian.org>
Wed, 31 Jul 2024 00:45:06 +0000 (01:45 +0100)
committerLuca Boccassi <bluca@debian.org>
Thu, 15 Aug 2024 13:04:40 +0000 (14:04 +0100)
commit84111f8916340e3e67d8166eb1d9938da94ce669
treed9e4524b7f03eed61ed5343d47b6f3422b9b4fab
parent0d98178abb5ea470d03d05680e58ff0e59fe69bd
stub: allocate and zero enough space in legacy x86 handover protocol

A PE image's memory footprint might be larger than its file size due
to uninitialized memory sections. Normally all PE headers should be
parsed to check the actual required size, but the legacy EFI handover
protocol is only used for x86 Linux bzImages, so we know only the last
section will require extra memory. Use SizeOfImage from the PE header
and if it is larger than the file size, allocate and zero extra memory
before using it.

Fixes https://github.com/systemd/systemd/issues/33816

(cherry picked from commit 19812661f1f65ebe777d1626b5abf6475faababc)
src/boot/efi/boot.c
src/boot/efi/linux.c
src/boot/efi/linux.h
src/boot/efi/linux_x86.c
src/boot/efi/pe.c
src/boot/efi/pe.h