Skip to content

kernel: boot the vmlinux through PVH, randomizing itself (#645) - #664

Closed
aledbf wants to merge 8 commits into
mainfrom
kernel/645-kaslr-pvh
Closed

aledbf wants to merge 8 commits into
mainfrom
kernel/645-kaslr-pvh

Conversation

@aledbf

@aledbf aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member

Why

The goal is a cold boot to the first SSH login in under 100 ms (v20261123.06: 370 cold, 72.2 restored). A bzImage's decompressor spent ~21 ms (bench) on a copy, LZ4 and parse_elf before the kernel's clock, and it was the only thing that randomized the kernel. This boots the release's vmlinux through PVH instead, the kernel moving itself to a random base (#645).

What

  • Kernel 0014-0018: Hou Wenlong's RFC (2026-01-26), made checkpatch --strict clean with each change noted in its header. 0019 sets KASLR_FLAG once the kernel moved, so RANDOMIZE_MEMORY runs. 0020 reads RDRAND and TSC from the CPUID registers that hold them: the RFC reads them swapped, so its virtual base was drawn from the i8254 and boot_params alone. Config: PVH, RELOCATABLE_UNCOMPRESSED_KERNEL, a 1 MiB table.

  • QEMU 0008: a random physical base from XEN_ELFNOTE_PHYS32_RELOC. pvh.bin ships again.

  • machine: a release whose vmlinux carries both Xen notes boots it through PVH; one without (v20261119.02 to v20261123.06) boots its bzImage as before. The bzImage still ships (spin's hack/machine/place.go asks for it, After #645, the bzImage, KERNEL_LZ4 and QEMU 0007 serve only releases before it #660).

  • Checks: verify kernel asserts both notes and a filled .data.reloc (fixture: internal/elftest). The kernel build asserts each patch, prints the table's use, and refuses __fentry__, sanitizer, stack-protector or GOT references in the pre-relocation object. boot:kaslr (compat.yml) requires _text, the physical base, the direct map and vmalloc each to move across 10 boots, through real addresses.

  • The kernel build's gates (Carried patches: no static analysis, no fuzzing, and the patched packages' own tests are off #653, kernel: enforce checkpatch --strict and sparse on the patched files (#653) #656), changed for these patches: checkpatch leaves out FILE_PATH_CHANGES (the MAINTAINERS question for an added file) by name; sparse runs over a file a patch adds with every warning counted new, over the decompressor's misc.c with the sparse command the bzImage's build ran for it (a single-object target compiles it with vmlinux's flags and failed, job 137873298240), and not over arch/x86/tools, host programs C= never checks.

Measured

Bench, spin's shape and login, against v20261123.06, 60 a side, measured on the kernel before 0020. 0020 adds one RDRAND and one RDTSC to the boot and goes in as a security fix, not as a boot change:

Δp50 [95%] run
first login −16.8 [−20.9, −13.0] (368 → 352) lab 45219785493
sshd accepting −16.7 [−20.2, −12.7] lab 45219785493
restored, evicted −4.4 [−17.5, −2.0] lab 45219801969
restored, cached −4.3 [−14.0, +10.2], within noise lab 45219801969

State −31.9 MiB, QEMU's RSS −13.8 MiB. The bound (no KASLR) was −18.9 cold, −3.6 restored (labs 45213668842, 45213683698).

The three questions

  • The table's size. A 512 KiB reserve fails the link naming 0xc7000 (parts run 45222305257). At boot the table is part of the image and cannot overflow.
  • RANDOMIZE_MEMORY. Without 0019 vmalloc and the direct map stayed at ffffc90000000000 and ffff888000000000 in all 10 boots and boot:kaslr failed (lab 45225297602); with it, 10 distinct bases each (lab 45221660056).
  • Entropy. The RFC alone drew the virtual base without RDRAND or RDTSC (0020 fixes it); with 0019 and 0020 each base and region is drawn as the bzImage's are, the physical one from the host's getrandom. budget: the decompressor's copy, LZ4 and parse_elf, 21 ms (bench) before the kernel's clock #645 has the comparison.

The machine's record

compat.yml on this PR (boot:record, boot:compat) says whether the record moves, and this section is filled in from its run before merge.

🤖 Generated with Claude Code

aledbf and others added 8 commits November 23, 2026 14:46
Hou Wenlong's RFC (0014-0018, 2026-01-26, unchanged on 7.3.5) lets a
vmlinux entered through PVH randomize its own virtual base at
startup_64, from a relocation table the relocs tool writes into
.data.reloc. 0019 sets KASLR_FLAG when it did, so RANDOMIZE_MEMORY
moves the direct map, vmalloc and vmemmap. 0020 reads RDRAND and TSC
from the CPUID registers that hold them: the RFC reads them swapped,
and drew the virtual base from the i8254 and boot_params alone.

The build asserts each patch on the vmlinux, prints how much of the
table the kernel uses, and refuses instrumentation or GOT references
in the code that runs before the relocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0008 honours XEN_ELFNOTE_PHYS32_RELOC, which Linux emits under
CONFIG_PVH: the physical base a bzImage's decompressor chose before,
drawn from qemu_guest_getrandom. pvh.bin ships again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…self (#645)

A release whose vmlinux has both Xen notes boots it with pvh.bin; one
without (v20261119.02 to v20261123.06) boots its bzImage as before.
verify kernel asserts the notes and a filled .data.reloc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run on every change that reaches the machine (compat.yml). The regions
are read through real addresses, kptr_restrict at 1: at 0 %pK prints
a hash that differs every boot whatever the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#645)

checkpatch's MAINTAINERS question for an added file is left out by
name: no patch here goes upstream until it has run in production.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he decompressor (#645)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…em (#645)

The sparse step (#656) made each touched file a single-object target,
which compiles arch/x86/boot/compressed/misc.c with vmlinux's flags and
fails. Its sparse command is taken from the bzImage's build instead
and run on both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf

aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Replaced by #675: the same commits on a linear branch off main (this one carries a merge commit, and the repository merges by rebase with linear history), plus the fixes for the red Gate (mutate), Compat (sparse over misc.c) and CodeQL (the kernel's bzImage-only files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant