shirudo build#
Compile and sign a BPF program, or sign a Java agent .jar, into a
.upatch artifact, or sign an unload directive for a loaded upatch.
Runs on: operator host, without the image gate. Requires: the
shirudo-build helper, the signing key and certificate, and for a
.bpf.c input clang 23 and a vmlinux.h. Changes measured
state: no.
Usage#
shirudo build <input> [-o <output> | --output <output>] [--name <name>]
[--keys-dir <dir> | --keys-dir=<dir>]
[--key <signing-key>] [--cert <certificate>]
[--vmlinux <vmlinux-h>] [--extra-cflags <flags>]
[--emit-artifacts]
shirudo build --unload <name> [-o <output> | --output <output>]
[--payload-sha256 <digest> [--java]]
[--keys-dir <dir> | --keys-dir=<dir>]
[--key <signing-key>] [--cert <certificate>]
shirudo build --help
shirudo-build --help
Every option except --keys-dir takes its value as the next argument.
The form --option=<value> is refused as an unknown option, except
--keys-dir=<dir>. -o and --output are the same option.
Options and the input may come in any order.
shirudo build executes the shirudo-build helper with the same
arguments (see shirudo for how it finds the helper).
shirudo build --help prints a short summary and the helper path.
shirudo-build --help, or --help after any other argument, prints
the helper’s full option list.
Description#
Building a upatch#
The helper resolves the signing key and the certificate:
--keyand--cert, elsesigning_key.pemandcert.derin the keys directory, which is--keys-dir, else$SHIRUDO_KEYS_DIR, else/var/lib/shirudo/keys. The key must be a regular file with mode 0600 and the certificate readable.It selects the output:
-o, else the input path with a trailing.c,.oor.jarreplaced by.upatch, beside the input (fix.bpf.cbecomesfix.bpf.upatch,agent.jaragent.upatch).For a
.bpf.cinput, it findsvmlinux.h:--vmlinux, else./vmlinux.h, else./vendor/linux/vmlinux.h, else the installedvmlinux.h(/usr/share/shirudo/vmlinux.hin the operator package,/usr/local/share/shirudo/vmlinux.haftermake install). It then runs/usr/bin/clang -target bpf -mcpu=v4 -fno-jump-tables -O2 -g -Wall -Wextra -Wshadow -Wtype-limits -Wno-missing-declarations -Wno-unused-parameterwith thevmlinux.hdirectory, the libbpf headers and the shirudo BPF headers on the include path, plus--extra-cflags.-mcpu=v4selects BPF instruction set v4, the newest clang knows and one every target kernel runs.-fno-jump-tableskeeps aswitchin branches, where clang would otherwise read its results from a table in.rodataat an offset the verifier cannot bound. The clang path is fixed when the helper is built,/usr/lib/llvm-23/bin/clangin the Debian package, andPATHis not searched. The object goes to a temporary file in/tmp, or with--emit-artifactsbeside the output.A
.bpf.oor.oinput is packaged as it is. A.jarinput is a Java agent, see Building a Java upatch. Any other input is refused.It names the upatch:
--name, else the input file name without.bpf.c,.bpf.o,.oor.jar.It generates the loader for the object, signs it with the key and writes the artifact. The detached CMS signature covers the loader instructions and the loader’s data, which hold the payload and the signed sections: the name, the attach metadata and any decoders (see .upatch format).
The helper prints wrote <output> (insns=<n> sig=<n> data=<n>
sections=<n> maps=<n> progs=<n> decoders=<n> name=<name>).
Building a Java upatch#
A .jar input is signed as it is, with no compiler. The helper refuses
a file that is no zip archive, and a jar whose manifest names no
Premain-Class: a JVM given such a jar as -javaagent does not
start. It also refuses a zip64 archive and a manifest that is neither
stored nor deflated. The jar and its signature must fit the 16 MiB a
.upatch may have. The
artifact carries no loader: its data holds the signed name, the payload
type and the jar, and the detached CMS signature covers that data alone
(see the Java payloads of .upatch format).
The helper prints wrote <output> (java sig=<n> data=<n> name=<name>).
Java agent upatches describes what a target does with it.
Signing an unload directive#
With --unload <name>, the helper takes no input. It signs the
prebuilt unload program together with <name> and the expected payload
digest:
The expected digest is
--payload-sha256, 64 hexadecimal characters. Read it from the artifact withupatch info --json(keypayload_sha256).Without
--payload-sha256, the helper reads the digest from/var/lib/shirudo/upatches/<name>.upatchon the host it runs on, and refuses with exit status 2 when that file is absent. It signs a Java directive when that upatch is a Java one.With
--payload-sha256,--javasigns the directive of a Java upatch: no unload program, the name, the payload type and the digest in the signed data.The output is
-o, else<name>.unload.upatchin the current directory.
A target applies a directive only to a upatch whose loaded payload
digest equals the signed one (shirudo upatch unload); a directive with
any other digest is refused with payload_mismatch.
Other helper commands#
The helper also serves keys vouch, image build, image verify
and the operator bpm commands, and two commands that only scripts and
tooling call:
shirudo-build image sign-root <root-hash-file> -o <signature>
[--keys-dir <dir>] [--key <signing-key>] [--cert <certificate>]
shirudo-build upatch rewrite-rodata <original> <modified> -o <output>
--data-range <offset>:<length> [--data-range ...]
[--keys-dir <dir>] [--key <signing-key>] [--cert <certificate>]
image sign-root signs the 64 lowercase hexadecimal characters of a
dm-verity root hash. shirudo-gen-verity calls it. upatch
rewrite-rodata re-signs an artifact whose .rodata changed inside the
given ranges.
Options#
Option |
Argument |
Default |
Description |
|---|---|---|---|
|
|
see above |
Where to write the artifact or directive. |
|
|
input file name |
Name of the upatch. Ignored with |
|
|
|
Directory holding |
|
|
from the keys directory |
Private key, PEM, mode 0600. Overrides |
|
|
from the keys directory |
Certificate, DER. Overrides |
|
|
see above |
|
|
|
none |
Further clang flags. They come after the built-in ones, so a
|
|
none |
off |
Keep the compiled object as |
|
|
none |
Sign an unload directive for the upatch |
|
|
see above |
Payload digest the directive expects. Only with |
|
none |
off |
Sign the directive of a Java upatch. Only with |
|
none |
Print the helper’s option list on standard output. |
Exit status#
Status |
Meaning |
|---|---|
0 |
The artifact or directive was written. |
1 |
The key or certificate is unusable, |
2 |
A usage error: an unknown option or one given twice, a value
missing or empty, a second input, an input that is not
|
127 |
|
Files and environment#
Reads the key and certificate,
vmlinux.h, and for--unloadwithout a digest/var/lib/shirudo/upatches/<name>.upatchWrites the output, and
/tmp/shirudo-build-*.bpf.owhile it compilesSHIRUDO_KEYS_DIR: the default keys directorySHIRUDO_BUILD: the helpershirudoexecutes
Examples#
Build and sign a upatch for the kernel whose vmlinux.h you name:
operator$ shirudo build basic.bpf.c --keys-dir <keys-dir> --vmlinux <vmlinux-h> -o basic.upatch
wrote basic.upatch (insns=992 sig=4853 data=2456 sections=2 maps=0 progs=1 decoders=0 name=basic)
Sign the directive that unloads it, bound to its payload digest:
operator$ shirudo build --unload basic --payload-sha256 <payload-sha256> --keys-dir <keys-dir> -o basic.unload.upatch
wrote basic.unload.upatch (insns=1320 sig=4853 data=2808 sections=2 maps=1 progs=1 decoders=0 name=basic UNLOAD)
<keys-dir> holds the key pair, <vmlinux-h> is the target kernel’s
vmlinux.h and <payload-sha256> is the payload_sha256 that
shirudo upatch info --json basic.upatch prints.