Kernel interfaces#
The kernel interfaces shirudo uses on a target, with the exact arguments. The operator side uses none of them. Signed loader path and Enforcement in the kernel explain why each is needed.
Kernel baseline#
Commit |
Subject |
First release |
|---|---|---|
|
block,lsm: add LSM blob and new LSM hooks for block devices |
v6.12 |
|
x86/ftrace: Implement DYNAMIC_FTRACE_WITH_JMP |
v6.19 |
|
dm-verity: add dm-verity keyring |
v7.0 |
|
bpf: Expose signature verdict via bpf_prog_aux |
v7.2 |
|
bpf: have bpf_real_data_inode() take a struct file |
v7.2 |
|
bpf: Add simple xattr support to bpffs |
v7.2 |
|
bpf, keys: Add a bpf keyring for program signature validation |
bpf-next |
|
bpf: Refuse caller-supplied keyrings when the bpf one is active |
bpf-next |
|
bpf, lsm: Let BPF LSM provide xattrs at inode creation |
bpf-next |
|
keys: add KEY_SPEC_DM_VERITY_KEYRING |
7.4 cycle |
bpf-next contains the signed-loader ABI at merge 0867b7bfa9de.
The test suite uses the pinned artifact built from testing/kernel/.
shirudo defines KEY_SPEC_DM_VERITY_KEYRING (-10) itself when
the UAPI headers lack it. The tpm_command LSM hook, the label reads
without the calling task’s permission, the sleepable form of six inode
hooks, the trusted d_parent and the mm_read_access LSM hook are
not in bpf-next;
Carried kernel patches lists the patches the test kernel carries. A
kernel is admitted by the ABI check below, not by its release string.
XDP attachment#
XDP uses BPF_LINK_CREATE with attach_type=BPF_XDP,
target_ifindex from runtime discovery and flags=XDP_FLAGS_DRV_MODE.
shirudo verifies BPF_LINK_TYPE_XDP and the returned xdp.ifindex
before pinning. Discovery uses kernel RTM_GETLINK replies,
ETHTOOL_GDRVINFO and devlink DEVLINK_CMD_PORT_GET; it does not
read sysfs to classify devices. The program a device runs, in any mode,
comes from the IFLA_XDP attributes of the same dump:
IFLA_XDP_DRV_PROG_ID, and IFLA_XDP_SKB_PROG_ID or
IFLA_XDP_HW_PROG_ID for a program shirudo did not attach. Before attaching, shirudo reads
NETDEV_A_DEV_XDP_FEATURES with NETDEV_CMD_DEV_GET on the netdev
generic netlink family and refuses a device that reports
NETDEV_XDP_ACT_BASIC without NETDEV_XDP_ACT_RX_SG, as the kernel
never compares a program’s multi-buffer flag with the device’s. The
lsm/bpf_prog guard refuses XDP
descriptors to unauthorized callers, including BPF_PROG_GET_FD_BY_ID,
because netlink accepts these descriptors outside bpf().
Signing ABI check#
kernel_abi_check() (util/kernel_abi.c) reads the running kernel’s
BTF and requires:
Member |
Required type |
|---|---|
|
|
|
pointer to a byte, not a bit field |
|
struct |
|
|
|
|
|
|
The pre-flight runs it as signed_loader_kernel_abi, and every
upatch load and upatch unload without --no-precheck runs it
before BPF_PROG_LOAD. A failure is kernel_abi_unsupported.
Beside it the pre-flight runs kernel_lsm_hooks: it reads the hooks
of every lsm and lsm.s program from the embedded bpf2 and
seal objects and refuses a kernel whose BTF has no
bpf_lsm_<hook> for one, naming the hooks it lacks.
lsm/bpf_prog_load compares sig.verdict with BPF_SIG_VERIFIED
and sig.keyring_type with BPF_SIG_KEYRING_BPF; these enum values
are compiled into bpf2 from the vmlinux.h of the build.
Signature verification#
Kernel behavior a signed load relies on (bpf_prog_verify_signature()
in kernel/bpf/verifier.c):
Input |
Behavior |
|---|---|
|
Size 1 to 64 KiB. Verified when |
|
|
|
The maps resolved from |
|
Must be 0 for a signed program ( |
Result |
On success, |
A map with excl_prog_hash set binds only to a program whose SHA-256
digest equals it.
BPF system calls of a load#
Every call below is made from userspace with kernel false, except
where the caller is the loader.
Command |
Attributes set |
|---|---|
|
|
|
|
|
|
|
|
|
|
loader: |
As gen_loader recorded them. |
|
One per program, with the attributes of its attach kind in the table below. |
|
On each link before it is pinned, compared as the table below
says; a mismatch is |
|
Links at |
The attach kinds are those of Attach kinds,
numbered as in the signed attach metadata. Every call is
BPF_LINK_CREATE except where the table says otherwise.
Kind |
|
Target and other attributes |
Checked before pinning |
|---|---|---|---|
0, an LSM program |
|
|
A raw tracepoint or tracing link. |
0, a |
|
As kinds 3 and 4. |
As kinds 3 and 4. |
0, any other program |
None: |
|
A raw tracepoint or tracing link. |
1, 2: kprobe, kretprobe |
|
|
Perf event type, function name and offset as signed. |
3, 4: |
|
|
|
5: |
|
|
A tracing link of |
6: netfilter |
|
|
|
7, 9: |
|
|
Offset count and the return flag. |
8: XDP |
|
|
|
10, 11: uprobe, uretprobe and their |
|
|
Perf event type, the file offset as signed and
|
A kprobe link’s perf event comes from perf_event_open(2) with
type read from /sys/bus/event_source/devices/kprobe/type,
config1 the symbol, config2 the offset, the bit named in
.../kprobe/format/retprobe set in config for a kretprobe, pid
-1, cpu 0 and PERF_FLAG_FD_CLOEXEC. A uprobe link’s comes from
the same call on the uprobe PMU, /sys/bus/event_source/devices/uprobe,
with config1 the path /proc/self/fd/<n> of the target binary’s
checked descriptor and config2 the recorded file offset.
An unload directive makes the first four calls and no others.
init loads bpf2 and seal with libbpf (BPF_BTF_LOAD,
BPF_MAP_CREATE, BPF_PROG_LOAD of BPF_PROG_TYPE_LSM), attaches
each program with BPF_LINK_CREATE and BPF_LSM_MAC, and pins it.
It populates the identity map with BPF_MAP_UPDATE_ELEM, seeds
shirudo_tasks with a pidfd as key, and freezes maps with
BPF_MAP_FREEZE.
Extended attributes#
Name |
Use |
|---|---|
|
The seal label on writable state, on |
|
The 32-byte payload digest on each upatch’s pin directory in the private bpffs. |
|
The 8-byte policy bitset of an executable, which the seal adds to the task’s bits at exec. |
|
The mark on each directory between the state root and the root of its file system, which the seal guards against a rename. |
LSM hooks#
Hook |
Object |
Kernel condition |
|---|---|---|
|
|
|
|
|
|
|
|
Carried patch |
|
|
Carried patch |
|
|
None |
|
|
|
|
|
None |
|
|
Carried patch 0004, for the read of |
|
|
Carried patch 0003, and 0004 for |
A hook the kernel’s BTF lacks fails the pre-flight check
kernel_lsm_hooks, before init loads anything. Enforcement in the kernel
gives each hook’s verdicts.
Kfuncs and helpers#
Kfunc |
Use |
|---|---|
|
Read |
|
Add the label in |
|
Tell an overlay copy from a direct inode at exec. Sleepable. |
|
Bounded loops ( |
Helpers: bpf_map_lookup_elem(), bpf_map_update_elem(),
bpf_map_delete_elem(), bpf_task_storage_get(),
bpf_inode_storage_get(), bpf_inode_storage_delete(),
bpf_sk_storage_get(), bpf_get_current_task_btf(),
bpf_probe_read_kernel(), bpf_probe_read_kernel_str(),
bpf_bprm_opts_set() with BPF_F_BPRM_SECUREEXEC,
bpf_dynptr_from_mem(), bpf_strncmp().
Map types: BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_HASH,
BPF_MAP_TYPE_TASK_STORAGE, BPF_MAP_TYPE_INODE_STORAGE,
BPF_MAP_TYPE_SK_STORAGE.
Keyrings#
Call |
Use |
|---|---|
|
Serial of |
|
Enroll a BPF certificate. |
|
Seal |
|
The same for |
|
List a keyring and compare it with the expected set. |
|
Remove a revoked certificate from |
|
Probe whether the kernel parses a certificate, then unlink it. |
|
Hand a config root signature to dm-verity as
|
|
Pre-flight check that keys are available. |
Device mapper and loop#
Call |
Use |
|---|---|
|
Attach an image file read-only with |
|
Check that a loop device still backs the image file. |
|
Create, check, list and remove |
|
Identify a mapping and check its size and read-only state. |
Process setup and prctl#
Call |
Use |
|---|---|
|
Enforcement probe. |
|
Drops the personality flags the caller passed down, |
|
Exec keeps the limits and timers the caller set, with which the
kernel would stop the command by |
|
Process hardening before every command. |
|
No core dumps; memory kept out of swap. A failed |
|
Key for the bootstrap mark in |
Mounts#
Mount |
Options |
|---|---|
|
|
|
|
ext4 runtime image at |
|
ext4 config image at |
|
bind of |
Recursive, in the initrd only, detached when |
Kconfig#
Option |
Why |
|---|---|
|
|
|
The BPF LSM. |
|
|
|
BPF trampolines, which every LSM program attaches through. |
|
CO-RE, the ABI check, the check of the pinned guard links. |
|
The |
|
The keyrings, certificates and CMS verification. |
|
ML-DSA-87 certificates and signatures; the SHA-512 digest in the CMS signed attributes; SHA-256 digests. |
|
The TPM. |
|
The runtime and config images. |
|
Security extended attributes when the state is on ext4. |
|
The label on |
|
The initrd |
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING and
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING widen the keys
the kernel’s own check of a config accepts, but the target checks the
signature against the runtime image’s certificates first; see
Config images and dm-verity. CONFIG_SECCOMP=n
is handled: the seal then sees no seccomp state. The attach kinds of
upatches can need further options; see Attach kinds.
The pre-flight check module_signatures refuses a kernel that builds
modules without CONFIG_MODULE_SIG, and tells it from the running
kernel, since a target need not have /proc/config.gz: from a BTF
function only the option builds, __module_address for
CONFIG_MODULES and mod_verify_sig for CONFIG_MODULE_SIG.
Without CONFIG_MODULE_SIG, module_sig_check() is a stub that
asks no LSM about an unsigned module.
The test kernel configuration sets these options and the additional options the test fixtures and VM need.
Kernel command line#
Parameter |
Why |
|---|---|
|
The kernel leaves |
|
The kernel leaves |
|
When |
shirudo-gen-initrd --print-cmdline prints the two keyring parameters.
Both belong on the UKI’s authenticated command line.