]> git.ipfire.org Git - thirdparty/systemd.git/commit
boot: Fix UKI boot for kernels with non-zero ImageBase (#40429)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 17 Feb 2026 18:27:41 +0000 (03:27 +0900)
committerGitHub <noreply@github.com>
Tue, 17 Feb 2026 18:27:41 +0000 (03:27 +0900)
commit78a61335e3e1a3b1dc24b2b1641ba3f76b75b5fd
treef9ee41856c6005a18ced6b93e63eaef8ab578b8f
parente38fac0cc520fe1487dd2b1d6111a9d3b3183ffc
parent353701b07e6750282461d6d61a3d8bffffe3ebbc
boot: Fix UKI boot for kernels with non-zero ImageBase (#40429)

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/boot.c