virtio-linux: pin KBUILD_BUILD_* for reproducible kernel image#261
Conversation
The kernel bakes build time/user/host into the image via scripts/mkcompile_h (surfaced in /proc/version), so vmlinuz differed byte-for-byte across otherwise-identical rebuilds. Pin all three (timestamp from SOURCE_DATE_EPOCH) so the image is deterministic. Verified reproducible on aarch64: two from-scratch forced rebuilds produced byte-identical output (repro-check diff, 3/3 files identical). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesKernel Build Reproducibility
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/virtio-linux/build.sh`:
- Around line 10-12: The KBUILD_BUILD_TIMESTAMP export depends on ambient
SOURCE_DATE_EPOCH environment variable which breaks byte-for-byte
reproducibility across different build environments. Fix this by changing
KBUILD_BUILD_TIMESTAMP to use a fixed value `@0` instead of the conditional
@${SOURCE_DATE_EPOCH:-0} expression. Additionally, add the missing environment
variable exports for SOURCE_DATE_EPOCH=0 and PYTHONHASHSEED=0 to ensure
deterministic Python-based build steps and embedded timestamps, ensuring all
reproducibility variables are pinned to fixed values within the script itself.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: adccf3f1-1036-4ce4-a0e3-9d1638c68bcf
📒 Files selected for processing (1)
packages/virtio-linux/build.sh
| export KBUILD_BUILD_TIMESTAMP="@${SOURCE_DATE_EPOCH:-0}" | ||
| export KBUILD_BUILD_USER=builder | ||
| export KBUILD_BUILD_HOST=minimal |
There was a problem hiding this comment.
Pin kernel reproducibility vars to fixed values inside the script.
KBUILD_BUILD_TIMESTAMP currently depends on ambient SOURCE_DATE_EPOCH (Line 10), which can vary per build environment and break byte-for-byte reproducibility. Also, the deterministic timestamp/Python env exports are missing.
Suggested patch
export KBUILD_BUILD_TIMESTAMP="@${SOURCE_DATE_EPOCH:-0}"
export KBUILD_BUILD_USER=builder
export KBUILD_BUILD_HOST=minimal
+export SOURCE_DATE_EPOCH=0
+export PYTHONHASHSEED=0
+export KBUILD_BUILD_TIMESTAMP=`@0`As per coding guidelines: “For Linux kernel builds, export KBUILD_BUILD_TIMESTAMP=@0 KBUILD_BUILD_USER=builder KBUILD_BUILD_HOST=minimal” and “For embedded timestamps and Python-based build steps, export SOURCE_DATE_EPOCH=0 and PYTHONHASHSEED=0.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/virtio-linux/build.sh` around lines 10 - 12, The
KBUILD_BUILD_TIMESTAMP export depends on ambient SOURCE_DATE_EPOCH environment
variable which breaks byte-for-byte reproducibility across different build
environments. Fix this by changing KBUILD_BUILD_TIMESTAMP to use a fixed value
`@0` instead of the conditional @${SOURCE_DATE_EPOCH:-0} expression. Additionally,
add the missing environment variable exports for SOURCE_DATE_EPOCH=0 and
PYTHONHASHSEED=0 to ensure deterministic Python-based build steps and embedded
timestamps, ensuring all reproducibility variables are pinned to fixed values
within the script itself.
Source: Coding guidelines
What
Pins the kernel's embedded build metadata so the
virtio-linuximage is reproducible.Why
The Linux kernel bakes build time, user, and host into the image (via
scripts/mkcompile_h, surfaced in/proc/version), sovmlinuzdiffered byte-for-byte across otherwise-identical rebuilds. Setting the standardKBUILD_BUILD_*variables makes those fields deterministic (timestamp derived fromSOURCE_DATE_EPOCH, defaulting to epoch 0).Verification
Verified with a build-twice-and-diff on aarch64: two from-scratch forced rebuilds (
--rebuild --no-fetch) produced byte-identical output (3/3 files identical). Before this change the image diverged on the embedded timestamp/user/host.🤖 Generated with Claude Code
Summary by CodeRabbit