]> git.ipfire.org Git - thirdparty/systemd.git/commit
boot: Fix UKI boot for kernels with non-zero ImageBase
authorcdown <cdown@devvm38360.cln0.facebook.com>
Thu, 22 Jan 2026 12:16:49 +0000 (04:16 -0800)
committerChris Down <chris@chrisdown.name>
Thu, 22 Jan 2026 16:18:25 +0000 (00:18 +0800)
commitd9d300dc4c9318fa6df22772c8f5ac94b1dd30cc
tree8cf7794a82e5f4bdb82739ad29af0f59f28634a7
parentb61aeeb315c2c9216acb2d960cd944b6ab8ef398
boot: Fix UKI boot for kernels with non-zero ImageBase

The current code incorrectly subtracts ImageBase from section
VirtualAddress values when loading sections into memory. This is based
on a misunderstanding of the PE specification.

VirtualAddress in section headers is the address of the first byte of
the section relative to the image base when the section is loaded into
memory. In other words, VirtualAddress is already an RVA measured from
the image base, it is definitely NOT an absolute address that needs to
be adjusted.

So when loading a PE image into a newly allocated buffer, sections
should be copied to buffer + VirtualAddress, regardless of what
ImageBase says. The ImageBase field merely indicates the *preferred*
load address, it does not affect how section RVAs are interpreted.

This happens to not cause issues when ImageBase was 0 (since
VirtualAddress - 0 = VirtualAddress), which is why this bug went
undetected on modern kernels. However, it fails with kernels that have
non-zero ImageBase values.

So let's remove the nonsensical VirtualAddress < ImageBase check, and
remove the ImageBase subtractions from section loading offsets. This
lets all kernel UKIs work properly again.

Fixes: #40342
src/boot/linux.c