]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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)
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
1  2 
src/boot/boot.c

diff --cc src/boot/boot.c
Simple merge