Skip to content

qemu: ask for the hardening instead of inheriting it - #270

Merged
aledbf merged 1 commit into
mainfrom
qemu-hardening-explicit
Nov 19, 2026
Merged

aledbf merged 1 commit into
mainfrom
qemu-hardening-explicit

Conversation

@aledbf

@aledbf aledbf commented Nov 19, 2026

Copy link
Copy Markdown
Member

Closes #264.

What

QEMU_FLAGS asks for the hardening the build used to inherit from meson's probes and Alpine's gcc:

  • --enable-pie, --enable-stack-protector: QEMU's own switches. A probe that fails is now a configure error instead of a binary without the property.
  • -fstack-clash-protection: new to QEMU's own code. gcc leaves it off, and the 502 probes in the old binary came from Alpine's static libraries; there are 542 now.
  • -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3: fortify-headers 3.0.1 (already in qemu/apk.lock). Level 2 was gcc's default. The -U keeps the redefinition warning out of meson's -Werror probes.
  • -Wl,-z,relro,-z,now,-z,noexecstack.
  • QEMU_CONFIG_REV 7 → 8, so cached build directories are configured again.

Answers to the issue's questions

  • FORTIFY 3, not 2. fortify-headers implements level 3 with __builtin_dynamic_object_size: 16 uses in string.h at level 3, none at level 2.
  • No -fcf-protection. A .o compiled with it carries IBT+SHSTK, but the static-pie linked against musl's libc.a does not, because musl is unmarked. Linux would enforce nothing, and every function would pay for an endbr64. The Dockerfile records this.
  • CFI with Clang+LTO: left for its own issue.

Asserted from the build

A stripped ELF cannot show stack-clash protection or FORTIFY, so the hardening step reads each build's compile_commands.json. Both flags are on all 2288 compile commands of the KVM build and all 2814 of the TCG build. The same step checks that string.h with FORTIFY=3 really selects fortify-headers' checks. The four ELF checks from before stay.

Measured (laptop, not the goal's host)

before (published 11.1.3) after
qemu-system-x86_64 9 297 056 B 9 297 120 B
stack-clash probes 502 542
canary reads 7111 7117
start → QMP quit, p50 / p95, 60 runs interleaved 38.7 / 48.1 ms 38.1 / 47.0 ms

These pass with this QEMU: boot:firmware, boot:logind, boot:roms and boot:compat (a checkpoint of v20261114.02 resumes). boot:hotadd fails the same way with the old QEMU: the local image predates 9cb49ae.

To come: boot:ssh-first interleaved against the release on the bench fleet, via lab.yml, with this PR's QEMU run. The result goes here and in docs/log.md.

🤖 Generated with Claude Code

QEMU_FLAGS now names what the build was given by meson's probes and
Alpine's gcc: --enable-pie and --enable-stack-protector turn a failed
probe into a configure error, and -z relro,now,noexecstack go to the
linker. Two properties are new to QEMU's own code: stack-clash
protection (gcc leaves it off; 502 -> 542 probes in qemu-system-x86_64)
and _FORTIFY_SOURCE=3 through fortify-headers. -fcf-protection is left
out: musl's libc.a carries no IBT/SHSTK marking, so the static-pie
loses the property at link time.

What a stripped ELF cannot show is asserted from the build: every
compile command carries both flags (2288 kvm, 2814 tcg), and string.h
with FORTIFY=3 sizes buffers with __builtin_dynamic_object_size.

Size: qemu-system-x86_64 9297056 -> 9297120 bytes. Process start to a
QMP quit, 60 runs each interleaved on a laptop: 38.7 -> 38.1 ms p50,
noise. boot:firmware, boot:logind, boot:roms and boot:compat pass.

kernel/README.md: where the bpf-restrict-fs line's fix lives (#261).

Refs #264, #261

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit 4c20b14 into main Nov 19, 2026
5 checks passed
@aledbf
aledbf deleted the qemu-hardening-explicit branch November 19, 2026 13:11
@aledbf

aledbf commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Bench fleet, lab run 44531049945, boot:firmware-stages, v20261114.02 against it with this PR's QEMU (run 44527678617) beside it, 20 traced boots of each, p50 ms:

step release this PR
QEMU start 32.04 32.05
PCI walk 5.13 5.28
fw_cfg directory 1.68 1.69
kernel and init 112.51 112.81

No step moves beyond noise: the hardening costs QEMU's start nothing that can be measured. boot:ssh-first takes no QEMU B, so that probe is what the lab compares a QEMU with.

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.

QEMU build: ask for its hardening explicitly instead of inheriting it

1 participant