Skip to content

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

Merged
aledbf merged 11 commits into
mainfrom
kernel/645-kaslr-pvh-3
Nov 23, 2026
Merged

aledbf merged 11 commits into
mainfrom
kernel/645-kaslr-pvh-3

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.

  • CodeQL's kernel analysis (codeql: prove the patched files were read, trace the kernel and QEMU, analyse our Go and workflows (#653) #659): the RFC is the first series to touch arch/x86/boot/compressed and arch/x86/tools, which only the bzImage builds. As single objects misc.o found no ../voffset.h and relocs.o failed vmlinux's -Werror (job 137883774299). A new spin-machine-dev patched prepare configures the kernel and builds the bzImage before the tracer starts; patched compile then touches each patched file and remakes its object and the bzImage, so only those are extracted and the guard that every touched C file is extracted stands.

  • sparse over misc.c: grep took the bzImage's V=1 log for binary and printed nothing (compat job 137883284845); it reads it with -a.

  • mutate (CI run 45228954837): internal/elftest's p_align, section alignments and the string table's name are fields neither reader reads, each line exempt saying so; a note truncated by its segment is refused by a new test.

Replaces #664, whose branch carried a merge commit from main.

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

It does not move (compat run 45232827254). Checkpoints of v20261123.06, .05 and .04 resume on this machine and go on counting; v20261123.03 is refused as before, by cpu x-legacy-cpuid2-cache (#586). pvh.bin reaches the guest through fw_cfg at a boot, as linuxboot_dma.bin did, and is not in the record, and a resumed guest runs the kernel in its saved memory. boot:record passes, and boot:kaslr saw _text, the physical base, vmalloc and the direct map at a different place in each of 10 boots.

🤖 Generated with Claude Code

aledbf and others added 11 commits November 23, 2026 15:23
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>
…empt from mutate (#645)

mutate left four edits of internal/elftest's fixture standing (CI run 45228954837): p_align, the
sections' alignments and the string table's own name, none of which machine.hasXenNote or
build.SelfRandomizing reads. Each line says so. And three of the readers themselves: a note whose
descriptor the segment cuts short is now refused by a test (its redundant bound removed), a
one-word relocation table is filled, and a 12-byte header alone cannot name "Xen".

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

grep took the log for binary and printed no line, so the build said it ran no sparse over
arch/x86/boot/compressed/misc.c when it had (compat job 137883284845).

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

The RFC is the first series to touch arch/x86/boot/compressed and arch/x86/tools. Made as single
objects they took vmlinux's flags: misc.o found no ../voffset.h, which only a linked vmlinux
gives, and relocs.o failed vmlinux's -Werror (codeql.yml job 137883774299). `patched prepare`
now configures the kernel and, when a touched file is one only the bzImage builds, builds the
bzImage, before CodeQL's tracer starts, so the whole kernel is not extracted; `patched compile`
touches each file and makes the objects, then the bzImage, in two makes (in one, make built
arch/x86/pci/common.o twice at once). Locally: prepare 3m13s, compile 25s, misc.o, kaslr.o and
relocs among what it rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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