Work from a checkout#
This page takes you from a clone of the repository to the operator binary, the operator-only helper and the static target binary, shows where the parts of the tree live and how to run the checks CI runs before you send a change. Run and write tests covers the tests and the test VM.
Before you begin#
A Linux host on x86-64, arm64 or riscv64. The test VM runs on x86-64 and arm64 hosts only.
A C compiler, GNU make,
pkg-config,python3, andclangandllvm23 with the BPF target, the release CI builds and tests with..github/scripts/install-clang.shinstalls them on Debian, Ubuntu and Fedora.The development files that
Makefile.configprobes for withpkg-config:Module
Debian or Ubuntu package
libcrypto >= 3.,5 libssl >= 3.5 libssl-from OpenSSL 3.5 or newerdev tss2-,esys >= 4. 0 tss2-tctildr libtss2-dev libelflibelf-dev zlibzlib1g-dev libcurl >= 7.75 libcurl4-openssl- dev luajitlibluajit-5. 1- dev The
opensslcommand from OpenSSL 3.5 or newer. The build probe runsopenssl list -public-key-algorithmsand refuses a version without ML-DSA.The BTF of a kernel that has the signed-loader ABI, see Select the kernel BTF.
The probe stops with shirudo: missing prerequisite: and an install
hint for each module it cannot find. It writes what it found to
config.mk, which make distclean removes.
Install OpenSSL 3.5#
The build probe’s hint names Ubuntu 26.04 and Fedora 43 as the first
releases that ship OpenSSL 3.5. Ubuntu 24.04 ships 3.0. On an older
distribution, build OpenSSL into a prefix of its own the way
.github/scripts/vm-toolchain.sh does for CI:
Download and unpack the release:
$ curl -fsSLO https://github.com/openssl/openssl/releases/download/openssl-3.5.9/openssl-3.5.9.tar.gz $ tar -xf openssl-3.5.9.tar.gz && cd openssl-3.5.9
Compare the archive with the SHA-256 that
vm-toolchain.shpins before you build it.Configure and install it under
<prefix>, a directory of your choice:$ ./Configure --prefix=<prefix> --openssldir=/etc/ssl --libdir=lib no-docs no-tests $ make -j"$(nproc)" && make install_sw
Put it first for every shell you build or test in:
$ export PATH=<prefix>/bin:$PATH $ export PKG_CONFIG_PATH=<prefix>/lib/pkgconfig $ export LD_LIBRARY_PATH=<prefix>/lib
Verify that the command knows ML-DSA:
$ openssl list -public-key-algorithms | grep -i ml-dsa
sudo drops LD_LIBRARY_PATH and replaces PATH. When you run
a make target as root, pass both on, as .github/scripts/tests.sh
does:
$ sudo -E env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" make tests
Select the kernel BTF#
The BPF objects that shirudo embeds compile against
vendor/linux/vmlinux.h. shirudo build run in the checkout root
uses the same header unless --vmlinux names another. The build
generates that header from BTF with tools/gen-vmlinux-h and never
commits it. The embedded
admission program reads the signature verdict the kernel records in
prog->aux->sig, so the header must come from a kernel with the
signed-loader ABI. A header generated from the BTF of a kernel without
that ABI fails the BPF build.
The build takes the first of these sources:
Source |
When |
|---|---|
|
Copies a prepared |
|
Generates the header from a BTF file or an ELF file with a
|
|
The BTF staged from the pinned CI kernel artifact. |
|
The running kernel. |
vendor/linux/.vmlinux-btf-source records the source used. When you
select another one, the next build regenerates the header.
Name the BTF of the kernel you build for:
$ make BPF_VMLINUX_BTF=<path-to-btf>
Verify which source the header came from:
$ cat vendor/linux/.vmlinux-btf-source
Build the operator binary#
Build
shirudoin the checkout root:$ make
Verify the build:
$ ./shirudo version
The build compiles the vendored libbpf, generates vmlinux.h,
compiles the userspace objects and the BPF objects under bpf/,
embeds the BPF objects into util/loader.o and links. These make
variables change it:
Variable |
Effect |
|---|---|
|
Prints the full command lines. |
|
Lets a compiler newer than the tree finish the build. A warning fails every build by default, the BPF objects and the vendored libbpf included. Fix the warning instead of keeping this set. |
|
Compiles the userspace objects with clang rather than |
|
Leaves out |
|
Instruments the host binaries and the test helpers with ASan and UBSan. See Run and write tests. |
|
Instruments them with TSan. See Run and write tests. |
|
Instruments them with MSan, the vendored libbpf included, and
wants the instrumented libraries
|
Build the shirudo-build helper#
The core binary never compiles or signs. shirudo build, shirudo
image build, shirudo image verify, shirudo keys vouch and the
operator bpm subcommands (build, push, tree append,
tree show and config update) execute the separate shirudo-build helper, which
is the only binary that links the signer.
Build the helper:
$ make shirudo-build
Point the core binary at it:
$ export SHIRUDO_BUILD=$PWD/tools/shirudo-build/shirudo-build $ export PATH=$PWD:$PATH
Verify that the operator subcommands resolve.
shirudo bpm --helplistsbuildandpushonly when the helper resolves:$ shirudo bpm --help
The core binary takes the helper from SHIRUDO_BUILD, then from
$(libexecdir)/shirudo/shirudo-build, the path compiled in, then
from PATH. Set SHIRUDO_BUILD rather than relying on PATH:
an operator package installed on the same host provides the compiled-in
path, which takes precedence over PATH.
bpm build compiles with the package directory as its working
directory. To build a package with a checkout’s vmlinux.h and BPF
headers, give the package directory vendor and bpf symbolic
links to the checkout’s, as t7005 does. An installed operator package
needs neither: shirudo-build falls back to the headers and
vmlinux.h it installs, as the operator VM of the end-to-end test
builds kernel-obs.
Build the target binary#
The target binary is a fully static PIE. It links static archives of
OpenSSL, libcurl and tpm2-tss that make target-deps builds from
source, and the distribution’s static libelf, zlib, zstd
and LuaJIT archives.
Install the static archives and the tools the tpm2-tss build needs. CI installs
autoconf,autoconf-archive,automake,libtool,libltdl-devandlibzstd-devfor this on Ubuntu.Build the dependencies and the binary:
$ make target
make targetrunsmake target-depsfirst. It builds OpenSSL 3.5.9, libcurl 8.18.0 and tpm2-tss 4.2.0 underbuild/target-depsand stages every archive inbuild/target-deps/lib.Verify that the result is a static PIE without an interpreter, shared dependencies or library search paths:
$ sh .github/scripts/check-static-target.sh shirudo-target
To use dependencies built elsewhere, set TARGET_DEPS_PREBUILT=1 and
point SHIRUDO_TARGET_PKG_CONFIG_PATH and
SHIRUDO_TARGET_STATIC_LIBDIR at them. make target-deps-clean
removes build/target-deps.
Refresh the vendored libbpf#
vendor/libbpf holds libbpf, its BPF-side headers and the BPF UAPI
headers. No kernel tree is needed to build. Refresh the copy only when
a change needs a newer libbpf or UAPI:
$ make bpf-deps KERNEL_SRC=<kernel-tree>
<kernel-tree> is a kernel checkout. Without KERNEL_SRC,
tools/bpf-deps/bpf-deps.sh makes a shallow clone of bpf-next.
The source revision is recorded in vendor/libbpf/COMMIT. After
refreshing, reapply the local changes vendor/libbpf/README.md
lists.
Other make targets#
Command |
Result |
|---|---|
|
Installs the operator binary and the bash completion under
|
|
Installs the static target binary as |
|
Builds |
|
Installs the operator binary, the helper under
|
|
Override the install paths. The unit and dracut directories are
absolute by default and do not follow |
|
Build the distribution packages from |
|
Renders the documentation and serves it on
|
|
Index the C sources, untracked ones and the generated
|
|
Remove the build products, and with |
|
List the targets. |
Project layout#
Path |
Contents |
|---|---|
The command dispatch table. |
|
|
One file per top-level command: |
The userspace library both binaries link. |
|
The embedded BPF programs: |
|
The headers more than one BPF program includes: the LSM helpers
and verity device records of |
|
Integer types, string and number helpers, the |
|
The operator-only helper: compile, sign, unload directives,
image signing, |
|
|
|
|
|
The dracut module, the initrd generator and the installer. |
|
The |
|
The script that refreshes |
|
Builds every shield package under |
|
Vendored libbpf and BPF UAPI headers. |
|
|
The generated |
The upstream kernel pin, configuration, patches and build script used by CI. See Carried kernel patches. |
|
The shipped packages: |
|
Unit and timer templates for the target. |
|
The bash completion. Command names come from
|
|
The tar, deb and rpm packaging. |
|
Unit, functional, end-to-end and fuzz tests, the test VM and their helpers. See Run and write tests. |
|
|
This documentation. |
The CI workflows and the scripts they run. |
|
|
The entry points, the build graph, the prerequisite probes, the target dependency build and version discovery. |
|
Generated: build products, the test VM state and the test kernels. Not tracked. |
shirudo --list-cmds prints the top-level commands.
Run the CI checks locally#
CI runs these scripts from .github/scripts/. Each takes the
arguments of git rev-list, such as origin/main..HEAD, and checks
the commit at HEAD alone without them.
Script |
Checks |
|---|---|
|
A one-line subject, a body beyond the tags and the author’s
|
|
The kernel’s |
|
The SPDX tag of every tracked source, in the kernel’s form for its
type: |
|
An extern function of the userspace C that nothing calls: the
compiler reports an unused |
|
The binary, the shirudo-build helper and the quote checker built
under clang’s static analyzer with its default checkers, failing
on any finding: a NULL or uninitialized value used, memory leaked
or used after its free, a store never read and more. It installs
Debian testing’s packages and clang 23’s tools, so it runs in a
throwaway container; on a host that has them,
|
|
|
|
Every semantic patch in |
|
Builds every commit on its own: |
|
Installs clang and LLVM 23, from the distribution, Debian unstable
or apt.llvm.org, and points |
|
Installs Debian testing’s compiler and libraries and clang 23
from unstable, builds the
binary and the helper with the BTF given, and runs the unit tests
and |
|
That a target binary is a static PIE. |
|
That each operator binary links no shared library but |
|
That a runtime image of the default size of
|
|
Prepares a CI runner as the VM host and runs |
|
Installs the CBMC and the elan CI pins, each verified by its
SHA-256, and Lean, all without root: CBMC into |
check-style.sh fetches the kernel’s checkpatch.pl at a pinned
tag into build/checkpatch/ and verifies its SHA-256. It asks
kernel.org first and then its GitHub mirror, gives each ten seconds to
answer, and does not ask again a source that failed once. Set
CHECKPATCH=<path> to use a kernel tree’s
scripts/checkpatch.pl instead, for example without network access.
Before you send a change, run what CI runs on a pull request:
Run the checks over your commits:
$ .github/scripts/check-dco.sh origin/main..HEAD $ .github/scripts/check-style.sh origin/main..HEAD $ .github/scripts/check-spdx.sh $ .github/scripts/check-unused.sh $ .github/scripts/check-sparse.sh $ .github/scripts/check-coccinelle.sh $ .github/scripts/build-commits.sh origin/main..HEAD
Run clang’s static analyzer, in a throwaway container with
scan-build.shor on a host that has clang 23’s tools:$ scan-build-23 --status-bugs --exclude vendor make ANALYZE=1
Run the tests the change touches, and
make testsbefore you send. When the change touches memory handling or binary formats, runmake tests VM=0 SANITIZE=address,undefinedfrom a clean tree too, as CI does. See Run and write tests.If you changed the documentation, check it and render it:
$ .github/scripts/check-docs.sh $ make -C Documentation html
Verify that every script printed its summary line and exited 0, for example
DCO: 3 commits checkedandstyle: 3 commits checked.
Coccinelle rules#
Each semantic patch in testing/coccinelle/ describes a pattern
the tree is kept free of, and check-coccinelle.sh fails on any
match, in the Coccinelle job of the Lint workflow. The rules
cover the C the project writes, as check-style.sh takes it: not the
vendored libbpf, the BTF dumps or the generated headers. A rule that
can rewrite what it finds does so with -D patch:
$ spatch -D patch --sp-file testing/coccinelle/zero_init.cocci \
--in-place --include-headers util/json.c
Rule |
Refuses |
|---|---|
|
An element count divided out by hand rather than
|
|
|
|
A ternary that picks the smaller or larger of two values rather
than |
|
|
|
A NULL test before a free function that takes NULL. Rewrites. |
|
A |
|
A |
|
A local filled with an activated credential, a KDF output or an
ECDH shared value, or by |
|
A local of a struct with a member marked |
|
A libcurl header list freed without first scrubbing its copied
header strings with |
|
|
|
Two strings fed to a digest one after the other, each by its
|
|
A test of the truth of an OpenSSL function that returns 0 or a negative value on failure. |
|
A sum or product tested for overflow by hand rather than with
the helpers of |
|
A |
|
A NULL passed to a memory or string function, and a
|
|
The size of a pointer where the object it points to is meant, wherever it is taken, unless the pointer’s own address goes to the same call. |
|
A length that does not match the string literal |
|
A string literal compared or searched with |
|
A string literal copied into an array with |
|
A buffer that |
|
The bytes |
|
A value compared with an option name, a literal that starts with
|
|
A pointer tested for NULL after its use. |
|
A pointer dereferenced in the branch of the test that found it NULL. |
|
An allocation used before it is checked. |
|
Memory used or freed again after it was freed. |
|
A local read after a |
|
The address of a local array or variable, or of a member or element
of one, stored in an object the caller passed in, in a member at
any depth, an element or |
|
An allocation sized for another type than its pointer, and a free of memory no allocator returned. |
|
A term tested twice, an |
|
A |
|
A descriptor left open on a path out once its open succeeded,
where it is not returned, stored or handed to what closes it, a
lock of |
|
A descriptor or stream opened without close-on-exec. |
|
A path passed to |
|
|
|
A function that runs a program, outside the operator helper, the command that hands work to it and the tests. |
|
A bitwise operator on a |
|
A |
|
A |
|
|
|
A cleanup call, such as |
|
A bare error number or |
|
A descriptor passed to a call after it was closed, after CERT C FIO46-C. |
|
A test for a negative value or |
|
A |
|
|
|
A value stored in a local and stored over on every path, the error exits included, before anything reads it, after CERT C MSC12-C. Following every path of a long function can take minutes, so the rule gives up on a file after one; the check names each file it gave up on. |
|
A |
|
An error stored before a |
|
A sum stored in a total under a condition, between a value it had
and an addition to it, where |
|
|
|
A compare-and-swap whose result is dropped. |
|
A |
|
|
|
Two reads of the same user address, between which the memory can change. |
|
A map value read through the pointer a lookup returned after
|
A new pattern worth refusing gets a rule: write it from scratch under
the BSD-2-Clause, or carry one from a project that offers it with a
BSD-2-Clause branch, keeping its SPDX and copyright lines and naming it
in check-spdx.sh, as bpf_map_use_after_delete comes from
tetragon. Give it a header that says why the pattern is refused, fix the
tree in the commits before it, and add it to the table. A rule exists
only to run in CI. Where the tree gives it no match, add a case of what
it refuses to t0006-check-coccinelle, which shows that it matches.
check-coccinelle.sh runs a rule without the headers a file includes,
which keeps it fast but leaves the types they declare unknown. A rule
that needs them, as sizeof_ptr needs the type of a struct member,
names its include options on a #spatch line. A rule whose search can
run long names --timeout <seconds> there, as dead_store does: the
check then runs it one file at a time and names each file spatch gave up
on, rather than failing.
Every rule declares SEC an attribute, as the rules run over the BPF
sources too. Without that, Coccinelle takes a map defined as
} name SEC(".maps"); for a type, and no pattern matches a call that
takes the map’s address, without an error; t0006 checks that each
rule declares it. The bpf_ rules also read the BPF sources
through testing/coccinelle/bpf.macros, which tells Coccinelle what
SEC(), BPF_PROG() and the map definition macros mean. A file that
defines its own token-pasting macros, as
upatches/kernel-obs/obs_table.h does, stays out of their reach.
Each matches a hazard that exists on every kernel. Per-CPU memory used
as scratch is a hazard only under some preemption models and program
types, which a rule cannot tell, so no rule refuses it.
Concurrency hazards explains each hazard
and where it applies.
Next steps#
Develop locally to run both roles on one machine and change shirudo end to end
Run and write tests to run and write tests
Commits and sign-off for the commit message and the sign-off
Linux kernel coding style for the C code
CLI for the commands