eBPF-based security platform
ci: Clean up the obsolete in-tree kernel builder
Michi Mutsuzakib3d2cfb1d903
diff --git a/.agents/skills/security-audit/SKILL.md b/.agents/skills/security-audit/SKILL.mdindex 0de3dc1e..5a1f51d4 100644--- a/.agents/skills/security-audit/SKILL.md+++ b/.agents/skills/security-audit/SKILL.md@@ -103,8 +103,8 @@ of `bpf/` the list of who writes and reads it, set against its flags.Hunt each class in both halves, the BPF programs and the userspace C,and with the kernel source open: a checkout of the kernel the test VM-boots, which `testing/vm/build-kernel.sh` builds, with the patches of-`kernel/` applied. Neither half can be judged without it. For a hook,+boots, which the `shirudo-dev/kernel` project builds with its patch+set. Neither half can be judged without it. For a hook,read the callers of `security_<hook>()`, what each does with the returnvalue and what it holds while it calls; for a helper or kfunc, what itreturns, when it fails and whether it sleeps; for a system call, adiff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.mdindex dfe468af..8f188e92 100644--- a/.agents/skills/testing/SKILL.md+++ b/.agents/skills/testing/SKILL.md@@ -94,12 +94,11 @@ parser of input from outside the host gets a target in `testing/fuzz/`.## Before a VM goal-- `vm`, `test-vm-bundle` and every family with target tests build the- kernel first when `testing/vm/build-kernel.sh` or a kernel patch is- newer than the artifact's `bzImage.sha256sum`. The build deletes the- artifact directory, needs gigabytes of disk and takes long, and a- checkout or rebase that touches the script triggers it. Compare the- times before starting and tell the user when a rebuild is due.+- `vm`, `test-vm-bundle` and every family with target tests require the+ kernel artifact from `shirudo-dev/kernel` under+ `artifacts/bpf-next-kernel-debs/`. The CI workflow pins a kernel run+ and its setup script stages that artifact. Local runs need the same+ artifact; they do not build a kernel from this checkout.- The bundle builds in the build container (`testing/container/`) froma copy of the files git sees in the checkout, tracked and untracked butnot ignored, so uncommitted changes are tested; edit nothing until the@@ -156,15 +155,10 @@ systemd-run --user --pipe --same-dir --wait --collect \## Kernel-The optional argument is passed as `KERNEL=`. Leave it out for-`bpf-next`, the kernel the test suite runs. A release such as `7.4`-boots that tag instead. `testing/Makefile` refuses one older than-`VM_KERNEL_MIN`. Either kernel is built on first use, which takes a-while; say so before starting. A build that fails because the host's-kernel BTF lacks the signed-loader ABI needs the kernel, not a VM: after-`make -C testing kernel` the build reads-`artifacts/bpf-next-kernel-debs/vmlinux.btf` in place of-`/sys/kernel/btf/vmlinux` (`Makefile.shirudo`).+The optional argument is passed as `KERNEL=` to select an already staged+artifact. Leave it out for `bpf-next`, the kernel the test suite runs.+The BPF build reads `artifacts/bpf-next-kernel-debs/vmlinux.btf` in+place of `/sys/kernel/btf/vmlinux` (`Makefile.shirudo`).## Reuse a running VM@@ -184,8 +178,7 @@ hold:1. It runs. `qemu.pid` holds a live PID, and `/proc/<pid>/cmdline`names the state directory.2. It booted the requested kernel. The `-kernel` path in that command- line lies in `artifacts/bpf-next-kernel-debs/` for bpf-next, or in- `artifacts/linux-v<version>-kernel-debs/` for a release.+ line lies in the selected staged kernel artifact directory.3. It runs the current build. The command line names the bundle itbooted, `shirudo-bundle,path=<bundle>`. The VM is stale when`<bundle>/.stamp` is newer than `created-at` (nanoseconds since thediff --git a/.github/scripts/tests.sh b/.github/scripts/tests.shindex dabeda52..d2874d6d 100755--- a/.github/scripts/tests.sh+++ b/.github/scripts/tests.sh@@ -4,13 +4,14 @@## .github/scripts/tests.sh -- run every test as make tests does on a# developer's host. setup makes the runner the VM host: KVM, the VM's-# packages, a compatible LVH kernel or the shirudo test kernel cache, and+# packages, the kernel CI artifact, and# the OpenSSL 3.5 toolchain from vm-toolchain.sh. run builds and runs the# unit, ci-checks, functional and end2end tests, each family of target tests# in a VM of its own, or one part of them: unit runs the unit and# ci-checks tests, functional and end2end the tier of that name.# With VM=0, setup installs only host test dependencies using the kernel-# CI artifact's BTF, and run leaves out target VMs.+# CI artifact's BTF, and run leaves out target VMs. CI supplies this artifact+# from github.com/shirudo-dev/kernel.## .github/scripts/tests.sh setup|run [unit|functional|end2end]#@@ -44,7 +45,7 @@ restore_workspace_ownership() {sudo chown -R "$(id -u):$(id -g)" .}-# The LVH build and production run leave root's files behind.+# Setup and production runs leave root's files behind.finish() {status=$?restore_workspace_ownership || status=$?@@ -52,18 +53,8 @@ finish() {exit "$status"}-require_kernel_config() {- config="$1"- setting="$2"- if ! grep -qx "$setting" "$config"; then- printf 'LVH kernel config lacks %s\n' "$setting" >&2- return 1- fi-}--# The programs of bpf/ attach to LSM hooks that carried patches of kernel/-# add. A kernel built without one passes every other check here and then-# fails init in the initrd of every VM.+# The kernel CI build carries the LSM hooks the programs of bpf/ attach to.+# A kernel built without one passes every other check and then fails init.require_lsm_hooks() {btf="$1"names=$(mktemp) || return 1@@ -74,21 +65,21 @@ require_lsm_hooks() {done)rm -f "$names"[ -z "$missing" ] && return 0- printf 'kernel BTF lacks the LSM hooks%s: build it with kernel/*.patch\n' \+ printf 'kernel BTF lacks the LSM hooks%s: use a shirudo-dev/kernel build\n' \"$missing" >&2return 1}-validate_lvh_kernel() {+validate_kernel_install() {source_dir="$1"[ -d "$source_dir/boot" ] || {- echo "LVH kernel artifacts are missing: $source_dir/boot" >&2+ echo "kernel artifacts are missing: $source_dir/boot" >&2return 1}set -- "$source_dir"/boot/vmlinuz-*[ "$#" -eq 1 ] && [ -s "$1" ] || {- echo "expected one LVH vmlinuz in $source_dir/boot" >&2+ echo "expected one kernel image in $source_dir/boot" >&2return 1}image="$1"@@ -98,108 +89,28 @@ validate_lvh_kernel() {modules="$source_dir/lib/modules/$release"[ -s "$btf" ] || {- echo "LVH kernel BTF is missing: $btf" >&2+ echo "kernel BTF is missing: $btf" >&2return 1}[ -s "$config" ] || {- echo "LVH kernel config is missing: $config" >&2+ echo "kernel config is missing: $config" >&2return 1}[ -d "$modules" ] || {- echo "LVH kernel modules are missing: $modules" >&2+ echo "kernel modules are missing: $modules" >&2return 1}grep -aq 'signature_size' "$btf" || {- echo "LVH kernel BTF lacks bpf_attr.signature_size" >&2+ echo "kernel BTF lacks bpf_attr.signature_size" >&2return 1}require_lsm_hooks "$btf" || return 1- for setting in \- CONFIG_BPF_EVENTS=y \- CONFIG_BPF_LSM=y \- CONFIG_BPF_SYSCALL=y \- CONFIG_BPF_JIT=y \- CONFIG_CGROUP_BPF=y \- CONFIG_FUNCTION_TRACER=y \- CONFIG_DYNAMIC_FTRACE=y \- CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y \- CONFIG_FPROBE=y \- CONFIG_DEBUG_INFO_BTF=y \- CONFIG_KEYS=y \- CONFIG_ASYMMETRIC_KEY_TYPE=y \- CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y \- CONFIG_X509_CERTIFICATE_PARSER=y \- CONFIG_PKCS7_MESSAGE_PARSER=y \- CONFIG_TCG_TPM=y \- CONFIG_TCG_TIS_CORE=y \- CONFIG_TCG_TIS=y \- CONFIG_TCG_CRB=y \- CONFIG_SYSTEM_DATA_VERIFICATION=y \- CONFIG_CRYPTO_MLDSA=y \- CONFIG_CRYPTO_SHA512=y \- CONFIG_CRYPTO_SHA256=y \- CONFIG_MODULE_SIG=y \- CONFIG_MODULE_SIG_ALL=y \- CONFIG_UPROBES=y \- CONFIG_SECURITY=y \- CONFIG_SECURITY_NETWORK=y \- CONFIG_SECURITYFS=y \- CONFIG_MODULES=y \- CONFIG_PCI=y \- CONFIG_PCI_MSI=y \- CONFIG_PCIEPORTBUS=y \- CONFIG_NETDEVICES=y \- CONFIG_ETHERNET=y \- CONFIG_IPV6=y \- CONFIG_PACKET=y \- CONFIG_ISO9660_FS=y \- CONFIG_DEVTMPFS=y \- CONFIG_DEVTMPFS_MOUNT=y \- CONFIG_VIRTIO=y \- CONFIG_VIRTIO_PCI=y \- CONFIG_VIRTIO_BLK=y \- CONFIG_VIRTIO_NET=y \- CONFIG_NET_9P=y \- CONFIG_NET_9P_VIRTIO=y \- CONFIG_9P_FS=y \- CONFIG_OVERLAY_FS=y \- CONFIG_EXT4_FS=y \- CONFIG_EXT4_FS_SECURITY=y \- CONFIG_TMPFS=y \- CONFIG_EFI_PARTITION=y \- CONFIG_ACPI=y \- CONFIG_PNP=y \- CONFIG_PNPACPI=y \- CONFIG_NETFILTER=y \- CONFIG_NETFILTER_INGRESS=y \- CONFIG_NET_NS=y \- CONFIG_NF_CONNTRACK=y \- CONFIG_NF_TABLES=m \- CONFIG_VETH=m \- CONFIG_BRIDGE=m \- CONFIG_VLAN_8021Q=m \- CONFIG_NF_FLOW_TABLE=m \- CONFIG_NF_FLOW_TABLE_INET=m \- CONFIG_NF_FLOW_TABLE_PROCFS=y \- CONFIG_BLK_DEV_INITRD=y \- CONFIG_RD_GZIP=y \- CONFIG_RD_XZ=y \- CONFIG_RD_ZSTD=y \- CONFIG_BLK_DEV_LOOP=y \- CONFIG_BLK_DEV_NVME=y \- CONFIG_EFI=y \- CONFIG_EFI_STUB=y \- CONFIG_SERIAL_8250=y \- CONFIG_SERIAL_8250_CONSOLE=y \- CONFIG_PROC_FS=y- do- require_kernel_config "$config" "$setting" || return 1- donereturn 0}-stage_lvh_kernel() {+stage_kernel_install() {+ rm -rf "$kernel/lib/modules" || return 1mkdir -p "$kernel/lib/modules" || return 1cp "$image" "$kernel/bzImage" || return 1cp "$btf" "$kernel/vmlinux.btf" || return 1@@ -255,17 +166,8 @@ stage_kernel_ci_artifact() {echo "kernel packages did not contain image and modules for $release" >&2return 1}- validate_lvh_kernel "$install_root" || return 1- stage_lvh_kernel-}--build_test_kernel() {- # A restored kernel is older than the checkout of the script that- # built it.- if [ -s "$kernel/bzImage.sha256sum" ]; then- touch "$kernel/bzImage.sha256sum"- fi- make -C testing kernel+ validate_kernel_install "$install_root" || return 1+ stage_kernel_install}setup() {@@ -273,18 +175,11 @@ setup() {sudo rm -rf /opt/ghc /usr/local/lib/android /usr/share/dotnetfi- if [ -n "${KERNEL_CI_ARTIFACT_DIR:-}" ]; then- stage_kernel_ci_artifact "$KERNEL_CI_ARTIFACT_DIR" || exit 1- elif [ -n "${LVH_KERNEL_ARTIFACT_DIR:-}" ] &&- validate_lvh_kernel "$LVH_KERNEL_ARTIFACT_DIR"; then- stage_lvh_kernel || exit 1- else- if [ -n "${LVH_KERNEL_ARTIFACT_DIR:-}" ]; then- printf '%s\n' \- '::warning::LVH kernel is incompatible; using the target kernel cache or building it on a cache miss.'- fi- build_test_kernel+ if [ -z "${KERNEL_CI_ARTIFACT_DIR:-}" ]; then+ echo 'KERNEL_CI_ARTIFACT_DIR must name the downloaded artifact from github.com/shirudo-dev/kernel' >&2+ exit 1fi+ stage_kernel_ci_artifact "$KERNEL_CI_ARTIFACT_DIR" || exit 1# spatch opens libpython3.X.so by that name for the Python of its# rules, and only the -dev package installs it.@@ -369,12 +264,6 @@ export BPF_VMLINUX_BTF="$PWD/$kernel/vmlinux.btf"# emergency mode for instance, would otherwise hold the job for an hour.export TEST_VM_TIMEOUT=900-# The kernel restored from the cache is older than this checkout of the-# script that built it.-if [ -s "$kernel/bzImage.sha256sum" ]; then- touch "$kernel/bzImage.sha256sum"-fi-sudo prlimit --pid "$$" --memlock=unlimited:unlimited# sudo drops LD_LIBRARY_PATH even with -E and replaces PATH with itsdiff --git a/Documentation/concepts/background/tpm.rst b/Documentation/concepts/background/tpm.rstindex 815cd3d2..364597fe 100644--- a/Documentation/concepts/background/tpm.rst+++ b/Documentation/concepts/background/tpm.rst@@ -366,9 +366,9 @@ from the frozen bytes has the recorded modulus.The signature alone does not keep other processes out. The bytes thewriter key derives from are not a secret, so any process that recreatesthe key could ask the TPM to sign. An LSM hook in the kernel keeps-them out. The companion kernel patch-:src:`kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patch` adds an-LSM hook, ``tpm_command``, that sees every command written to+them out. The companion kernel change in the+`shirudo-dev/kernel project <https://github.com/shirudo-dev/kernel>`_+adds an LSM hook, ``tpm_command``, that sees every command written to``/dev/tpm0`` or ``/dev/tpmrm0`` before the driver sends or queues it.shirudo's ``lsm/tpm_command``program refuses ``TPM2_NV_Extend`` of the frozen index to any taskdiff --git a/Documentation/concepts/background/xattrs.rst b/Documentation/concepts/background/xattrs.rstindex cd1f9c42..0f20d40a 100644--- a/Documentation/concepts/background/xattrs.rst+++ b/Documentation/concepts/background/xattrs.rst@@ -74,7 +74,7 @@ kfuncs:Read an xattr whose name starts with ``user.`` or ``security.bpf.``.They first check that the current task may read the inode(``inode_permission()`` with ``MAY_READ``) and return its error if- not; a kernel patch shirudo carries skips that check for+ not; kernel project patch 0002 skips that check for``security.bpf.`` names (:doc:`/internals/kernel-patches`). Bothmay sleep, so only sleepable programs call them.@@ -188,7 +188,7 @@ on the hooks the kernel lists as sleepable, and the read kfuncs need adentry or a file. The hooks that decide a new entry receive thedirectory they change as a ``struct inode``; its dentry is only the newentry's ``d_parent``, a pointer the verifier does not trust. Two kernel-patches shirudo carries change that (:doc:`/internals/kernel-patches`):+project patches change that (:doc:`/internals/kernel-patches`):0003 adds ``inode_mkdir``, ``inode_link``, ``inode_copy_up`` and the ACLand inode flag hooks to the sleepable set, and 0004 lets a program pass``dentry->d_parent`` to the read kfuncs. Whether a hook can read the@@ -298,8 +298,8 @@ Limits------Upstream, the read kfuncs check the calling task's read permission even-for ``security.bpf.`` names; the kernel patch shirudo carries drops that-check for them. On a kernel without the patch, when another LSM, an ACL+for ``security.bpf.`` names; kernel project patch 0002 drops that check+for them. On a kernel without the patch, when another LSM, an ACLor an idmapped mount denies that task read access, the seal decides bythe record of the inode, or of the directory the operation changes, anda labeled inode without a record looks unlabeled. :doc:`/internals/seal`diff --git a/Documentation/contribute/arch-support.rst b/Documentation/contribute/arch-support.rstindex 00ef6215..3cda5580 100644--- a/Documentation/contribute/arch-support.rst+++ b/Documentation/contribute/arch-support.rst@@ -48,10 +48,10 @@ Comparison- Stack-clash protection, call-used register zeroing,``-mbranch-protection=standard``- None- * - Carried kernel patches- - ``kernel/0001`` to ``kernel/0005``- - ``kernel/0001`` to ``kernel/0005``- - ``kernel/0001`` to ``kernel/0005``+ * - Kernel project patch set+ - Included in the external kernel build+ - Included in the external kernel build+ - Included in the external kernel build* - BPF trampolines (``lsm``, ``fentry``, ``fexit``, ``fmod_ret``)- 36 programs per function- 37 programs per function@@ -137,9 +137,8 @@ shirudo- Run the CI tiers on arm64, with the test VM booting on an arm64runner.-- Add riscv64 to the test VM in :src:`testing/vm/arch.sh` and- :src:`testing/vm/build-kernel.sh`, and boot a first riscv64 target with a- TPM.+- Add riscv64 to the test VM in :src:`testing/vm/arch.sh`, and boot a+ first riscv64 target with a TPM.- Build the target binary and the packages for arm64 and riscv64 in CI.- Check that every library the target links builds and runs onriscv64, LuaJIT included.@@ -152,8 +151,8 @@ shirudoLinux kernel~~~~~~~~~~~~-- Get ``kernel/0001`` to ``kernel/0005`` upstream. None of them is in- bpf-next; :doc:`/internals/kernel-patches` describes each.+- Get the remaining kernel changes upstream. The kernel project+ maintains them; :doc:`/internals/kernel-patches` describes each.- riscv64: BPF trampolines on a kernel built with ``CONFIG_CFI``.- riscv64: arenas on CPUs without Zacas.- riscv64: large stacks, exceptions and private stacks in the BPF JIT.diff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rstindex bd47d110..0451dc13 100644--- a/Documentation/contribute/code/developer-guide.rst+++ b/Documentation/contribute/code/developer-guide.rst@@ -134,28 +134,20 @@ The build takes the first of these sources:- Generates the header from a BTF file or an ELF file with a``.BTF`` section.* - ``artifacts/bpf-next-kernel-debs/vmlinux.btf``- - The BTF of the test kernel, when ``make -C testing kernel`` has- built it.+ - The BTF staged from the pinned kernel project artifact.* - ``/sys/kernel/btf/vmlinux``- The running kernel.``vendor/linux/.vmlinux-btf-source`` records the source used. When youselect another one, the next build regenerates the header.-1. Build the test kernel, which also writes its BTF.- :doc:`/contribute/testing/testing` describes the kernel build:-- .. code-block:: console-- $ make -C testing kernel--2. Or name the BTF of the kernel you build for:+1. Name the BTF of the kernel you build for:.. code-block:: console$ make BPF_VMLINUX_BTF=<path-to-btf>-3. Verify which source the header came from:+2. Verify which source the header came from:.. code-block:: console@@ -423,9 +415,9 @@ Project layout- Vendored libbpf and BPF UAPI headers.* - ``vendor/linux/``- The generated ``vmlinux.h``. Not tracked.- * - :src:`kernel/`- - Kernel patches the test kernel build applies. See- :doc:`/internals/kernel-patches`.+ * - ``shirudo-dev/kernel``+ - Kernel source, configuration, patches and built artifacts used+ by CI. See :doc:`/internals/kernel-patches`.* - :src:`upatches/`- The shipped packages, ``kernel-obs`` and ``kernel-cve``, eachwith its Beefile.diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex e8b4cacd..81a91cf7 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -106,13 +106,11 @@ signed config image.- Initrd generator and installer options, the installer's``--dry-run`` plan* - ``t1007-test-vm-cli``- - Test VM scripts: kernel selection, host dependencies, arm64+ - Test VM scripts: kernel artifact selection, host dependencies, arm64boot settings, the bundle stamp, the build container, serve mode,node mode only for a core or edge node of the end-to-end tier,whose vTPM keys the builder helper creates before boot, theoperator VM's role and its signing key- * - ``t1008-kernel-ami-config``- - The slim kernel configuration for NitroTPM CRB, EC2, EFI and SSM* - ``t1009-upatch-isa``- The upatch build compiles for BPF instruction set v4, and a``-mcpu`` in ``--extra-cflags`` replaces it; a dense ``switch``@@ -1055,7 +1053,7 @@ Coverage by area``t7001``, ``t8001``* - Build and packaging- ``t0005``, ``t0007``, ``t1003``, ``t1004``, ``t1005``,- ``t1008``, ``t7004``, ``t8003``+ ``t7004``, ``t8003``* - CI scripts- ``t0001`` to ``t0008``* - Parsers@@ -1283,8 +1281,7 @@ Platforms~~~~~~~~~- Real TPMs. Every TPM test uses ``swtpm`` in the VM or the libtpms- simulator helper. ``t1008`` checks only the kernel configuration for- NitroTPM.+ simulator helper.- Architectures. CI builds and runs the unit tests on arm64 and onriscv64, under QEMU user emulation, with the BPF objects built fromthe BTF of the x86-64 bpf-next kernel. The CI suite also runs unit,diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rstindex f2c09154..0f2d0d10 100644--- a/Documentation/contribute/testing/testing.rst+++ b/Documentation/contribute/testing/testing.rst@@ -60,12 +60,11 @@ kernel does not change what a series is tested on. For a manual run,set ``kernel_run_id`` to select another run. The run must contain thatartifact. The ``KERNEL_REPO_READ_TOKEN`` secret needs Actions readaccess to the kernel repository. Setup extracts the image and headers-packages, checks the kernel config and BTF, and stages the result for-the test VM. It refuses a kernel whose BTF lacks an LSM hook a program-of ``bpf/`` attaches to, or whose config does not sign every module.-A change to ``kernel/`` or to :src:`testing/vm/build-kernel.sh`-therefore needs a new run of the kernel repository and the pin moved to-it before CI can boot the series.+packages, checks BTF for the signed-loader ABI and every LSM hook a+program of ``bpf/`` attaches to, and stages the result for the test VM.+The kernel project owns the kernel source, configuration and patch+application. Changes to those inputs need a successful kernel project+run and an updated pin before CI can boot the series.Test tiers----------@@ -149,8 +148,8 @@ A shell test is named ``t<F><K><NN>-<what>.sh``:* - 1- ``functional/build/``- Helper dispatch, the command surface, the static target, rpm- packaging, the initrd generator and installer, the test VM- scripts and the slim kernel configuration+ packaging, the initrd generator and installer, and the test VM+ scripts* - 2- ``functional/signing/``- Keys, signatures, vouching, revocation and the trusted set@@ -444,63 +443,21 @@ end-to-end test has no TPM and no shirudo kernel arguments; it buildsand installs the operator package and serves the end-to-end run. Theinteractive VM stays up until you stop it.-Build the test kernel-~~~~~~~~~~~~~~~~~~~~~+Use a kernel project artifact+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-``make -C testing kernel`` builds bpf-next with the slim configuration-in :src:`testing/vm/build-kernel.sh` and the patches under :src:`kernel/`. It-writes the kernel image, ``vmlinux.btf``, ``kernel.config``, packages-and a record of the commit it built to-``artifacts/bpf-next-kernel-debs/``. Every target that boots a VM-builds the kernel first when it is missing.+The kernel project publishes the kernel image, BTF, configuration and+modules together. Download the ``kernel-packages-x86-64-ci`` artifact+from the run pinned in :src:`.github/workflows/tests.yml` and pass its+directory to the setup script:-1. Build the kernel:-- .. code-block:: console-- $ make -C testing kernel--2. Verify the commit it built:-- .. code-block:: console-- $ grep '^commit=' artifacts/bpf-next-kernel-debs/bpf-next-kernel-build+.. code-block:: console-The stamp is ``artifacts/bpf-next-kernel-debs/bzImage.sha256sum``-(``Image.sha256sum`` on arm64). Make rebuilds the kernel when-:src:`testing/vm/build-kernel.sh` or a patch under :src:`kernel/` is newer-than the stamp, so a checkout or rebase that touches either rebuilds-it on the next VM run. When you know the kernel is current, touch the-stamp, as :src:`.github/scripts/tests.sh` does. The build removes the-artifact directory first, so do not run it while a VM run or a build-reads ``vmlinux.btf``.+ $ KERNEL_CI_ARTIFACT_DIR=$HOME/Downloads/kernel-packages-x86-64-ci .github/scripts/tests.sh setup-.. list-table::- :header-rows: 1- :widths: 34 66-- * - Variable- - Effect- * - ``KERNEL_TAG=v<version>``- - Builds a release instead of bpf-next, v7.4 or newer, into- ``artifacts/linux-v<version>-kernel-debs/``.- * - ``KERNEL_COMMIT=<sha>``- - Builds an exact commit of a release tag. Not for bpf-next.- * - ``KERNEL_SOURCE_DIR=<dir>``- - Builds from a clean git checkout instead of a fresh clone.- * - ``KERNEL_CONFIG=<file>``- - Starts from a full configuration instead of the slim fragment.- * - ``KERNEL_PATCHES=<dir>``- - Applies these patches instead of :src:`kernel/`.- * - ``KERNEL_BUILD_JOBS=<n>``- - Parallel jobs, ``nproc`` by default.- * - ``WORK_DIR=<dir>``- - The build directory, read from the environment.- ``/tmp/<name>-kernel-build`` by default.--``make -C testing bpf-next`` rebuilds bpf-next without looking at the-stamp. The kernel build installs missing build dependencies with-``apt-get`` or ``dnf``, through ``sudo`` when it does not run as root.+Setup stages the kernel under ``artifacts/bpf-next-kernel-debs/``.+Target VM goals require this artifact; they do not build a kernel from+this checkout.Build the bundle~~~~~~~~~~~~~~~~diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex 917057f5..349f8c78 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -532,7 +532,7 @@ Hooks in seal``mm_access()`` would grant ``CAP_PERFMON`` after the ptrace checkrefused it: ``environ``, ``maps``, ``smaps``, ``pagemap``.- ``EACCES``, uncounted- - Closed, with carried patch 0005.+ - Closed, with kernel project patch 0005.* - ``lsm/perf_event_alloc``- A perf event bound to a marked task. CPU-wide events have no taskand are not checked.diff --git a/Documentation/internals/kernel-interfaces.rst b/Documentation/internals/kernel-interfaces.rstindex dae385a0..c685b1e4 100644--- a/Documentation/internals/kernel-interfaces.rst+++ b/Documentation/internals/kernel-interfaces.rst@@ -54,8 +54,8 @@ Kernel baseline- 7.4 cyclebpf-next contains the signed-loader ABI at merge ``0867b7bfa9de``.-:src:`testing/vm/build-kernel.sh` accepts bpf-next or a release of v7.4 or-later. shirudo defines ``KEY_SPEC_DM_VERITY_KEYRING`` (-10) itself when+The test suite uses the pinned artifact built by ``shirudo-dev/kernel``.+shirudo defines ``KEY_SPEC_DM_VERITY_KEYRING`` (-10) itself whenthe UAPI headers lack it. The ``tpm_command`` LSM hook, the label readswithout the calling task's permission, the sleepable form of six inodehooks, the trusted ``d_parent`` and the ``mm_read_access`` LSM hook are@@ -386,7 +386,7 @@ Kfuncs and helpers- Read ``security.bpf.shirudo``, ``security.bpf.shirudo.policy``and ``security.bpf.shirudo.ancestor``.Sleepable; upstream they check ``MAY_READ`` for the calling task- first, which the carried patch 0002 skips for ``security.bpf.``+ first, which kernel project patch 0002 skips for ``security.bpf.``names.* - ``bpf_inode_init_xattr()``- Add the label in ``inode_init_security``.@@ -571,9 +571,8 @@ that verify a config; see :doc:`config-images`. ``CONFIG_SECCOMP=n``is handled: the seal then sees no seccomp state. The attach kinds ofupatches can need further options; see :doc:`/upatches/write/attach-kinds`.-:src:`testing/vm/build-kernel.sh` enforces its own list with-``require_config``, which also covers what the test fixtures and the test-VM need.+The kernel project configures the test kernel with these options and the+additional options the test fixtures and VM need.Kernel command line-------------------diff --git a/Documentation/internals/kernel-patches.rst b/Documentation/internals/kernel-patches.rstindex 475e4f8a..7eed7a86 100644--- a/Documentation/internals/kernel-patches.rst+++ b/Documentation/internals/kernel-patches.rst@@ -8,8 +8,10 @@Carried kernel patches======================-The kernel patches in :src:`kernel/` of the shirudo tree. The test kernel-build applies them; a production kernel needs the same changes.+The kernel changes shirudo needs and the external project that builds+them. The ``shirudo-dev/kernel`` repository carries these changes and+publishes the kernel artifacts used by the test suite. A production+kernel needs the same changes.Summary-------@@ -59,14 +61,13 @@ which bpf-next and the bpf fixes tree for 7.4 contain and which thetree does not carry; :doc:`/operate/plan/system-requirements` sayswhy.-How the test kernel applies them---------------------------------+How the test kernel includes them+----------------------------------``make -C testing kernel`` passes ``KERNEL_PATCHES``, which defaults to-:src:`kernel/` when that directory holds patches.-:src:`testing/vm/build-kernel.sh` applies each patch in name order with-``git apply --index`` and commits it, and skips a patch whose reverse-already applies. A patch that applies neither way fails the build.+The kernel project maintains and builds the patches. CI downloads its+kernel package artifact and checks the BTF ABI and LSM hooks before it+stages the image for the test VM. The kernel configuration and patch+application are owned by that project.TPM command LSM hook--------------------diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rstindex 497ab7db..3ad1c2d1 100644--- a/Documentation/internals/seal.rst+++ b/Documentation/internals/seal.rst@@ -174,7 +174,7 @@ task. It counts one whose mode includes ``PTRACE_MODE_ATTACH````pidfd_getfd()`` and ``process_vm_readv()``, and refuses a read-modeone uncounted, because journald reads ``/proc/<pid>/exe`` of everyprocess it logs for and a counted read would rise on an honest node.-``lsm/mm_read_access``, a hook of carried patch 0005, refuses the+``lsm/mm_read_access``, a hook of kernel project patch 0005, refuses theread-only access ``mm_access()`` grants ``CAP_PERFMON`` after thatrefusal, to ``environ``, ``maps`` and the other memory files. ``lsm/perf_event_alloc``refuses a perf event bound to a marked task (``SealPerf``).@@ -265,7 +265,7 @@ Reading the label~~~~~~~~~~~~~~~~~The seal reads the label with the ``bpf_get_file_xattr()`` and-``bpf_get_dentry_xattr()`` kfuncs. With the carried kernel patch they+``bpf_get_dentry_xattr()`` kfuncs. With the kernel project patch theyreturn a ``security.bpf.`` label as the in-kernel LSMs read theirs,without the calling task's permission. Upstream they first check thatthe calling task may read the inode, against its raw ids, and root can@@ -397,11 +397,11 @@ Marks are a cacheentry's parent dentry and refresh its mark on the way, which``inode_init_security``, the one hook without a dentry, labels thenew inode from in the same operation. On a kernel without the- carried patches 0003 and 0004, the seal's entry hooks do not load+ kernel project patches 0003 and 0004, the seal's entry hooks do not loadand ``init`` fails.Label reads on an upstream kernel- Without the carried xattr patch, the kfuncs check that the calling+ Without kernel project patch 0002, the kfuncs check that the callingtask may read the inode, and every LSM's ``inode_permission`` hooktakes part. A read that fails for the caller, through an idmappedmount, an ACL or another LSM's policy, makes a labeled inodediff --git a/Documentation/operate/plan/hardening.rst b/Documentation/operate/plan/hardening.rstindex ddd7563c..8fa5145a 100644--- a/Documentation/operate/plan/hardening.rst+++ b/Documentation/operate/plan/hardening.rst@@ -101,8 +101,7 @@ Kernel configurationcount, including the module signing key of the kernel build, sokeep that key in the same custody as the config key.- no- * - The ``tpm_command`` LSM hook from ``kernel/0001`` in the shirudo- tree+ * - The ``tpm_command`` LSM hook carried by the shirudo kernel build- The hook lets shirudo refuse extensions of its register byother processes.- init fails: ``lsm/tpm_command`` cannot attachdiff --git a/Documentation/operate/plan/interoperability.rst b/Documentation/operate/plan/interoperability.rstindex 29cd25ab..f6dabe2a 100644--- a/Documentation/operate/plan/interoperability.rst+++ b/Documentation/operate/plan/interoperability.rst@@ -314,7 +314,7 @@ Other LSMsshirudo's programs and moves no counter. With ``bpf`` before them,shirudo's refusal ends the walk and the other LSM does not see or logthe attempt.-:Seal labels: With the carried kernel patch, the seal reads a file's+:Seal labels: With the kernel project patch, the seal reads a file'slabel as the in-kernel LSMs read theirs, without the caller's readpermission, and no other LSM's ``inode_permission`` policy can hideit. On an upstream kernel the kfunc checks that permission, everydiff --git a/Documentation/operate/plan/overhead.rst b/Documentation/operate/plan/overhead.rstindex f09c779b..c6b336e4 100644--- a/Documentation/operate/plan/overhead.rst+++ b/Documentation/operate/plan/overhead.rst@@ -40,7 +40,7 @@ Measurement setup- A test VM: ``q35`` machine, 4 vCPUs (``-cpu host``), 4 GiB ofmemory, Ubuntu 26.04 with systemd 259.* - Kernel- - bpf-next, built by ``make -C testing kernel``.+ - The pinned bpf-next artifact from ``shirudo-dev/kernel``.* - TPM- swtpm 0.7.3, a software TPM, through ``/dev/tpmrm0``.* - Methoddiff --git a/Documentation/operate/plan/system-requirements.rst b/Documentation/operate/plan/system-requirements.rstindex b97e415e..396b891e 100644--- a/Documentation/operate/plan/system-requirements.rst+++ b/Documentation/operate/plan/system-requirements.rst@@ -75,60 +75,58 @@ Kernel sourcewith gcc 13 and ``CONFIG_CC_OPTIMIZE_FOR_SIZE=y``). Unloading aupatch detaches its programs from hooks that other programsshare. Apply it to an x86-64 tree that predates it.- * - :src:`kernel/0001 <kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patch>`+ * - ``tpm_command`` LSM hook- Adds the ``tpm_command`` LSM hook. ``shirudo init`` attaches``lsm/tpm_command`` to refuse an untrusted ``TPM2_NV_Extend`` ofits register and fails without the hook.- * - :src:`kernel/0002 <kernel/0002-bpf-Read-security.bpf-xattrs-for-LSM-programs-without-the-caller-s-permission.patch>`+ * - BPF LSM xattr reads- Lets an LSM program read a ``security.bpf.`` xattr without thecalling task's read permission on the inode, as the in-kernelLSMs read their labels. Without it the seal takes a label itscaller may not read for a missing one unless the inode carries amark, which root can arrange with an idmapped mount or an ACL.- * - :src:`kernel/0003 <kernel/0003-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch>`+ * - Sleepable inode hooks- Lets a sleepable LSM program attach to ``inode_mkdir``,``inode_link``, ``inode_set_acl``, ``inode_remove_acl``,``inode_file_setattr`` and ``inode_copy_up``. The seal readslabels in those hooks and ``shirudo init`` fails to attach themwithout it.- * - :src:`kernel/0004 <kernel/0004-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch>`+ * - Trusted ``dentry->d_parent``- Lets an LSM program pass ``dentry->d_parent`` to the xattr kfunc.The seal reads the label of the directory a new entry goes intofrom it; without the patch the verifier refuses the seal's entryhooks.- * - :src:`kernel/0005 <kernel/0005-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch>`+ * - ``mm_read_access`` LSM hook- Adds the ``mm_read_access`` LSM hook, which ``mm_access()`` asksbefore it grants a read-only access to another task's memory to``CAP_PERFMON``. The seal refuses a task with runtime authoritythere, and ``init`` fails without the hook.-:doc:`/internals/kernel-patches` gives the upstream status of the-carried patches.+:doc:`/internals/kernel-patches` describes the required changes and+their status. The `shirudo-dev/kernel repository+<https://github.com/shirudo-dev/kernel>`_ maintains the patches and+builds the test and production kernel artifacts.Identify the kernel~~~~~~~~~~~~~~~~~~~-- Record the source commit and the patches applied when you build the- kernel. ``make -C testing kernel`` writes them as ``commit=``,- ``upstream_commit=`` and ``patches_applied=`` to a- ``<name>-kernel-build`` file beside the kernel packages, for bpf-next- ``bpf-next-kernel-build``.+- Record the source commit and patches from the kernel build artifact's+ ``<name>-kernel-build`` metadata file.- ``shirudo init --check-only`` checks the ABI of the running kernelfrom its BTF (``signed_loader_kernel_abi``). A load on a kernelwithout it fails with ``kernel_abi_unsupported``. It also checks thatthe kernel has every LSM hook the embedded programs attach to(``kernel_lsm_hooks``), and names the hooks a kernel built without- the carried patches lacks.-- The test harness builds bpf-next by default. It also builds release- tags and refuses any tag older than v7.4. It applies the patches in- :src:`kernel/` to either. A release kernel still needs ``kernel/0001``.+ the kernel project patch set lacks.+- The test harness uses the pinned kernel build artifact from+ `shirudo-dev/kernel <https://github.com/shirudo-dev/kernel>`_. The+ kernel project owns its source, configuration and patch application.Kernel configuration~~~~~~~~~~~~~~~~~~~~-shirudo needs every option below. The test kernel's configuration is the-slim configuration in :src:`testing/vm/build-kernel.sh`, which also enables-options that only the tests use.+shirudo needs every option below. The kernel project's CI profile sets+these options and additional ones that the tests use... list-table:::header-rows: 1diff --git a/Documentation/operate/troubleshoot/troubleshooting.rst b/Documentation/operate/troubleshoot/troubleshooting.rstindex ab2b97a9..06f5a84c 100644--- a/Documentation/operate/troubleshoot/troubleshooting.rst+++ b/Documentation/operate/troubleshoot/troubleshooting.rst@@ -500,7 +500,7 @@ MeaningCausesThe check names the requirement that is missing: root, the BPF LSMin the kernel's active LSM list, bpffs, the signed-loader ABI, an- LSM hook only the carried kernel patches add, the certificate and+ LSM hook only the kernel project patches add, the certificate andits algorithm, the kernel keyring, the embedded loader or the TPM.Actiondiff --git a/Documentation/reference/versions.rst b/Documentation/reference/versions.rstindex 80bab339..30bc93ce 100644--- a/Documentation/reference/versions.rst+++ b/Documentation/reference/versions.rst@@ -227,7 +227,7 @@ kernel. The pre-flight checks ``signed_loader_kernel_abi`` andkernel without the ABI fails with ``kernel_abi_unsupported``.:doc:`/operate/plan/system-requirements` lists the kernel requirements and howto identify a kernel, :doc:`/internals/kernel-interfaces` every interface-shirudo uses, and :doc:`/internals/kernel-patches` the carried patches.+shirudo uses, and :doc:`/internals/kernel-patches` the kernel project patches.Mixing builds-------------diff --git a/Documentation/security/security-model.rst b/Documentation/security/security-model.rstindex bd49f46e..f9ad78fd 100644--- a/Documentation/security/security-model.rst+++ b/Documentation/security/security-model.rst@@ -94,7 +94,7 @@ The properties above hold only on a deployment that provides the:ref:`assumptions <tm-assumptions>`. In brief:- A trusted kernel with the BPF LSM, the signed-loader ABI and the- carried kernel patches+ kernel project patches- Module signatures, no 32-bit compatibility, no resume device in theUKI and no writes under mounted file systems- Secure Boot with a signed, measured UKI and an authenticated kerneldiff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex e5930a7c..e5161f84 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -159,12 +159,9 @@ without the protection.``inode_remove_acl``, ``inode_file_setattr`` and``inode_copy_up``, a ``dentry->d_parent`` the verifier trusts,and the ``mm_read_access`` LSM hook. Upstream has none of these,- and shirudo carries them as- :src:`kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patch`,- :src:`kernel/0002-bpf-Read-security.bpf-xattrs-for-LSM-programs-without-the-caller-s-permission.patch`,- :src:`kernel/0003-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch`,- :src:`kernel/0004-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch`- and :src:`kernel/0005-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch`.+ and the `shirudo-dev/kernel project+ <https://github.com/shirudo-dev/kernel>`_ carries them in the+ target kernel build.- T1 needs the ABI, T5 the hook, T3 the label read, the sleepablehooks, the trusted parent and the read-only mm access hook.- Partly. The pre-flight checks ``signed_loader_kernel_abi`` and@@ -416,7 +413,7 @@ Figure 1 shows the parties and where trust ends.Figure 1. Trust boundaries and the evidence boundary.The target TCB is the kernel with its configuration and command line-(A1, A4, A11) and the carried kernel patches (A3); the firmware, boot loader+(A1, A4, A11) and the kernel project patches (A3); the firmware, boot loaderand UKI (A6); the TPM (A15); the initrd and every unit it runs before``shirudo-initrd.service`` completes; and the runtime image. Theruntime image holds the shirudo binary with its two embedded BPF@@ -793,7 +790,7 @@ receive no binding to these maps.A labeled directory takes new entries, by create, mkdir, symlink,mknod, hard link or rename, only from authorized tasks (``SealEntry``):each entry hook reads the directory's label from the new entry's parent-dentry, which the carried patches 0003 and 0004 (A3) make possible by+dentry, which the kernel project patches 0003 and 0004 (A3) make possible byletting a sleepable program attach to ``inode_mkdir`` and ``inode_link``and by trusting ``dentry->d_parent``, and refreshes the directory'smark on the way, from which ``lsm/inode_init_security`` gives the new@@ -872,7 +869,7 @@ An authorized process is protected against being taken over:``/proc/<pid>/exe``, ``environ``, ``maps`` and the ``fd`` links,without a counter. ``lsm/mm_read_access`` refuses the read-onlyaccess ``mm_access()`` would otherwise grant ``CAP_PERFMON`` past that- refusal (carried patch 0005, A3).+ refusal (kernel project patch 0005, A3).- ``lsm/perf_event_alloc`` refuses a perf event bound to a marked task(``SealPerf``). Events on all tasks of a CPU, and events opened on atask before the exec that marks it, are not checked (D9).@@ -2206,8 +2203,8 @@ the procedures.The deployer:-- Builds the kernel with the signed-loader ABI and the carried kernel- patches (A3), ``CONFIG_MODULE_SIG`` (A4),+- Builds the kernel with the signed-loader ABI and the kernel project+ patch set (A3), ``CONFIG_MODULE_SIG`` (A4),``CONFIG_COMPAT=n`` (A5), bothdm-verity keyring options off and no foreign built-in certificate(A7), the TPM driver without ``i2c-dev`` or ``spidev`` on its busdiff --git a/Documentation/start/faq.rst b/Documentation/start/faq.rstindex 4dfb156f..6534e01a 100644--- a/Documentation/start/faq.rst+++ b/Documentation/start/faq.rst@@ -52,7 +52,7 @@ Which kernel does a target need?--------------------------------A kernel with the signed-loader ABI of bpf-next and the ``tpm_command``-patch that shirudo carries, plus a second patch on x86-64.+patch in the shirudo kernel build, plus a second patch on x86-64.:doc:`/operate/plan/system-requirements` lists the kernel options and:doc:`/internals/kernel-patches` the patches.diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rstindex 83e0c582..16c461c2 100644--- a/Documentation/start/quickstart.rst+++ b/Documentation/start/quickstart.rst@@ -25,8 +25,9 @@ Before you beginbinaries lock their memory and refuse to run without it. Root is notneeded; the test VM builds its initrd with dracut as you, withoutchanging the host's dracut.-- Network access. The first boot clones the bpf-next kernel tree and- downloads an Ubuntu cloud image.+- Network access. The first boot downloads an Ubuntu cloud image. Get+ the test kernel package artifact from the pinned run in+ ``.github/workflows/tests.yml`` before building the target binary.- To build shirudo: a C toolchain with ``make`` and ``pkg-config``, aclang and LLVM 23 with the BPF target, ``clang`` installed as``/usr/bin/clang``, and the development files of OpenSSL 3.5 or later,@@ -41,25 +42,24 @@ Before you begin``isc-dhcp-client``, ``curl``, ``kmod`` and ``file``, and the staticarchives the target binary links: libelf, zlib, zstd, LuaJIT and a staticglibc. The VM scripts stop at the first missing command and print the- command that installs it. The kernel build installs its own build- dependencies.+ command that installs it.- ``jq`` and the ``openssl`` command, for the attestation step.:doc:`/operate/plan/system-requirements` lists the requirements in full.-Build a target kernel-----------------------+Use the test kernel artifact+-----------------------------Before we build shirudo, we need a kernel for it to build against:-shirudo's embedded BPF objects compile against a kernel's BTF and use-the signed-loader ABI that only a bpf-next kernel patched under-:src:`kernel/` has. Without one, the build falls back to the BTF of the-kernel you are running, which lacks that ABI and fails to build. Build-one first:+Download the ``kernel-packages-x86-64-ci`` artifact from the run pinned+in ``.github/workflows/tests.yml``. Stage it and prepare the test host:.. code-block:: console- operator$ make -C testing kernel+ operator$ KERNEL_CI_ARTIFACT_DIR=$HOME/Downloads/kernel-packages-x86-64-ci \+ .github/scripts/tests.sh setup++The artifact includes the kernel, its BTF, configuration and modules.+shirudo compiles its embedded BPF objects against that BTF.Build shirudo-------------@@ -105,10 +105,9 @@ Boot a test target[test-vm] console: make -C testing vm-console VM_NAME=quickstart[test-vm] ssh: make -C testing vm-ssh- The first run takes a while. It builds a bpf-next kernel with the- patches under :src:`kernel/`, an Ubuntu disk image and a bundle: the static- target binary, a dm-verity runtime image, signed config images and a- throwaway signing key. Later runs reuse them.+ The first run takes a while. It builds an Ubuntu disk image and a+ bundle: the static target binary, a dm-verity runtime image, signed+ config images and a throwaway signing key. Later runs reuse them.The VM boots the way a production target does. The kernel starts withthe BPF LSM and with the ``.bpf`` and ``.dm-verity`` keyrings open fordiff --git a/Documentation/start/who-is-shirudo-for.rst b/Documentation/start/who-is-shirudo-for.rstindex e1cb455a..f24da34f 100644--- a/Documentation/start/who-is-shirudo-for.rst+++ b/Documentation/start/who-is-shirudo-for.rst@@ -119,7 +119,7 @@ When shirudo is not a fit yet- shirudo has no release. ``main`` is the development branch, and noformat carries a compatibility promise yet.- A target needs a bpf-next kernel with the signed-loader interface and- the patches shirudo carries, a TPM 2.0, and a unified kernel image+ the patches in the shirudo kernel build, a TPM 2.0, and a unified kernel imagebooted through ``systemd-stub`` with a systemd initrd built by dracut.There is no fallback for an older kernel.- On an enforcing target, only signed upatches run BPF. BPF-baseddiff --git a/kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patch b/kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patchdeleted file mode 100644index 8f1f273c..00000000--- a/kernel/0001-tpm-Let-LSMs-inspect-userspace-commands.patch+++ /dev/null@@ -1,139 +0,0 @@-From b0cbdcfd2176e8e1056334085b6da92bc0dd0dc2 Mon Sep 17 00:00:00 2001-From: KP Singh <[email protected]>-Date: Wed, 28 Oct 2026 16:26:25 +0100-Subject: [PATCH] tpm: Let LSMs inspect userspace commands--Shirudo keeps the key that authorizes its TPM NV writes inside the TPM.-Another process can recreate that key and ask the TPM to sign. An LSM-therefore needs the target index of an NV_Extend command to decide-whether the caller may change Shirudo's register. A check made when the-TPM device is opened would miss inherited descriptors.--Call a new tpm_command hook after copying the command from userspace and-validating its header. Pass the device file, copied command, and the-header's declared length while the buffer is locked. The hook runs-before both direct transmission and nonblocking queueing. The declared-length keeps any trailing write bytes out of the policy decision.--Link: https://github.com/shirudo-dev/shirudo/pull/57-Signed-off-by: KP Singh <[email protected]>----- drivers/char/tpm/tpm-dev-common.c | 13 +++++++++++--- include/linux/lsm_hook_defs.h | 2 ++- include/linux/security.h | 8 ++++++++- security/security.c | 18 ++++++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-)--diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c-index 6569212dc6b8..15b72b4a0885 100644---- a/drivers/char/tpm/tpm-dev-common.c-+++ b/drivers/char/tpm/tpm-dev-common.c-@@ -13,6 +13,7 @@- * Device file system interface to the TPM- */- #include <linux/poll.h>-+#include <linux/security.h>- #include <linux/slab.h>- #include <linux/uaccess.h>- #include <linux/workqueue.h>-@@ -174,6 +175,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,- size_t size, loff_t *off)- {- struct file_priv *priv = file->private_data;-+ struct tpm_header *header;- int ret = 0;-- if (size > TPM_BUFSIZE)-@@ -196,12 +198,19 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,- goto out;- }--- if (size < 6 ||-- size < be32_to_cpu(*((__be32 *)(priv->data_buffer + 2)))) {-+ header = (struct tpm_header *)priv->data_buffer;-+ if (size < sizeof(*header) ||-+ be32_to_cpu(header->length) < sizeof(*header) ||-+ size < be32_to_cpu(header->length)) {- ret = -EINVAL;- goto out;- }--+ ret = security_tpm_command(file, priv->data_buffer,-+ be32_to_cpu(header->length));-+ if (ret)-+ goto out;-+- priv->response_length = 0;- priv->response_read = false;- *off = 0;-diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h-index 87d9d06710cb..90209bf5cf6f 100644---- a/include/linux/lsm_hook_defs.h-+++ b/include/linux/lsm_hook_defs.h-@@ -189,6 +189,8 @@ LSM_HOOK(int, 0, inode_setintegrity, const struct inode *inode,- LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir,- struct kernfs_node *kn)- LSM_HOOK(int, 0, file_permission, struct file *file, int mask)-+LSM_HOOK(int, 0, tpm_command, struct file *file,-+ const u8 *command, size_t command_len)- LSM_HOOK(int, 0, file_alloc_security, struct file *file)- LSM_HOOK(void, LSM_RET_VOID, file_release, struct file *file)- LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file)-diff --git a/include/linux/security.h b/include/linux/security.h-index 40831fab5470..f017412d5adb 100644---- a/include/linux/security.h-+++ b/include/linux/security.h-@@ -475,6 +475,8 @@ int security_inode_setintegrity(const struct inode *inode,- int security_kernfs_init_security(struct kernfs_node *kn_dir,- struct kernfs_node *kn);- int security_file_permission(struct file *file, int mask);-+int security_tpm_command(struct file *file, const u8 *command,-+ size_t command_len);- int security_file_alloc(struct file *file);- void security_file_release(struct file *file);- void security_file_free(struct file *file);-@@ -1152,6 +1154,12 @@ static inline int security_file_permission(struct file *file, int mask)- return 0;- }--+static inline int security_tpm_command(struct file *file,-+ const u8 *command, size_t command_len)-+{-+ return 0;-+}-+- static inline int security_file_alloc(struct file *file)- {- return 0;-diff --git a/security/security.c b/security/security.c-index f6583d507395..86636c894ebe 100644---- a/security/security.c-+++ b/security/security.c-@@ -2414,6 +2414,24 @@ int security_file_permission(struct file *file, int mask)- return call_int_hook(file_permission, file, mask);- }--+/**-+ * security_tpm_command() - Check a userspace TPM command-+ * @file: TPM device file-+ * @command: TPM command copied from userspace-+ * @command_len: length declared in the validated command header-+ *-+ * Check a command before the TPM driver queues or sends it. The command-+ * remains in the device buffer until this call returns.-+ *-+ * Return: Returns 0 if permission is granted.-+ */-+int security_tpm_command(struct file *file, const u8 *command,-+ size_t command_len)-+{-+ return call_int_hook(tpm_command, file, command, command_len);-+}-+EXPORT_SYMBOL_GPL(security_tpm_command);-+- /**- * security_file_alloc() - Allocate and init a file's LSM blob- * @file: the file----2.53.0-diff --git a/kernel/0002-bpf-Read-security.bpf-xattrs-for-LSM-programs-without-the-caller-s-permission.patch b/kernel/0002-bpf-Read-security.bpf-xattrs-for-LSM-programs-without-the-caller-s-permission.patchdeleted file mode 100644index 9994cee0..00000000--- a/kernel/0002-bpf-Read-security.bpf-xattrs-for-LSM-programs-without-the-caller-s-permission.patch+++ /dev/null@@ -1,64 +0,0 @@-From 4d30e9a670741ab7ab778f28bebf445624416059 Mon Sep 17 00:00:00 2001-From: Daniel Borkmann <[email protected]>-Date: Tue, 3 Nov 2026 10:49:48 +0000-Subject: [PATCH] bpf: Read security.bpf xattrs for LSM programs without the- caller's permission--bpf_get_dentry_xattr() and bpf_get_file_xattr() check that the current-task may read the inode before they return an xattr, for user. and-security.bpf. names alike. For a BPF LSM program the labels it keeps-under security.bpf. are its own, and the task whose operation it decides-is the one the program may refuse: its read permission on the inode says-nothing about the label. The in-kernel LSMs read their labels with-__vfs_getxattr() in kernel context for that reason.--The check also lets that task choose what the program sees. A read that-fails with -EACCES or -EPERM looks to the program like a missing label-unless it fails every such operation closed, which it cannot do without-refusing every write-only open and every unlink of an unreadable file on-the system. Root arranges the failure for any labeled inode: an idmapped-bind mount shows uid 0's files as another id's to the permission check,-an ACL grants another id a write without a read, and a task at that id-through setfsuid() keeps CAP_SYS_ADMIN but not the DAC capabilities, so-the kernel lets it write what the program then takes for unlabeled.-Another LSM's inode_permission policy does the same.--Skip the permission check for security.bpf. names. The kfuncs are-registered for LSM and struct_ops programs, which run in kernel context-with the labels they maintain; user. names keep the check.--Signed-off-by: Daniel Borkmann <[email protected]>----- fs/bpf_fs_kfuncs.c | 16 +++++++++++++---- 1 file changed, 13 insertions(+), 3 deletions(-)--diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c-index 35ccd98a4de6..3447159eb919 100644---- a/fs/bpf_fs_kfuncs.c-+++ b/fs/bpf_fs_kfuncs.c-@@ -106,9 +106,19 @@ static int bpf_xattr_read_permission(const char *name, struct inode *inode)- if (!inode)- return -EINVAL;--- /* Allow reading xattr with user. and security.bpf. prefix */-- if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&-- !match_security_bpf_prefix(name))-+ /*-+ * The labels a BPF LSM keeps under security.bpf. are its own, read-+ * as SELinux, Smack and EVM read theirs with __vfs_getxattr(): in-+ * kernel context, not with the permission of the task whose-+ * operation the program decides. That task's read permission says-+ * nothing about the label, and a read that fails for it, through an-+ * idmapped mount, an ACL or another LSM's policy, would hide the-+ * label from the program that enforces it. user. xattrs stay the-+ * task's to read.-+ */-+ if (match_security_bpf_prefix(name))-+ return 0;-+ if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))- return -EPERM;-- return inode_permission(&nop_mnt_idmap, inode, MAY_READ);----2.43.0-diff --git a/kernel/0003-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch b/kernel/0003-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patchdeleted file mode 100644index ce1c7fc1..00000000--- a/kernel/0003-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch+++ /dev/null@@ -1,61 +0,0 @@-From 4394d88fc34a232779f9b1322c5cf6169e3fab13 Mon Sep 17 00:00:00 2001-From: Daniel Borkmann <[email protected]>-Date: Tue, 3 Nov 2026 13:52:42 +0000-Subject: [PATCH] bpf: Let sleepable LSM programs attach to the remaining inode- hooks--A BPF LSM program reads an xattr with bpf_get_dentry_xattr() or-bpf_get_file_xattr(), which sleep, so only a sleepable program can-decide an operation by the label an inode carries. The set of hooks-such a program may attach to holds inode_create, inode_symlink,-inode_mknod, inode_unlink, inode_rename, inode_rmdir, inode_setattr,-inode_setxattr and inode_removexattr, but not inode_mkdir and-inode_link, the other two hooks that decide a new directory entry, nor-inode_set_acl, inode_remove_acl and inode_file_setattr, which decide-an ACL and an inode flag change, nor inode_copy_up, which decides an-overlay copy-up. Each of them is called from process context with the-inode lock held, as the hooks already in the set are, and may sleep.--Add them, so that a program which labels directories can read the-label of the directory a mkdir or a link changes, the label of the-inode an ACL or flag change targets, and the label of the inode an-overlay copies up, instead of a cache of its own that the inode's-eviction empties.--Signed-off-by: Daniel Borkmann <[email protected]>----- kernel/bpf/bpf_lsm.c | 6 ++++++- 1 file changed, 6 insertions(+)--diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c-index f58dce888ff4..688c249680ef 100644---- a/kernel/bpf/bpf_lsm.c-+++ b/kernel/bpf/bpf_lsm.c-@@ -333,18 +333,24 @@ BTF_ID(func, bpf_lsm_file_open)- BTF_ID(func, bpf_lsm_file_post_open)- BTF_ID(func, bpf_lsm_file_receive)--+BTF_ID(func, bpf_lsm_inode_copy_up)- BTF_ID(func, bpf_lsm_inode_create)-+BTF_ID(func, bpf_lsm_inode_file_setattr)- BTF_ID(func, bpf_lsm_inode_free_security)- BTF_ID(func, bpf_lsm_inode_getattr)- BTF_ID(func, bpf_lsm_inode_getxattr)-+BTF_ID(func, bpf_lsm_inode_link)-+BTF_ID(func, bpf_lsm_inode_mkdir)- BTF_ID(func, bpf_lsm_inode_mknod)- BTF_ID(func, bpf_lsm_inode_need_killpriv)- BTF_ID(func, bpf_lsm_inode_post_setxattr)- BTF_ID(func, bpf_lsm_inode_post_removexattr)- BTF_ID(func, bpf_lsm_inode_readlink)-+BTF_ID(func, bpf_lsm_inode_remove_acl)- BTF_ID(func, bpf_lsm_inode_removexattr)- BTF_ID(func, bpf_lsm_inode_rename)- BTF_ID(func, bpf_lsm_inode_rmdir)-+BTF_ID(func, bpf_lsm_inode_set_acl)- BTF_ID(func, bpf_lsm_inode_setattr)- BTF_ID(func, bpf_lsm_inode_setxattr)- BTF_ID(func, bpf_lsm_inode_symlink)----2.43.0-diff --git a/kernel/0004-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch b/kernel/0004-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patchdeleted file mode 100644index 6375790c..00000000--- a/kernel/0004-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch+++ /dev/null@@ -1,39 +0,0 @@-From 66a9f20316aea80c61881a1c4c722261587375ee Mon Sep 17 00:00:00 2001-From: Daniel Borkmann <[email protected]>-Date: Tue, 3 Nov 2026 13:52:42 +0000-Subject: [PATCH] bpf: Treat dentry->d_parent as a trusted pointer--An LSM program that decides a new directory entry in inode_create,-inode_mkdir, inode_symlink, inode_mknod or inode_link receives the-directory as a struct inode and the new entry as a dentry. The-directory's label lives in an xattr that bpf_get_dentry_xattr() reads-from a dentry, and the one the program has for it is dentry->d_parent,-which the verifier treats as an untrusted pointer, so the kfunc refuses-it and the program cannot read the label of the directory it decides-on.--d_parent of a dentry an inode hook receives is stable while the hook-runs, under the parent's inode lock the caller holds, and is never NULL,-since the root's points to itself. Add it beside d_inode as trusted or-null, which keeps a program checking it before use.--Signed-off-by: Daniel Borkmann <[email protected]>----- kernel/bpf/verifier.c | 1 +- 1 file changed, 1 insertion(+)--diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c-index 935b163f81e4..0ef1d5076485 100644---- a/kernel/bpf/verifier.c-+++ b/kernel/bpf/verifier.c-@@ -6509,6 +6509,7 @@ BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args) {-- BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry) {- struct inode *d_inode;-+ struct dentry *d_parent;- };-- BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct linux_binprm) {----2.43.0-diff --git a/kernel/0005-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch b/kernel/0005-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patchdeleted file mode 100644index 850b0a45..00000000--- a/kernel/0005-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch+++ /dev/null@@ -1,113 +0,0 @@-From 94eb18b95c122ad0747d3c4030dce92c65ce9a97 Mon Sep 17 00:00:00 2001-From: Daniel Borkmann <[email protected]>-Date: Tue, 17 Nov 2026 12:20:31 +0000-Subject: [PATCH] mm: Let LSMs check read-only remote mm access under- CAP_PERFMON--Since commit 0c555a3c1bc9 ("mm,procfs: allow read-only remote mm access-under CAP_PERFMON"), mm_access() grants a read-mode access to a caller-with CAP_PERFMON or CAP_SYS_ADMIN after ptrace_may_access() refused it.-The refusal may have come from an LSM's ptrace_access_check hook, which-then has no say: /proc/<pid>/environ, maps, smaps, numa_maps, pagemap-and auxv of a task the LSM keeps others away from open all the same.--Shirudo marks the processes that run its runtime binary and refuses-every ptrace access to them from tasks without its authority. With the-perfmon path, root reads their environment and their memory layout.--Call a new mm_read_access hook before mm_access() grants a read-mode-access that way. It sees the target task and the PTRACE_MODE flags of-the access, as ptrace_access_check does, and is consulted only on the-CAP_PERFMON path, so an access ptrace_may_access() allows is not-checked twice.--Signed-off-by: Daniel Borkmann <[email protected]>----- include/linux/lsm_hook_defs.h | 1 +- include/linux/security.h | 7 +++++++- kernel/fork.c | 3 ++-- security/security.c | 17 +++++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-)--diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h-index 90209bf5cf6f..c52571d8ee65 100644---- a/include/linux/lsm_hook_defs.h-+++ b/include/linux/lsm_hook_defs.h-@@ -36,6 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from,- LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,- unsigned int mode)- LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent)-+LSM_HOOK(int, 0, mm_read_access, struct task_struct *task, unsigned int mode)- LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective,- kernel_cap_t *inheritable, kernel_cap_t *permitted)- LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old,-diff --git a/include/linux/security.h b/include/linux/security.h-index f017412d5adb..e44a065b1145 100644---- a/include/linux/security.h-+++ b/include/linux/security.h-@@ -340,6 +340,7 @@ int security_binder_transfer_file(const struct cred *from,- const struct cred *to, const struct file *file);- int security_ptrace_access_check(struct task_struct *child, unsigned int mode);- int security_ptrace_traceme(struct task_struct *parent);-+int security_mm_read_access(struct task_struct *task, unsigned int mode);- int security_capget(const struct task_struct *target,- kernel_cap_t *effective,- kernel_cap_t *inheritable,-@@ -687,6 +688,12 @@ static inline int security_ptrace_traceme(struct task_struct *parent)- return cap_ptrace_traceme(parent);- }--+static inline int security_mm_read_access(struct task_struct *task,-+ unsigned int mode)-+{-+ return 0;-+}-+- static inline int security_capget(const struct task_struct *target,- kernel_cap_t *effective,- kernel_cap_t *inheritable,-diff --git a/kernel/fork.c b/kernel/fork.c-index 8b108ed37152..f8da387a126e 100644---- a/kernel/fork.c-+++ b/kernel/fork.c-@@ -1402,7 +1402,8 @@ static bool may_access_mm(struct mm_struct *mm, struct task_struct *task, unsign- return true;- if (ptrace_may_access(task, mode))- return true;-- if ((mode & PTRACE_MODE_READ) && perfmon_capable())-+ if ((mode & PTRACE_MODE_READ) && perfmon_capable() &&-+ !security_mm_read_access(task, mode))- return true;- return false;- }-diff --git a/security/security.c b/security/security.c-index 86636c894ebe..45869f746bcb 100644---- a/security/security.c-+++ b/security/security.c-@@ -609,6 +609,23 @@ int security_ptrace_traceme(struct task_struct *parent)- return call_int_hook(ptrace_traceme, parent);- }--+/**-+ * security_mm_read_access() - Check a read-only access granted by CAP_PERFMON-+ * @task: task whose memory is accessed-+ * @mode: PTRACE_MODE flags of the access, read mode-+ *-+ * mm_access() grants a read-only access to the memory of @task to a caller-+ * with CAP_PERFMON even when ptrace_may_access(), and so the-+ * ptrace_access_check hook, refused it. Check that access before it is-+ * granted that way.-+ *-+ * Return: Returns 0 if permission is granted.-+ */-+int security_mm_read_access(struct task_struct *task, unsigned int mode)-+{-+ return call_int_hook(mm_read_access, task, mode);-+}-+- /**- * security_capget() - Get the capability sets for a process- * @target: target process----2.43.0-diff --git a/testing/Makefile b/testing/Makefileindex 49b2f409..f68bb54a 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -1,7 +1,7 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# Test, VM and kernel targets. make -C testing runs every test, make -C+# Test and VM targets. make -C testing runs every test, make -C# testing <tier>[/<name>] one tier or part of it; make -C testing help# lists the rest.@@ -29,12 +29,9 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \.DEFAULT_GOAL := all.PHONY: all help clean unit ci-checks functional end2end build-operator build-unit \test-helpers \- fuzz afl bundle test-vm-bundle kernel bpf-next vm vm-console vm-ssh vm-stop vm-clean \+ fuzz afl bundle test-vm-bundle require-vm-kernel vm vm-console vm-ssh vm-stop vm-clean \vm-operator-end2end-KERNEL_PATCHES ?= $(if $(wildcard $(ROOT)/kernel/*.patch),$(ROOT)/kernel/,)-override KERNEL_PATCHES := $(if $(strip $(KERNEL_PATCHES)),$(call root-path,$(KERNEL_PATCHES)),)-KERNEL_PATCH_FILES := $(foreach patch,$(KERNEL_PATCHES),$(if $(wildcard $(patch)/*.patch),$(wildcard $(patch)/*.patch),$(wildcard $(patch))))PACKAGE_FORMAT ?= $(call test-vm-arch,TEST_VM_HOST_PKG_FORMAT)TEST_VM_MODE ?= verity@@ -66,9 +63,7 @@ TEST_VM_MEMORY ?= 4GTEST_VM_DISK_SIZE ?= 30GTEST_VM_UBUNTU_CODENAME ?= resoluteTEST_VM_VERBOSE ?= 0-# `make -C testing vm` keeps bpf-next as its default, but can boot a kernel-# built from an upstream release tag, Linux v7.4 or newer being what a-# target runs.+# Test VMs use kernel artifacts built by github.com/shirudo-dev/kernel.VM_KERNEL ?= $(if $(strip $(KERNEL)),$(KERNEL),bpf-next)VM_KERNEL_VERSION := $(patsubst v%,%,$(VM_KERNEL))VM_KERNEL_MIN := 7.4@@ -97,29 +92,6 @@ override TEST_VM_BUNDLE_DIR := $(call root-path,$(TEST_VM_BUNDLE_DIR))VM_KERNEL_IMAGE_NAME := $(call test-vm-arch,TEST_VM_ARCH_KIMAGE)VM_KERNEL_IMAGE := $(VM_KERNEL_ARTIFACT_DIR)/$(VM_KERNEL_IMAGE_NAME)VM_KERNEL_STAMP := $(VM_KERNEL_ARTIFACT_DIR)/$(VM_KERNEL_IMAGE_NAME).sha256sum-VM_KERNEL_DEP := $(VM_KERNEL_STAMP)--KERNEL_TAG ?= $(if $(strip $(TAG)),$(TAG),bpf-next)-KERNEL_TAG_VERSION := $(patsubst v%,%,$(KERNEL_TAG))-KERNEL_REPOSITORY ?= https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git-KERNEL_SOURCE_DIR ?=-override KERNEL_SOURCE_DIR := $(if $(strip $(KERNEL_SOURCE_DIR)),$(call root-path,$(KERNEL_SOURCE_DIR)),)-KERNEL_CONFIG ?=-override KERNEL_CONFIG := $(if $(strip $(KERNEL_CONFIG)),$(call root-path,$(KERNEL_CONFIG)),)-KERNEL_BUILD_JOBS ?= $(shell nproc)-ifeq ($(KERNEL_TAG),bpf-next)-ifneq ($(filter kernel bpf-next,$(MAKECMDGOALS)),)-ifneq ($(strip $(KERNEL_COMMIT)),)- $(error KERNEL_COMMIT is supported only for release kernel tags)-endif-endif- KERNEL_TAG_NORMALIZED := bpf-next- KERNEL_BUILD_ARTIFACT_DIR := $(ROOT)/artifacts/bpf-next-kernel-debs-else- KERNEL_TAG_NORMALIZED := v$(KERNEL_TAG_VERSION)- KERNEL_BUILD_ARTIFACT_DIR := $(ROOT)/artifacts/linux-$(KERNEL_TAG_NORMALIZED)$(KERNEL_COMMIT_SUFFIX)-kernel-debs-endif-KERNEL_BUILD_STAMP := $(KERNEL_BUILD_ARTIFACT_DIR)/$(VM_KERNEL_IMAGE_NAME).sha256sumTEST_VM_BUNDLE_STAMP := $(TEST_VM_BUNDLE_DIR)/.stampTEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \@@ -150,8 +122,9 @@ TEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \# The host's util/version_id.c is no input: every build of the host's# writes it, and the bundle's build writes its own.TEST_VM_BUNDLE_SOURCES := $(filter-out $(ROOT)/util/version_id.c,$(TEST_VM_BUNDLE_SOURCES))-# The kernel build replaces versioned package files; depend on its stable stamp.-TEST_VM_BUNDLE_ARTIFACTS := $(VM_KERNEL_STAMP)+# The external kernel build replaces versioned package files. Track its stamp+# when present so a new artifact invalidates the bundle.+TEST_VM_BUNDLE_ARTIFACTS := $(wildcard $(VM_KERNEL_STAMP))# The bundle builds in the build container unless BUILD_CONTAINER=0, so it# depends on the image's inputs rather than on the host's configuration.BUILD_CONTAINER ?= 1@@ -177,7 +150,7 @@ TEST_VM_BUNDLE_INPUTS := $(sort \$(ROOT)/config.mk: $(ROOT)/Makefile.config+$(Q)$(MAKE) -C $(ROOT) config-test-vm-bundle: $(VM_KERNEL_DEP) $(TEST_VM_BUNDLE_STAMP)+test-vm-bundle: require-vm-kernel $(TEST_VM_BUNDLE_STAMP)$(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)$(Q)mkdir -p $(dir $(BUILD_LOCK))@@ -196,39 +169,18 @@ $(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)BPF_VMLINUX_BTF="$(abspath $(VM_KERNEL_ARTIFACT_DIR)/vmlinux.btf)" \flock $(BUILD_LOCK) $(ROOT)/testing/vm/build-bundle.sh-kernel: $(KERNEL_BUILD_STAMP)--bpf-next:- $(Q)PACKAGE_FORMAT='$(PACKAGE_FORMAT)' \- KERNEL_PATCHES='$(KERNEL_PATCHES)' \- KERNEL_CONFIG='$(KERNEL_CONFIG)' \- KERNEL_BUILD_JOBS='$(KERNEL_BUILD_JOBS)' \- $(ROOT)/testing/vm/build-kernel.sh--$(KERNEL_BUILD_STAMP): $(ROOT)/testing/vm/build-kernel.sh $(KERNEL_PATCH_FILES)- $(Q)KERNEL_TAG='$(KERNEL_TAG_NORMALIZED)' \- KERNEL_COMMIT='$(KERNEL_COMMIT)' \- KERNEL_PATCHES='$(KERNEL_PATCHES)' \- KERNEL_REPOSITORY='$(KERNEL_REPOSITORY)' \- KERNEL_SOURCE_DIR='$(KERNEL_SOURCE_DIR)' \- KERNEL_CONFIG='$(KERNEL_CONFIG)' \- PACKAGE_FORMAT='$(PACKAGE_FORMAT)' \- KERNEL_BUILD_JOBS='$(KERNEL_BUILD_JOBS)' \- OUTPUT_DIR="$(abspath $(KERNEL_BUILD_ARTIFACT_DIR))" \- $(ROOT)/testing/vm/build-kernel.sh--# A VM selection owns its kernel artifact independently of the generic-# KERNEL_TAG selection used by `make -C testing kernel`.-ifneq ($(VM_KERNEL_DEP),)-ifneq ($(VM_KERNEL_TAG),$(KERNEL_TAG_NORMALIZED))-$(VM_KERNEL_STAMP):- +$(Q)$(MAKE) -C $(ROOT) -f testing/Makefile kernel KERNEL_TAG='$(VM_KERNEL_TAG)' KERNEL_COMMIT='$(KERNEL_COMMIT)' KERNEL_CONFIG='$(KERNEL_CONFIG)'-endif-endif+require-vm-kernel:+ $(Q)test -s "$(VM_KERNEL_IMAGE)" -a -s "$(VM_KERNEL_STAMP)" -a \+ -s "$(VM_KERNEL_ARTIFACT_DIR)/vmlinux.btf" -a \+ -s "$(VM_KERNEL_ARTIFACT_DIR)/kernel.config" -a \+ -d "$(VM_KERNEL_ARTIFACT_DIR)/lib/modules" || { \+ echo "kernel artifact is missing; use github.com/shirudo-dev/kernel packages in $(VM_KERNEL_ARTIFACT_DIR)" >&2; \+ exit 1; \+ }LOCAL_STACK ?= 1-vm: $(VM_KERNEL_DEP) test-vm-bundle+vm: require-vm-kernel test-vm-bundle$(Q)VM_MODE=interactive VM_NAME="$(VM_NAME)" VM_TENANT="$(VM_TENANT)" \TEST_VM_KERNEL="$(abspath $(VM_KERNEL_IMAGE))" \TEST_VM_KERNEL_ARTIFACT_DIR="$(abspath $(VM_KERNEL_ARTIFACT_DIR))" \@@ -369,7 +321,7 @@ vm-node-end2end:vm-test-tpm: vm-test-register$(addprefix vm-test-,register $(filter-out end2end,$(VM_SUITES))): \- vm-test-%: $(VM_KERNEL_DEP) test-vm-bundle+ vm-test-%: require-vm-kernel test-vm-bundle$(Q)$(call run-target-vm,$*,$(if $(VM_NAME),$(VM_NAME)-$*),$(if $(filter register,$*),0,1))vm-stop:@@ -442,9 +394,8 @@ help:' make -C testing fuzz [FUZZ_SECONDS=60] [FUZZ_CORPUS=<dir>] [FUZZERS=<target>...]' \' make -C testing afl [AFL_SECONDS=600] [FUZZ_CORPUS=<dir>] [FUZZERS=<target>...]' \' make -C testing vm, vm-console, vm-ssh, vm-stop, or vm-clean' \- ' make -C testing vm KERNEL=7.4' \- ' make -C testing kernel KERNEL_TAG=v7.4' \- ' make -C testing bpf-next, bundle or test-helpers' \+ ' VM_KERNEL=bpf-next (default) selects the shirudo-dev/kernel artifact' \+ ' make -C testing bundle or test-helpers' \' make -C testing stack-up, oci, telemetry or stack-down' \' make -C testing clean'diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.shindex bd4e0807..098c42de 100755--- a/testing/functional/build/t1007-test-vm-cli.sh+++ b/testing/functional/build/t1007-test-vm-cli.sh@@ -472,8 +472,7 @@ test_expect_success 'test-vm imports the host-built payload' 'grep -Fq "LIBBPF_VENDOR := vendor/libbpf" ../Makefile.shirudo &&grep -Fq "\$(LIBBPF_A)" ../Makefile.shirudo &&grep -Fq "VMLINUX_GEN := tools/gen-vmlinux-h/gen-vmlinux-h" \- ../Makefile.shirudo &&- ! grep -q "shirudo-bpf-deps" vm/build-kernel.sh+ ../Makefile.shirudo'test_expect_success 'test-vm bundle stamp controls incremental rebuilds' 'grep -q "TEST_VM_BUNDLE_STAMP" ../testing/Makefile &&@@ -629,132 +628,11 @@ test_expect_success 'an operator VM serves without a TPM and alone gets the key'grep -q "the operator VM has a TPM" vm/guest.sh &&grep -q "bindeb-pkg PKG_ROLES=operator" vm/guest.sh'-test_expect_success 'make -C testing vm boots a release kernel at or above the floor' '- grep -q "VM_KERNEL_MIN := 7.4" ../testing/Makefile &&- grep -q "make -C testing vm KERNEL=7.4" ../testing/Makefile &&- grep -Fq "VM_KERNEL_ARTIFACT_DIR := \$(ROOT)/artifacts/linux-\$(VM_KERNEL_TAG)\$(KERNEL_COMMIT_SUFFIX)-kernel-debs" ../testing/Makefile &&- grep -q "TEST_VM_KERNEL=\"\$(abspath \$(VM_KERNEL_IMAGE))\"" ../testing/Makefile &&- make -n -C .. -f testing/Makefile vm KERNEL=7.4 TEST_VM_ARCH=x86_64 \- TEST_VM_WORK_DIR="$WORK/release-vm" \- >"$WORK/release-vm-make.out" 2>&1 &&- grep -q "artifacts/linux-v7.4-kernel-debs/bzImage" \- "$WORK/release-vm-make.out" &&- make -n -C .. -f testing/Makefile vm KERNEL=7.10 TEST_VM_ARCH=x86_64 \- TEST_VM_WORK_DIR="$WORK/newer-vm" \- >"$WORK/newer-vm-make.out" 2>&1 &&- grep -q "artifacts/linux-v7.10-kernel-debs/bzImage" \- "$WORK/newer-vm-make.out" &&- ! make -n -C .. -f testing/Makefile vm KERNEL=6.18 TEST_VM_ARCH=x86_64 \- TEST_VM_WORK_DIR="$WORK/old-vm" \- >"$WORK/old-vm-make.out" 2>&1 &&- grep -q "requires Linux v7.4 or newer" "$WORK/old-vm-make.out"-'--test_expect_success 'the VM kernel image is named for the host architecture' '- for spec in x86_64:bzImage amd64:bzImage aarch64:Image arm64:Image \- riscv64:bzImage- do- arch=${spec%%:*} image=${spec#*:} &&- make -n -C .. -f testing/Makefile vm KERNEL=7.4 \- TEST_VM_ARCH=$arch TEST_VM_WORK_DIR="$WORK/arch-$arch" \- >"$WORK/arch-$arch.out" 2>&1 &&- grep -q "artifacts/linux-v7.4-kernel-debs/$image" \- "$WORK/arch-$arch.out" || return 1- done-'--test_expect_success 'the VM kernel is not built on an unsupported architecture' '- ! TEST_VM_ARCH=riscv64 vm/build-kernel.sh \- >"$WORK/riscv64-kernel.out" 2>&1 &&- grep -q "x86_64 and aarch64 hosts only, not riscv64" \- "$WORK/riscv64-kernel.out"-'--test_expect_success 'the kernel builder requires the NV writer parser and RSA support' '- for symbol in PKCS8_PRIVATE_KEY_PARSER CRYPTO_RSA; do- grep -qx "CONFIG_$symbol=y" vm/build-kernel.sh &&- grep -qx "require_config CONFIG_$symbol y" vm/build-kernel.sh ||- exit 1- done-'--test_expect_success 'all kernel and VM builds use the slim profile' '- ! grep -Eq "^(kernel-small|vm-small|test-vm-small-bundle):" ../testing/Makefile &&- ! grep -q "KERNEL_PROFILE" ../testing/Makefile vm/build-kernel.sh &&- grep -q "kernel-slim.config" vm/build-kernel.sh &&- grep -q "config_profile=slim" vm/build-kernel.sh &&- grep -q "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" vm/build-kernel.sh &&- grep -q "make -C testing vm KERNEL=7.4" ../testing/Makefile &&- make -n -C .. -f testing/Makefile vm VM_NAME=slim-cli-vm \- TEST_VM_ARCH=x86_64 TEST_VM_WORK_DIR="$WORK/slim-vm" \- >"$WORK/slim-vm-make.out" 2>&1 &&- grep -q "artifacts/bpf-next-kernel-debs/bzImage" \- "$WORK/slim-vm-make.out" &&- grep -q "BPF_VMLINUX_BTF=.*artifacts/bpf-next-kernel-debs/vmlinux.btf" \- "$WORK/slim-vm-make.out"-'--test_expect_success 'VM reports guest and host memory usage' '- grep -q "report_boot_memory" vm/guest.sh &&- grep -q "guest_mem_total_kb" vm/guest.sh &&- grep -q "guest_mem_available_kb" vm/guest.sh &&- grep -q "guest_mem_used_percent" vm/guest.sh &&- grep -q "capture_host_memory_report" vm/run.sh &&- grep -q "qemu_vmrss_kb" vm/run.sh &&- grep -q "qemu_pss_kb" vm/run.sh &&- grep -q "print_memory_summary" vm/run.sh-'--test_expect_success 'make -C testing kernel builds a tagged third-party Linux source' '- grep -q "^kernel: \$(KERNEL_BUILD_STAMP)" ../testing/Makefile &&- grep -q "KERNEL_TAG=\"\${KERNEL_TAG:-bpf-next}\"" \- vm/build-kernel.sh &&- grep -q "KERNEL_REPOSITORY=\"\${KERNEL_REPOSITORY:-https://git.kernel.org" \- vm/build-kernel.sh &&- grep -q "git clone --depth 1 --branch" vm/build-kernel.sh &&- grep -q "make -C testing kernel KERNEL_TAG=v7.4" ../testing/Makefile &&- ! KERNEL_TAG=not-a-kernel-tag vm/build-kernel.sh \- >"$WORK/invalid-kernel-tag.out" 2>&1 &&- grep -q "KERNEL_TAG must be bpf-next or a Linux release tag" \- "$WORK/invalid-kernel-tag.out" &&- ! KERNEL_TAG=v6.18 vm/build-kernel.sh \- >"$WORK/old-kernel-tag.out" 2>&1 &&- grep -q "requires Linux v7.4 or newer" "$WORK/old-kernel-tag.out"-'-test_expect_success 'make -C testing vm and kernel select an exact release commit' '- make -n -C .. -f testing/Makefile vm KERNEL=7.4 KERNEL_COMMIT=abcdef1234567 \- TEST_VM_ARCH=x86_64 TEST_VM_WORK_DIR="$WORK/commit-vm" \- >"$WORK/commit-vm-make.out" 2>&1 &&- grep -q "artifacts/linux-v7.4-abcdef1234567-kernel-debs/bzImage" \- "$WORK/commit-vm-make.out" &&- grep -q "KERNEL_COMMIT=" "$WORK/commit-vm-make.out" &&- grep -q "KERNEL_COMMIT is supported only for release VM kernels" ../testing/Makefile &&- ! make -n -C .. -f testing/Makefile vm KERNEL=bpf-next KERNEL_COMMIT=abcdef1234567 \- >"$WORK/commit-bpf-next.out" 2>&1 &&- grep -q "KERNEL_COMMIT is supported only for release VM kernels" \- "$WORK/commit-bpf-next.out" &&- ! KERNEL_TAG=v7.4 KERNEL_COMMIT=not-a-sha \- vm/build-kernel.sh >"$WORK/invalid-kernel-commit.out" 2>&1 &&- grep -q "KERNEL_COMMIT must contain 7 to 40 hexadecimal characters" \- "$WORK/invalid-kernel-commit.out"-'-test_expect_success 'kernel VM artifacts provide networking modules' '- grep -q "CONFIG_VETH=m" vm/build-kernel.sh &&- grep -q "CONFIG_BRIDGE=m" vm/build-kernel.sh &&- grep -q "CONFIG_VLAN_8021Q=m" vm/build-kernel.sh &&- grep -q "CONFIG_NF_FLOW_TABLE=m" vm/build-kernel.sh &&- grep -q "CONFIG_NF_FLOW_TABLE_INET=m" vm/build-kernel.sh &&- grep -q "CONFIG_NF_FLOW_TABLE_PROCFS=y" vm/build-kernel.sh &&- grep -q "CONFIG_PROC_FS=y" vm/build-kernel.sh &&- grep -q "require_config CONFIG_VETH m" vm/build-kernel.sh &&- grep -q "dpkg-deb -x" vm/build-kernel.sh &&- grep -q "depmod -b" vm/build-kernel.sh &&- grep -q "TEST_VM_KERNEL_ARTIFACT_DIR" ../testing/Makefile &&- grep -q "mount_tag=shirudo-kernel" vm/run.sh &&- grep -q "TEST_VM_KERNEL_MODULES" vm/run.sh &&- grep -q "install_kernel_modules" vm/guest.sh &&- grep -q "modprobe \"\$module\"" vm/guest.sh &&- grep -q "nf_flow_table_procfs" vm/guest.sh+test_expect_success 'test VMs require a kernel project artifact' '+ grep -q "github.com/shirudo-dev/kernel" ../testing/Makefile &&+ grep -q "^require-vm-kernel:" ../testing/Makefile &&+ ! grep -q "build-kernel.sh\|KERNEL_CONFIG\|KERNEL_PATCHES" ../testing/Makefile &&+ grep -q "KERNEL_CI_ARTIFACT_DIR" ../.github/scripts/tests.sh'test_expect_success 'prepared VM runtime includes ripgrep' 'grep -qx "ripgrep" vm/runtime-packages &&diff --git a/testing/functional/build/t1008-kernel-ami-config.sh b/testing/functional/build/t1008-kernel-ami-config.shdeleted file mode 100644index 239cbd94..00000000--- a/testing/functional/build/t1008-kernel-ami-config.sh+++ /dev/null@@ -1,38 +0,0 @@-#!/bin/sh-# SPDX-License-Identifier: BSD-2-Clause-# Copyright (c) 2026 Authors of shirudo--cd "$(dirname "$0")/../.."-. ./test-lib.sh--BUILDER=vm/build-kernel.sh--check_builtin_options() {- for symbol in "$@"; do- grep -qx "${symbol}=y" "$BUILDER" &&- grep -Eq "^[[:space:]]*require_config ${symbol} y$" \- "$BUILDER" || return 1- done-}--test_expect_success 'slim kernel enables and validates NitroTPM CRB' '- check_builtin_options CONFIG_TCG_CRB-'--test_expect_success 'slim kernel enables and validates EC2 network and storage' '- check_builtin_options CONFIG_NET_VENDOR_AMAZON CONFIG_ENA_ETHERNET \- CONFIG_BLK_DEV_NVME-'--test_expect_success 'slim kernel enables and validates EFI and initramfs boot' '- check_builtin_options CONFIG_EFI CONFIG_EFI_STUB \- CONFIG_BLK_DEV_INITRD CONFIG_RD_GZIP CONFIG_RD_XZ CONFIG_RD_ZSTD-'--test_expect_success 'slim kernel enables and validates snap-packaged SSM support' '- check_builtin_options CONFIG_BLK_DEV_LOOP CONFIG_MISC_FILESYSTEMS \- CONFIG_SQUASHFS CONFIG_SQUASHFS_ZLIB CONFIG_SQUASHFS_XZ \- CONFIG_SQUASHFS_ZSTD-'--test_donediff --git a/testing/vm/build-kernel.sh b/testing/vm/build-kernel.shdeleted file mode 100755index b8e4364d..00000000--- a/testing/vm/build-kernel.sh+++ /dev/null@@ -1,811 +0,0 @@-#!/usr/bin/env bash-# SPDX-License-Identifier: BSD-2-Clause-# Copyright (c) 2026 Authors of shirudo-set -euo pipefail--KERNEL_TAG="${KERNEL_TAG:-bpf-next}"-KERNEL_COMMIT="${KERNEL_COMMIT:-}"-KERNEL_REPOSITORY="${KERNEL_REPOSITORY:-https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git}"-KERNEL_PATCHES="${KERNEL_PATCHES:-}"-KERNEL_CONFIG="${KERNEL_CONFIG:-}"-KERNEL_BUILD_JOBS="${KERNEL_BUILD_JOBS:-$(nproc)}"-REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"-# shellcheck source=testing/vm/arch.sh-. "${REPO_ROOT}/testing/vm/arch.sh"-KERNEL_SOURCE_DIR_INPUT="${KERNEL_SOURCE_DIR:-}"-if [[ "$KERNEL_TAG" =~ ^[0-9]+\.[0-9]+([.][0-9]+)?$ ]]; then- KERNEL_TAG="v${KERNEL_TAG}"-fi-if [[ "$KERNEL_TAG" != "bpf-next" &&- ! "$KERNEL_TAG" =~ ^v[0-9]+\.[0-9]+([.][0-9]+)?$ ]]; then- echo "KERNEL_TAG must be bpf-next or a Linux release tag such as v7.4" >&2- exit 1-fi-KERNEL_MIN_VERSION="7.4"-if [[ "$KERNEL_TAG" != "bpf-next" ]]; then- oldest=$(printf '%s\n' "$KERNEL_MIN_VERSION" "${KERNEL_TAG#v}" | sort -V | head -n 1)- if [[ "$oldest" != "$KERNEL_MIN_VERSION" ]]; then- echo "shirudo requires Linux v${KERNEL_MIN_VERSION} or newer; ${KERNEL_TAG} is older" >&2- exit 1- fi-fi-if [[ -n "$KERNEL_COMMIT" ]]; then- if [[ "$KERNEL_TAG" == "bpf-next" ]]; then- echo "KERNEL_COMMIT is supported only for release kernel tags" >&2- exit 1- fi- if [[ ! "$KERNEL_COMMIT" =~ ^[0-9a-fA-F]{7,40}$ ]]; then- echo "KERNEL_COMMIT must contain 7 to 40 hexadecimal characters" >&2- exit 1- fi- KERNEL_COMMIT="${KERNEL_COMMIT,,}"-fi-# After the argument checks, so that those report the same on every host.-if [[ "$TEST_VM_ARCH_SUPPORTED" != 1 ]]; then- echo "the test VM kernel is built on x86_64 and aarch64 hosts only, not ${TEST_VM_ARCH}" >&2- exit 1-fi-KERNEL_ARTIFACT_NAME="bpf-next"-if [[ "$KERNEL_TAG" != "bpf-next" ]]; then- KERNEL_ARTIFACT_NAME="linux-${KERNEL_TAG}"-fi-if [[ -n "$KERNEL_COMMIT" ]]; then- KERNEL_ARTIFACT_NAME="${KERNEL_ARTIFACT_NAME}-${KERNEL_COMMIT}"-fi-if [[ -z "${KERNEL_LOCALVERSION:-}" ]]; then- if [[ "$KERNEL_TAG" == "bpf-next" ]]; then- KERNEL_LOCALVERSION="-bpf-next"- else- KERNEL_LOCALVERSION="-shirudo-${KERNEL_TAG#v}"- fi-fi-PACKAGE_FORMAT="${PACKAGE_FORMAT:-$TEST_VM_HOST_PKG_FORMAT}"-case "$PACKAGE_FORMAT" in- deb)- PACKAGE_SUFFIX="debs"- ;;- rpm)- PACKAGE_SUFFIX="rpms"- ;;- *)- echo "unsupported PACKAGE_FORMAT: ${PACKAGE_FORMAT} (expected deb or rpm)" >&2- exit 1- ;;-esac-WORK_DIR="${WORK_DIR:-${RUNNER_TEMP:-/tmp}/${KERNEL_ARTIFACT_NAME}-kernel-build}"-SOURCE_DIR="${WORK_DIR}/linux"-if [[ -n "$KERNEL_SOURCE_DIR_INPUT" ]]; then- KERNEL_SOURCE_DIR="$KERNEL_SOURCE_DIR_INPUT"-elif [[ "$KERNEL_TAG" == "bpf-next" ]]; then- # Reuse the managed shallow clone unless KERNEL_SOURCE_DIR names a checkout.- KERNEL_SOURCE_DIR="$SOURCE_DIR"-else- KERNEL_SOURCE_DIR="$SOURCE_DIR"-fi-OUTPUT_DIR="${OUTPUT_DIR:-${REPO_ROOT}/artifacts/${KERNEL_ARTIFACT_NAME}-kernel-${PACKAGE_SUFFIX}}"-BUNDLE_PATH="${BUNDLE_PATH:-${OUTPUT_DIR}.tar.gz}"-VMLINUX_PATH="${OUTPUT_DIR}/${TEST_VM_ARCH_KIMAGE}"-VMLINUX_BTF_PATH="${OUTPUT_DIR}/vmlinux.btf"--if [[ "$PACKAGE_FORMAT" == deb ]]; then- BUILD_DEPENDENCIES=(- bc- bison- build-essential- ca-certificates- cpio- debhelper- dpkg-dev- dwarves- fakeroot- flex- git- kmod- libdw-dev- libelf-dev- libncurses-dev- libssl-dev- openssl- pahole- python3- rsync- xz-utils- zstd- )-else- BUILD_DEPENDENCIES=(- bc- bison- ca-certificates- cpio- dwarves- elfutils-devel- elfutils-libelf-devel- flex- gcc- git- gzip- hostname- kmod- make- ncurses-devel- openssl- openssl-devel- perl- python3- rpm-build- rsync- tar- xz- zstd- )-fi--run_as_root() {- if [[ "$(id -u)" -eq 0 ]]; then- "$@"- elif command -v sudo >/dev/null 2>&1; then- sudo "$@"- else- echo "installing kernel build dependencies requires root or sudo" >&2- exit 1- fi-}--install_build_dependencies() {- local missing_dependencies=()- if [[ "$PACKAGE_FORMAT" == deb ]]; then- if ! command -v apt-get >/dev/null 2>&1; then- echo "cannot install Debian kernel build dependencies: apt-get is not installed" >&2- exit 1- fi- if command -v dpkg-query >/dev/null 2>&1; then- for dependency in "${BUILD_DEPENDENCIES[@]}"; do- if ! dpkg-query -W -f='${Status}\n' "$dependency" 2>/dev/null |- grep -q 'install ok installed'; then- missing_dependencies+=("$dependency")- fi- done- else- missing_dependencies=("${BUILD_DEPENDENCIES[@]}")- fi- if [[ ${#missing_dependencies[@]} -eq 0 ]]; then- echo "All kernel build dependencies are already installed"- return- fi- run_as_root apt-get update- run_as_root apt-get install -y --no-install-recommends "${missing_dependencies[@]}"- else- if ! command -v dnf >/dev/null 2>&1; then- echo "cannot install RPM kernel build dependencies: dnf is not installed" >&2- exit 1- fi- if command -v rpm >/dev/null 2>&1; then- for dependency in "${BUILD_DEPENDENCIES[@]}"; do- rpm -q "$dependency" >/dev/null 2>&1 ||- missing_dependencies+=("$dependency")- done- else- missing_dependencies=("${BUILD_DEPENDENCIES[@]}")- fi- if [[ ${#missing_dependencies[@]} -eq 0 ]]; then- echo "All kernel build dependencies are already installed"- return- fi- run_as_root dnf install -y "${missing_dependencies[@]}"- fi-}--install_build_dependencies--if [[ "$KERNEL_TAG" == "bpf-next" && "$KERNEL_SOURCE_DIR" == "$SOURCE_DIR" ]]; then- mkdir -p "$WORK_DIR"-else- rm -rf "$WORK_DIR"- mkdir -p "$WORK_DIR"-fi-rm -rf "$OUTPUT_DIR" "$BUNDLE_PATH" "${BUNDLE_PATH}.sha256sum"-mkdir -p "$WORK_DIR" "$OUTPUT_DIR"--if [[ "$KERNEL_TAG" == "bpf-next" && "$KERNEL_SOURCE_DIR" == "$SOURCE_DIR" ]]; then- repository="${BPF_NEXT_REPOSITORY:-https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git}"- if git -C "$KERNEL_SOURCE_DIR" rev-parse --is-inside-work-tree \- >/dev/null 2>&1; then- echo "Updating bpf-next"- git -C "$KERNEL_SOURCE_DIR" remote set-url origin "$repository"- git -C "$KERNEL_SOURCE_DIR" fetch --depth 1 origin HEAD- git -C "$KERNEL_SOURCE_DIR" reset --hard FETCH_HEAD- git -C "$KERNEL_SOURCE_DIR" clean -fdx- else- echo "Fetching bpf-next"- rm -rf "$KERNEL_SOURCE_DIR"- git clone --depth 1 --single-branch "$repository" "$KERNEL_SOURCE_DIR"- fi-elif [[ "$KERNEL_TAG" != "bpf-next" && -z "$KERNEL_SOURCE_DIR_INPUT" ]]; then- echo "Fetching third-party Linux kernel ${KERNEL_TAG}"- if [[ -n "$KERNEL_COMMIT" ]]; then- git clone --filter=blob:none --no-checkout \- "$KERNEL_REPOSITORY" "$KERNEL_SOURCE_DIR"- else- git clone --depth 1 --branch "$KERNEL_TAG" \- "$KERNEL_REPOSITORY" "$KERNEL_SOURCE_DIR"- fi-fi-if [[ ! -d "$KERNEL_SOURCE_DIR" ]]; then- echo "kernel source directory not found: ${KERNEL_SOURCE_DIR}" >&2- exit 1-fi-if ! git -C "$KERNEL_SOURCE_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then- echo "kernel source directory is not a git checkout: ${KERNEL_SOURCE_DIR}" >&2- exit 1-fi-# An exact-commit clone is intentionally created with --no-checkout. Select-# the requested commit before checking cleanliness; otherwise Git reports the-# intentionally absent worktree files as staged deletions.-if [[ -n "$KERNEL_COMMIT" && -z "$KERNEL_SOURCE_DIR_INPUT" ]]; then- git -C "$KERNEL_SOURCE_DIR" checkout --detach "$KERNEL_COMMIT"-fi-if [[ -n "$(git -C "$KERNEL_SOURCE_DIR" status --porcelain)" ]]; then- echo "kernel source checkout is dirty: ${KERNEL_SOURCE_DIR}" >&2- echo "commit or stash its changes before running make -C testing kernel" >&2- exit 1-fi--if [[ "$KERNEL_SOURCE_DIR" == "$SOURCE_DIR" ]]; then- cd "$SOURCE_DIR"-else- submodule_commit="$(git -C "$KERNEL_SOURCE_DIR" rev-parse HEAD)"- git clone --no-checkout "$KERNEL_SOURCE_DIR" "$SOURCE_DIR"- cd "$SOURCE_DIR"- if [[ -n "$KERNEL_COMMIT" ]]; then- git rev-parse --verify "$KERNEL_COMMIT^{commit}" >/dev/null 2>&1 || {- echo "KERNEL_COMMIT is not available in KERNEL_SOURCE_DIR: ${KERNEL_COMMIT}" >&2- exit 1- }- git checkout --detach "$KERNEL_COMMIT"- else- git checkout --detach "$submodule_commit"- fi-fi--if [[ -n "$KERNEL_COMMIT" ]]; then- git rev-parse --verify "$KERNEL_COMMIT^{commit}" >/dev/null 2>&1 || {- echo "kernel commit not found in ${KERNEL_REPOSITORY}: ${KERNEL_COMMIT}" >&2- exit 1- }- git checkout --detach "$KERNEL_COMMIT"-fi--upstream_commit="$(git rev-parse HEAD)"-applied_patches=()--apply_kernel_patch() {- local patch_path="$1"- local patch_subject-- if [[ "$patch_path" != /* ]]; then- patch_path="${REPO_ROOT}/${patch_path}"- fi- if [[ ! -f "$patch_path" ]]; then- echo "kernel patch not found: ${patch_path}" >&2- exit 1- fi-- echo "Applying kernel patch: ${patch_path}"- if git apply --reverse --check "$patch_path" >/dev/null 2>&1; then- echo "Kernel patch already applied: ${patch_path}"- applied_patches+=("$patch_path")- return- fi-- git config user.name "shirudo workflow"- git config user.email "shirudo@localhost"- if ! git apply --index "$patch_path"; then- echo "failed to apply kernel patch: ${patch_path}" >&2- exit 1- fi- patch_subject="$(- sed -n \- -e 's/^Subject: \[PATCH[^]]*\] //p' \- -e 's/^Subject: //p' \- "$patch_path" | head -n 1- )"- if [[ -z "$patch_subject" ]]; then- patch_subject="Apply $(basename "$patch_path")"- fi- git commit -m "$patch_subject"- applied_patches+=("$patch_path")-}--expand_kernel_patches() {- local patch_entry="$1"- local patch_path="$patch_entry"-- if [[ "$patch_path" != /* ]]; then- patch_path="${REPO_ROOT}/${patch_path}"- fi-- if [[ -d "$patch_path" ]]; then- find "$patch_path" -maxdepth 1 -type f -name '*.patch' | sort- else- printf '%s\n' "$patch_path"- fi-}--for patch_entry in $KERNEL_PATCHES; do- while IFS= read -r patch_path; do- [[ -n "$patch_path" ]] || continue- apply_kernel_patch "$patch_path"- done < <(expand_kernel_patches "$patch_entry")-done--kernel_commit="$(git rev-parse HEAD)"-if [[ -n "$KERNEL_CONFIG" ]]; then- if [[ "$KERNEL_CONFIG" != /* ]]; then- KERNEL_CONFIG="${REPO_ROOT}/${KERNEL_CONFIG}"- fi- if [[ ! -f "$KERNEL_CONFIG" ]]; then- echo "kernel config not found: ${KERNEL_CONFIG}" >&2- exit 1- fi- cp "$KERNEL_CONFIG" .config- config_source="$KERNEL_CONFIG"- config_profile=custom-else- config_fragment="${WORK_DIR}/kernel-slim.config"- cat > "$config_fragment" <<'EOF'-CONFIG_64BIT=y-CONFIG_SMP=y-CONFIG_BPF=y-CONFIG_BPF_SYSCALL=y-CONFIG_BPF_JIT=y-CONFIG_BPF_LSM=y-CONFIG_BPF_EVENTS=y-CONFIG_UPROBE_EVENTS=y-CONFIG_CGROUPS=y-CONFIG_CGROUP_BPF=y-CONFIG_FTRACE=y-CONFIG_FTRACE_SYSCALLS=y-CONFIG_FUNCTION_TRACER=y-CONFIG_DYNAMIC_FTRACE=y-CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y-CONFIG_FPROBE=y-CONFIG_UPROBES=y-CONFIG_SECCOMP=y-CONFIG_SECCOMP_FILTER=y-CONFIG_CROSS_MEMORY_ATTACH=y-CONFIG_DEBUG_INFO=y-CONFIG_DEBUG_KERNEL=y-CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y-CONFIG_DEBUG_INFO_BTF=y-CONFIG_DEBUG_INFO_BTF_MODULES=n-CONFIG_KEYS=y-CONFIG_ASYMMETRIC_KEY_TYPE=y-CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y-CONFIG_X509_CERTIFICATE_PARSER=y-CONFIG_PKCS8_PRIVATE_KEY_PARSER=y-CONFIG_PKCS7_MESSAGE_PARSER=y-CONFIG_SYSTEM_DATA_VERIFICATION=y-CONFIG_SYSTEM_TRUSTED_KEYS=""-CONFIG_SYSTEM_REVOCATION_KEYS=""-CONFIG_UTS_NS=y-CONFIG_MODULE_SIG=y-CONFIG_MODULE_SIG_ALL=y-CONFIG_CRYPTO_RSA=y-CONFIG_CRYPTO_SHA256=y-CONFIG_CRYPTO_MLDSA=y-CONFIG_CRYPTO_SHA512=y-CONFIG_TCG_TPM=y-CONFIG_TCG_TIS_CORE=y-CONFIG_TCG_TIS=y-CONFIG_TCG_CRB=y-CONFIG_SECCOMP=y-CONFIG_SECCOMP_FILTER=y-CONFIG_CROSS_MEMORY_ATTACH=y-CONFIG_SECURITY=y-CONFIG_SECURITY_NETWORK=y-CONFIG_SECURITYFS=y-CONFIG_LSM="bpf"-CONFIG_DEVTMPFS=y-CONFIG_DEVTMPFS_MOUNT=y-CONFIG_BINFMT_ELF=y-CONFIG_BINFMT_SCRIPT=y-CONFIG_INOTIFY_USER=y-CONFIG_MODULES=y-CONFIG_MODULE_UNLOAD=y-CONFIG_BLK_DEV=y-CONFIG_BLOCK=y-CONFIG_MD=y-CONFIG_BLK_DEV_DM=y-CONFIG_BLK_DEV_INITRD=y-CONFIG_RD_GZIP=y-CONFIG_RD_XZ=y-CONFIG_RD_ZSTD=y-CONFIG_BLK_DEV_LOOP=y-CONFIG_BLK_DEV_NVME=y-CONFIG_PARTITION_ADVANCED=y-CONFIG_EFI=y-CONFIG_EFI_STUB=y-CONFIG_EFI_PARTITION=y-CONFIG_FAT_FS=y-CONFIG_VFAT_FS=y-CONFIG_ISO9660_FS=y-CONFIG_NLS_CODEPAGE_437=y-CONFIG_NLS_ASCII=y-CONFIG_NLS_ISO8859_1=y-CONFIG_NLS_UTF8=y-CONFIG_NLS_DEFAULT="utf8"-CONFIG_VIRTIO_MENU=y-CONFIG_VIRTIO=y-CONFIG_VIRTIO_PCI=y-CONFIG_VIRTIO_PCI_LEGACY=y-CONFIG_VIRTIO_BLK=y-CONFIG_VIRTIO_NET=y-CONFIG_PCI=y-CONFIG_PCI_MSI=y-CONFIG_PCIEPORTBUS=y-CONFIG_NET=y-CONFIG_NET_NS=y-CONFIG_USER_NS=y-CONFIG_PACKET=y-CONFIG_NETDEVICES=y-CONFIG_NET_CORE=y-CONFIG_ETHERNET=y-CONFIG_NET_VENDOR_AMAZON=y-CONFIG_ENA_ETHERNET=y-CONFIG_INET=y-CONFIG_IPV6=y-CONFIG_UNIX=y-CONFIG_NETWORK_FILESYSTEMS=y-CONFIG_NET_9P=y-CONFIG_NET_9P_VIRTIO=y-CONFIG_9P_FS=y-CONFIG_OVERLAY_FS=y-CONFIG_KEXEC=y-CONFIG_KEXEC_FILE=y-CONFIG_MISC_FILESYSTEMS=y-CONFIG_SQUASHFS=y-CONFIG_SQUASHFS_ZLIB=y-CONFIG_SQUASHFS_XZ=y-CONFIG_SQUASHFS_ZSTD=y-CONFIG_EXT4_FS=y-CONFIG_EXT4_FS_SECURITY=y-CONFIG_MD=y-CONFIG_BLK_DEV_DM=y-CONFIG_DM_VERITY=y-CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y-CONFIG_TMPFS=y-CONFIG_TMPFS_XATTR=y-CONFIG_TTY=y-CONFIG_ACPI=y-CONFIG_PNP=y-CONFIG_PNPACPI=y-CONFIG_NETFILTER=y-CONFIG_NETFILTER_INGRESS=y-CONFIG_NF_CONNTRACK=y-CONFIG_NF_TABLES=m-CONFIG_VETH=m-CONFIG_BRIDGE=m-CONFIG_VLAN_8021Q=m-CONFIG_NF_FLOW_TABLE=m-CONFIG_NF_FLOW_TABLE_INET=m-CONFIG_NF_FLOW_TABLE_PROCFS=y-CONFIG_PROC_FS=y-CONFIG_CC_OPTIMIZE_FOR_SIZE=y-EOF- # QEMU's arm64 virt machine needs the generic PCI host bridge for virtio,- # PSCI to power off and the PL031 RTC, without which the guest clock- # starts in the past and rejects certificates made today. x86 selects- # PERF_EVENTS on its own; without it BPF_EVENTS and BPF_LSM drop out.- case "$TEST_VM_ARCH" in- x86_64)- cat >> "$config_fragment" <<'EOF'-CONFIG_X86_64=y-CONFIG_X86=y-CONFIG_PARAVIRT=y-CONFIG_PARAVIRT_CLOCK=y-CONFIG_KVM_GUEST=y-CONFIG_SERIAL_8250=y-CONFIG_SERIAL_8250_CONSOLE=y-CONFIG_KERNEL_XZ=y-CONFIG_KERNEL_GZIP=n-CONFIG_KERNEL_ZSTD=n-CONFIG_KERNEL_LZMA=n-CONFIG_KERNEL_LZO=n-CONFIG_KERNEL_LZ4=n-CONFIG_KERNEL_UNCOMPRESSED=n-EOF- ;;- aarch64)- cat >> "$config_fragment" <<'EOF'-CONFIG_ARM64=y-CONFIG_OF=y-CONFIG_PERF_EVENTS=y-CONFIG_ARM_PSCI_FW=y-CONFIG_PCI_HOST_GENERIC=y-CONFIG_VIRTIO_MMIO=y-CONFIG_SERIAL_AMBA_PL011=y-CONFIG_SERIAL_AMBA_PL011_CONSOLE=y-CONFIG_RTC_CLASS=y-CONFIG_RTC_HCTOSYS=y-CONFIG_RTC_DRV_PL031=y-EOF- ;;- esac- make KCONFIG_ALLCONFIG="$config_fragment" allnoconfig- config_source="embedded slim kernel config (KCONFIG_ALLCONFIG)"- config_profile=slim-fi--scripts/config --set-str LOCALVERSION "$KERNEL_LOCALVERSION"-make olddefconfig--require_config() {- local symbol="$1"- local expected_pattern="$2"-- if ! grep -Eq "^${symbol}=${expected_pattern}$" .config; then- echo "required kernel config ${symbol} does not match ${expected_pattern}" >&2- grep -E "^${symbol}=|^# ${symbol} is not set" .config >&2 || true- exit 1- fi-}--require_config CONFIG_BPF_LSM y-require_config CONFIG_BPF_SYSCALL y-require_config CONFIG_KEYS y-require_config CONFIG_BPF_JIT y-require_config CONFIG_CGROUP_BPF y-require_config CONFIG_FUNCTION_TRACER y-require_config CONFIG_DYNAMIC_FTRACE y-require_config CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS y-require_config CONFIG_FPROBE y-require_config CONFIG_DEBUG_INFO_BTF y-require_config CONFIG_TCG_TPM y-require_config CONFIG_TCG_TIS_CORE y-require_config CONFIG_TCG_TIS y-require_config CONFIG_SECCOMP y-require_config CONFIG_SECCOMP_FILTER y-require_config CONFIG_CROSS_MEMORY_ATTACH y-require_config CONFIG_SYSTEM_DATA_VERIFICATION y-# shirudo refuses unsigned modules once init runs, and the guest loads its-# networking modules after that.-require_config CONFIG_MODULE_SIG_ALL y-require_config CONFIG_PKCS8_PRIVATE_KEY_PARSER y-require_config CONFIG_CRYPTO_RSA y-require_config CONFIG_UPROBES y-require_config CONFIG_SECCOMP y-require_config CONFIG_SECCOMP_FILTER y-require_config CONFIG_CROSS_MEMORY_ATTACH y-require_config CONFIG_SECURITY y-require_config CONFIG_SECURITY_NETWORK y-require_config CONFIG_SECURITYFS y-require_config CONFIG_UTS_NS y-if [[ "$config_profile" == slim ]]; then- require_config CONFIG_USER_NS y- require_config CONFIG_TCG_CRB y- require_config CONFIG_BLK_DEV_INITRD y- require_config CONFIG_RD_GZIP y- require_config CONFIG_RD_XZ y- require_config CONFIG_RD_ZSTD y- require_config CONFIG_BLK_DEV_LOOP y- require_config CONFIG_BLK_DEV_NVME y- require_config CONFIG_EFI y- require_config CONFIG_EFI_STUB y- require_config CONFIG_NET_VENDOR_AMAZON y- require_config CONFIG_ENA_ETHERNET y- require_config CONFIG_MISC_FILESYSTEMS y- require_config CONFIG_SQUASHFS y- require_config CONFIG_SQUASHFS_ZLIB y- require_config CONFIG_SQUASHFS_XZ y- require_config CONFIG_SQUASHFS_ZSTD y-fi-require_config CONFIG_MODULES y-require_config CONFIG_MD y-require_config CONFIG_BLK_DEV_DM y-require_config CONFIG_DM_VERITY y-require_config CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG y-require_config CONFIG_BLK_DEV_LOOP y-require_config CONFIG_PCI y-require_config CONFIG_PCI_MSI y-require_config CONFIG_PCIEPORTBUS y-require_config CONFIG_NETDEVICES y-require_config CONFIG_ETHERNET y-require_config CONFIG_IPV6 y-require_config CONFIG_PACKET y-require_config CONFIG_ISO9660_FS y-require_config CONFIG_DEVTMPFS y-require_config CONFIG_DEVTMPFS_MOUNT y-require_config CONFIG_VIRTIO y-require_config CONFIG_VIRTIO_PCI y-require_config CONFIG_VIRTIO_BLK y-require_config CONFIG_VIRTIO_NET y-require_config CONFIG_NET_9P y-require_config CONFIG_NET_9P_VIRTIO y-require_config CONFIG_9P_FS y-require_config CONFIG_OVERLAY_FS y-require_config CONFIG_EXT4_FS y-require_config CONFIG_EXT4_FS_SECURITY y-require_config CONFIG_TMPFS y-require_config CONFIG_TMPFS_XATTR y-require_config CONFIG_EFI_PARTITION y-case "$TEST_VM_ARCH" in-x86_64)- require_config CONFIG_SERIAL_8250 y- require_config CONFIG_SERIAL_8250_CONSOLE y- ;;-aarch64)- require_config CONFIG_ARM64 y- require_config CONFIG_ARM_PSCI_FW y- require_config CONFIG_PCI_HOST_GENERIC y- require_config CONFIG_SERIAL_AMBA_PL011 y- require_config CONFIG_SERIAL_AMBA_PL011_CONSOLE y- require_config CONFIG_RTC_DRV_PL031 y- require_config CONFIG_RTC_HCTOSYS y- ;;-esac-require_config CONFIG_ACPI y-require_config CONFIG_PNP y-require_config CONFIG_PNPACPI y-require_config CONFIG_NETFILTER y-require_config CONFIG_NETFILTER_INGRESS y-require_config CONFIG_NET_NS y-require_config CONFIG_NF_CONNTRACK y-require_config CONFIG_NF_TABLES m-require_config CONFIG_VETH m-require_config CONFIG_BRIDGE m-require_config CONFIG_VLAN_8021Q m-require_config CONFIG_NF_FLOW_TABLE m-require_config CONFIG_NF_FLOW_TABLE_INET m-require_config CONFIG_NF_FLOW_TABLE_PROCFS y-require_config CONFIG_PROC_FS y-if [[ "$config_profile" == slim ]]; then- require_config CONFIG_CC_OPTIMIZE_FOR_SIZE y- if [[ "$TEST_VM_ARCH" == x86_64 ]]; then- require_config CONFIG_KERNEL_XZ y- fi-fi--# Refresh the generated release after the config edits above. kernelrelease-# reads include/config/kernel.release, which may still contain the pre-config-# value until its FORCE target has run; the Debian package uses the refreshed-# value when it stages /lib/modules.-make -s include/config/kernel.release-kernel_release="$(<include/config/kernel.release)"-package_version="1+$(date -u +%Y%m%d%H%M%S)+g${kernel_commit:0:12}"-# GCC 15 defaults to GNU C23, while older stable snapshots still use `bool`-# and `false` as identifiers. KCFLAGS covers normal Kbuild CFLAGS, but x86-# EFI and realmode Makefiles replace KBUILD_CFLAGS for their special builds.-# Put GNU11 on the compiler command itself so those paths receive it too.-# Older stable snapshots can also trigger discarded-qualifier warnings in the-# bundled host-side libbpf, so keep that compatibility warning in host tools.-kernel_cc="${CC:-cc} -std=gnu11"-kernel_hostcflags="${HOSTCFLAGS:-} -std=gnu11 -Wno-error=discarded-qualifiers"-kernel_kcflags="${KCFLAGS:-} -std=gnu11"-# GCC rejects -Wno-error= for a warning it does not know, so only add the-# GCC 15 one where the compiler has it.-if ${CC:-cc} -Werror -Wunterminated-string-initialization -x c -c /dev/null \- -o /dev/null >/dev/null 2>&1; then- kernel_kcflags="$kernel_kcflags -Wno-error=unterminated-string-initialization"-fi-if [[ "$PACKAGE_FORMAT" == deb ]]; then- make -j "$KERNEL_BUILD_JOBS" bindeb-pkg KDEB_PKGVERSION="$package_version" \- CC="$kernel_cc" \- HOSTCFLAGS="$kernel_hostcflags" \- KCFLAGS="$kernel_kcflags"-- IMAGE_DEB="$(find "$WORK_DIR" -maxdepth 1 -type f \- -name "linux-image-[0-9]*_${package_version}_*.deb" \- ! -name '*-dbg*.deb' -print -quit)"- if [[ -z "$IMAGE_DEB" ]]; then- echo "kernel image deb for package version ${package_version} was not produced" >&2- exit 1- fi- find "$WORK_DIR" -maxdepth 1 -type f \- -name "*_${package_version}_*.deb" ! -name '*-dbg*.deb' \- -exec cp {} "$OUTPUT_DIR/" \;-else- rm -rf "$SOURCE_DIR/rpmbuild/RPMS"- make -j "$KERNEL_BUILD_JOBS" binrpm-pkg-- IMAGE_RPM="$(find "$SOURCE_DIR/rpmbuild/RPMS" -type f \- -name 'kernel-[0-9]*.rpm' \- ! -name '*debug*' ! -name '*debuginfo*' \- ! -name '*headers*' ! -name '*devel*' -print -quit)"- if [[ -z "$IMAGE_RPM" ]]; then- echo "kernel RPM was not produced" >&2- exit 1- fi- find "$SOURCE_DIR/rpmbuild/RPMS" -type f -name '*.rpm' \- ! -name '*debug*' ! -name '*debuginfo*' -exec cp {} "$OUTPUT_DIR/" \;-fi--# The VM boots the kernel image directly, so carry the matching module tree-# alongside it. This keeps module loading deterministic for a selected-# kernel commit.-MODULES_STAGE_DIR="${WORK_DIR}/modules"-rm -rf "$MODULES_STAGE_DIR"-mkdir -p "$MODULES_STAGE_DIR"-if [[ "$PACKAGE_FORMAT" == deb ]]; then- dpkg-deb -x "$IMAGE_DEB" "$MODULES_STAGE_DIR"-else- rpm2cpio "$IMAGE_RPM" |- (cd "$MODULES_STAGE_DIR" && cpio -idm --quiet)-fi-MODULES_SOURCE_DIR=""-for candidate in \- "$MODULES_STAGE_DIR/lib/modules/$kernel_release" \- "$MODULES_STAGE_DIR/usr/lib/modules/$kernel_release"; do- if [[ -d "$candidate" ]]; then- MODULES_SOURCE_DIR="$candidate"- break- fi-done-if [[ -z "$MODULES_SOURCE_DIR" ]]; then- echo "kernel image package has no modules for ${kernel_release}" >&2- exit 1-else- mkdir -p "$OUTPUT_DIR/lib/modules"- rm -rf "$OUTPUT_DIR/lib/modules/$kernel_release"- cp -a "$MODULES_SOURCE_DIR" "$OUTPUT_DIR/lib/modules/"- depmod -b "$OUTPUT_DIR" "$kernel_release"-fi--if [[ ! -s "$TEST_VM_ARCH_KIMAGE_SRC" ]]; then- echo "kernel ${TEST_VM_ARCH_KIMAGE} was not produced" >&2- exit 1-fi-cp "$TEST_VM_ARCH_KIMAGE_SRC" "$VMLINUX_PATH"-cp .config "${OUTPUT_DIR}/kernel.config"--# Keep the exact detached BTF used by this kernel build. It lets shirudo-# generate vendor/linux/vmlinux.h against the artifact kernel before that kernel is-# booted, rather than accidentally using the build host's /sys BTF.-if [[ ! -s vmlinux ]]; then- echo "kernel vmlinux was not produced" >&2- exit 1-fi-if ! objcopy --dump-section .BTF="$VMLINUX_BTF_PATH" vmlinux; then- echo "failed to extract .BTF from kernel vmlinux" >&2- exit 1-fi-if [[ ! -s "$VMLINUX_BTF_PATH" ]]; then- echo "kernel vmlinux has no usable .BTF section" >&2- exit 1-fi--cat > "${OUTPUT_DIR}/${KERNEL_ARTIFACT_NAME}-kernel-build" <<EOF-source_dir=${KERNEL_SOURCE_DIR}-source_repository=${KERNEL_REPOSITORY}-tag=${KERNEL_TAG}-requested_commit=${KERNEL_COMMIT}-upstream_commit=${upstream_commit}-commit=${kernel_commit}-package_format=${PACKAGE_FORMAT}-patches_requested=${KERNEL_PATCHES}-patches_applied=${applied_patches[*]}-profile=${config_profile}-config_source=${config_source}-kernel_release=${kernel_release}-package_version=${package_version}-built_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)-EOF--(- cd "$OUTPUT_DIR"- sha256sum "$TEST_VM_ARCH_KIMAGE" > "${TEST_VM_ARCH_KIMAGE}.sha256sum"- sha256sum vmlinux.btf > vmlinux.btf.sha256sum- find . -type f ! -name SHA256SUMS -print0 | sort -z |- xargs -0 sha256sum > SHA256SUMS-)--mkdir -p "$(dirname "$BUNDLE_PATH")"-tar -C "$OUTPUT_DIR" -czf "$BUNDLE_PATH" .-(- cd "$(dirname "$BUNDLE_PATH")"- sha256sum "$(basename "$BUNDLE_PATH")" > "$(basename "$BUNDLE_PATH").sha256sum"-)--echo "Built ${KERNEL_TAG} kernel ${TEST_VM_ARCH_KIMAGE}: ${VMLINUX_PATH}"-echo "Built kernel BTF: ${VMLINUX_BTF_PATH}"-echo "Built kernel ${PACKAGE_FORMAT} bundle: ${BUNDLE_PATH}"diff --git a/testing/vm/run.sh b/testing/vm/run.shindex b3b47c98..e327c983 100755--- a/testing/vm/run.sh+++ b/testing/vm/run.sh@@ -466,7 +466,7 @@ validate_kernel_selection()die "kernel image not found: $KERNEL_OVERRIDE"else[[ -s "$DEFAULT_KERNEL" ]] ||- die "kernel image not found: $DEFAULT_KERNEL; run 'make -C testing bpf-next' first"+ die "kernel image not found: $DEFAULT_KERNEL; place a shirudo-dev/kernel build artifact there"fi}@@ -1382,12 +1382,12 @@ resolve_kernel()fi[[ -s "$DEFAULT_KERNEL" ]] ||- die "kernel image not found: $DEFAULT_KERNEL; run 'make -C testing bpf-next' first"+ die "kernel image not found: $DEFAULT_KERNEL; place a shirudo-dev/kernel build artifact there"if [[ -s "${DEFAULT_KERNEL}.sha256sum" ]]; then(cd "$(dirname "$DEFAULT_KERNEL")" &&sha256sum -c "${DEFAULT_KERNEL##*/}.sha256sum" >/dev/null)else- die "kernel checksum not found: ${DEFAULT_KERNEL}.sha256sum; run 'make -C testing bpf-next'"+ die "kernel checksum not found: ${DEFAULT_KERNEL}.sha256sum"fiprintf '%s\n' "$DEFAULT_KERNEL"}