eBPF-based security platform
systemd: start XDP reconcile from udev and a timer
John Fastabend62a1bf5d39b4
diff --git a/.gitignore b/.gitignoreindex 2fe0cbda..434f900d 100644--- a/.gitignore+++ b/.gitignore@@ -35,6 +35,7 @@/systemd/shirudo-initrd.service/systemd/shirudo-map-export.service/systemd/shirudo-keepalive.service+/systemd/shirudo-xdp-reconcile.service/systemd/shirudo-bpm-repo-update.service/systemd/shirudo-bpm-tree-sync.servicediff --git a/AGENTS.md b/AGENTS.mdindex 276768ac..94193e0b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -20,7 +20,8 @@ what is present on the machine, never by separate builds:initrd under PCRs 9 and 11 and anchored in PCR 9, verifies everyload, emits TPM-signed evidence on request(`shirudo attest`) and is agentless: no daemon, no listening socket,- every operation is a one-shot CLI invocation run locally or by the+ every operation is a one-shot CLI invocation run locally, by systemd+ when udev reports a new network device (`upatch reconcile`), or by thesystemd timers that pull packages (`bpm repo update`, `bpm upgrade`,`bpm tree sync`) and export status (OTLP). The operator verifies thatevidence offline (`shirudo attest verify`, `shirudo attest predict`).@@ -183,7 +184,7 @@ one usually still compiles and passes tests.on drift (`tampered`) rather than retrying. Boot restore is exactly oneregister event and a re-run of `init` adds none. A load stoppedbetween its pins and its extend leaves pins without a record: `status`- reports them (`UpatchesMeasured`) and the next upatch command undoes+ reports them (`UpatchesMeasured`) and the next upatch load or unload undoesthem, or refuses when it cannot, under the register lock, which aload or an unload holds from before it touches the pins to itsappend, and a purge from its archive read until its pins and archivediff --git a/Documentation/concepts/operator-and-target.rst b/Documentation/concepts/operator-and-target.rstindex 7c50fab3..fae5df9e 100644--- a/Documentation/concepts/operator-and-target.rst+++ b/Documentation/concepts/operator-and-target.rst@@ -193,8 +193,9 @@ keepalives every five seconds.What must outlive a command is pinned in the private bpffs, and what mustoutlive the boot is archived under ``/var/lib/shirudo`` and restored by``init``. We accept the cost of this design, which is latency: a target-learns of a new package at its next timer run, and nothing on it reacts-between runs. In return there is no long-running process for root to+learns of a new package at its next timer run, and besides a new network+device starting ``upatch reconcile``, nothing on it reacts between runs.+In return there is no long-running process for root toattack, no socket for the network to reach, and less code in the target'strusted computing base.diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex a1da6510..2c1c843e 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -426,7 +426,7 @@ signed config image.- Task policy is inherited by a listener and its accepted socket* - ``t6143-unmeasured-load``- A load stopped before its extend is counted, reported by status- and undone by the next upatch command+ and undone by the next upatch load or unload* - ``t6144-returned-archive``- The archive directory with its mark evicted takes nothing andlets no labeled archive out; an archive without a record of itsdiff --git a/Documentation/internals/design-decisions.rst b/Documentation/internals/design-decisions.rstindex 143b1686..93a55590 100644--- a/Documentation/internals/design-decisions.rst+++ b/Documentation/internals/design-decisions.rst@@ -36,7 +36,8 @@ Agentless targets-----------------A target runs no daemon and opens no listening socket. Every operation-is a one-shot ``shirudo`` command, started by hand or by a systemd timer.+is a one-shot ``shirudo`` command, started by hand, by a systemd timer, or+for ``upatch reconcile`` by systemd when udev reports a new network device.A long-running process is something root can trace, stop or feedinput to for as long as it runs, and a socket is an attack surface for@@ -46,7 +47,10 @@ kernel enforces without a helper, and the TPM keeps the record.The cost is that nothing on the target watches continuously. Packageupdates and telemetry run on timer periods, and a target reports its-state only when a command runs.+state only when a command runs. A new network device is the one event a+command starts on, because a device left without its XDP upatch for a+whole period is exposed for that long; the command still does one pass+and exits.Pull-based delivery-------------------diff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rstindex 44df5c92..28531d98 100644--- a/Documentation/operate/deploy/boot-integration.rst+++ b/Documentation/operate/deploy/boot-integration.rst@@ -303,7 +303,15 @@ the initrd, from the binary the UKI authenticates.ExecStart=ExecStart=/run/shirudo/runtime/usr/bin/shirudo bpm tree sync-6. Reload systemd:+6. Write ``/etc/systemd/system/shirudo-xdp-reconcile.service.d/runtime.conf``:++ .. code-block:: ini++ [Service]+ ExecStart=+ ExecStart=/run/shirudo/runtime/usr/bin/shirudo upatch reconcile++7. Reload systemd:.. code-block:: consolediff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rstindex 02a79acd..8dab05f2 100644--- a/Documentation/operate/run/read-status.rst+++ b/Documentation/operate/run/read-status.rst@@ -654,7 +654,7 @@ there except ``SealSignal``. A refusal worked, so a counter alone doesnot change any condition or the verdict. It tells you that something onthe host tried. A ``SealSignal`` tells you that a shirudo command wassignalled from outside; a load stopped that way shows under-``UpatchesMeasured`` until the next upatch command undoes it.+``UpatchesMeasured`` until the next upatch load or unload undoes it.These four attempts, made as root without shirudo's runtime authority,were each refused:diff --git a/Documentation/reference/systemd-units.rst b/Documentation/reference/systemd-units.rstindex 0d0fc695..54e865d6 100644--- a/Documentation/reference/systemd-units.rst+++ b/Documentation/reference/systemd-units.rst@@ -32,6 +32,9 @@ Units* - ``shirudo-keepalive.service``- ``@bindir@/shirudo status --otel --include-system``- ``shirudo-keepalive.timer``+ * - ``shirudo-xdp-reconcile.service``+ - ``@bindir@/shirudo upatch reconcile``+ - ``shirudo-xdp-reconcile.timer`` and the udev rule below* - ``shirudo-map-export.service``- ``@bindir@/shirudo upatch map --all``- ``shirudo-map-export.timer``@@ -158,7 +161,7 @@ installed, ``/etc/shirudo/init.env`` and ``SHIRUDO_INIT_ARGS`` have noeffect.The generator writes this drop-in for ``shirudo.service`` only. The-keepalive, map-export, repository-update and tree-sync services run+keepalive, reconcile, map-export, repository-update and tree-sync services run``@bindir@/shirudo``. On a target that enforces, a shirudo binary outsidethe runtime image is refused with ``shirudo: image state: Permissiondenied`` and exit status 1, so each of these services needs its own@@ -189,6 +192,36 @@ The keepalive is sent only when ``map_export.otel_endpoint``,``OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`` or ``OTEL_EXPORTER_OTLP_ENDPOINT``names an endpoint. See :doc:`/reference/formats/otlp`.+shirudo-xdp-reconcile.service+-----------------------------++.. list-table::+ :header-rows: 1+ :widths: 30 70++ * - Setting+ - Value+ * - ``ExecStart``+ - ``@bindir@/shirudo upatch reconcile``+ * - ``After``+ - ``shirudo.service``+ * - ``ConditionPathExists``+ - ``/run/shirudo/bpffs/lsm_link``+ * - ``StartLimitIntervalSec``+ - ``0``, as a burst of new veths would otherwise disable it+ * - ``TimeoutStartSec``+ - ``2min``+ * - ``LimitMEMLOCK``+ - ``infinity``++The rule ``90-shirudo-xdp-reconcile.rules`` in+``/usr/lib/udev/rules.d`` starts it through ``SYSTEMD_WANTS`` when a+network device other than ``lo`` appears. It is not ``RUN+=``, because a+child of ``systemd-udevd`` inherits its seccomp filter and would get no+task mark. A veth peer moving namespace gives the initial namespace no+such event, so the timer is what catches it. The unit and the rule are not+in the initrd. See :doc:`/reference/cli/upatch-reconcile`.+shirudo-map-export.service--------------------------@@ -284,6 +317,8 @@ Timers- Schedule* - ``shirudo-keepalive.timer``- ``OnBootSec=5s``, ``OnUnitInactiveSec=5s``, ``AccuracySec=1s``+ * - ``shirudo-xdp-reconcile.timer``+ - ``OnBootSec=5s``, ``OnUnitInactiveSec=5s``, ``AccuracySec=1s``* - ``shirudo-map-export.timer``- ``OnBootSec=5s``, ``OnUnitInactiveSec=5s``, ``AccuracySec=1s``* - ``shirudo-bpm-repo-update.timer``@@ -315,8 +350,9 @@ Enablement- What it enables* - Target ``.deb`` and ``.rpm``- On install: ``systemctl enable`` of ``shirudo.service`` and the- four timers, for the next boot. Nothing is started. On removal:- ``disable --now`` of the four timers and ``disable`` of+ five timers, for the next boot, and ``udevadm control --reload``.+ Nothing is started. On removal: ``disable --now`` of the five+ timers and ``disable`` of``shirudo.service``.* - Target tarball (``install.sh``)- ``systemctl daemon-reload`` only.diff --git a/Documentation/security/tamper-counters.rst b/Documentation/security/tamper-counters.rstindex afd8fa54..664aabdf 100644--- a/Documentation/security/tamper-counters.rst+++ b/Documentation/security/tamper-counters.rst@@ -294,7 +294,7 @@ What a non-zero counter meansA counter that moved means that a guard refused an operation this boot.The refusal is what moved it: the operation did not happen. The oneexception is ``SealSignal``, which counts a signal the seal delivered:-the task it went to may have been stopped, and the next upatch command+the task it went to may have been stopped, and the next upatch load or unloadand ``shirudo status`` find what a stopped load left.A non-zero counter does not mean:diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex c183b3e5..642060a1 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1551,8 +1551,11 @@ R21 upatches can be neutralized by changing their targetsXDP coverage is reconciled, not continuous. A device added after loadruns without the upatch until ``upatch reconcile`` next runs, and is- unfiltered until then. A device stays uncovered while its XDP slot is- occupied or it has no native XDP. A veth end moved to another namespace+ unfiltered until then: normally seconds after its udev event, and up to+ one pass plus five seconds when udev gives no signal, as for a veth+ peer moving namespace. A device stays uncovered while its XDP slot is+ occupied, it has no native XDP, or root stops the timer and the udev+ rule, and ``status`` does not list such devices. A veth end moved to another namespacekeeps its link, so a pair can hold two attachments, one of them runningin that namespace. Reconcile adds no register event: TPM evidence coversthe signed class mask and loaded artifact, not the device inventory ordiff --git a/Makefile b/Makefileindex 089c51cf..b5381c1a 100644--- a/Makefile+++ b/Makefile@@ -34,6 +34,7 @@ mandir ?= $(sharedir)/mancompletionsdir ?= $(sharedir)/bash-completion/completions# Absolute by default (systemd does not scan /usr/local); packagers override.systemdunitdir ?= /usr/lib/systemd/system+udevrulesdir ?= /usr/lib/udev/rules.ddracutmodulesdir ?= /usr/lib/dracut/modules.d# Local target dependency build defaults. make target-deps builds a static@@ -47,7 +48,7 @@ SHIRUDO_TARGET_STATIC_LIBDIR ?= $(TARGET_DEPS_DIR)/libSHIRUDO_TARGET_PKG_CONFIG_PATH ?= $(TARGET_DEPS_CURL_PREFIX)/lib/pkgconfig:$(TARGET_DEPS_OPENSSL_PREFIX)/lib/pkgconfig:$(SHIRUDO_TARGET_STATIC_LIBDIR)/pkgconfigexport prefix exec_prefix bindir libexecdir sharedir libdir mandir completionsdir \- systemdunitdir dracutmodulesdir SHIRUDO_TARGET_PKG_CONFIG_PATH \+ systemdunitdir udevrulesdir dracutmodulesdir SHIRUDO_TARGET_PKG_CONFIG_PATH \SHIRUDO_TARGET_STATIC_LIBDIR.PHONY: all help target target-deps target-deps-clean shirudo-target target-config shirudo-build docs bpf-deps install install-target install-operator clean distclean config tests proofs proofs-cbmc proofs-lean4 sparsediff --git a/Makefile.shirudo b/Makefile.shirudoindex 30b340df..d6d4a981 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -522,6 +522,10 @@ systemd/shirudo-keepalive.service: systemd/shirudo-keepalive.service.in@printf ' GEN $@\n'$(Q)sed 's|@bindir@|$(bindir)|g' $< > $@+systemd/shirudo-xdp-reconcile.service: systemd/shirudo-xdp-reconcile.service.in+ @printf ' GEN $@\n'+ $(Q)sed 's|@bindir@|$(bindir)|g' $< > $@+# The BPM repository refresh is target-only and uses the same installed# binary plus the optional BPM OCI environment file.systemd/shirudo-bpm-repo-update.service: systemd/shirudo-bpm-repo-update.service.in@@ -554,6 +558,8 @@ install-target: shirudo-target install-common systemd/shirudo.service \systemd/shirudo-map-export.timer \systemd/shirudo-keepalive.service \systemd/shirudo-keepalive.timer \+ systemd/shirudo-xdp-reconcile.service \+ systemd/shirudo-xdp-reconcile.timer \systemd/shirudo-bpm-repo-update.service \systemd/shirudo-bpm-repo-update.timer \systemd/shirudo-bpm-tree-sync.service \@@ -576,11 +582,17 @@ install-target: shirudo-target install-common systemd/shirudo.service \systemd/shirudo-map-export.timer \systemd/shirudo-keepalive.service \systemd/shirudo-keepalive.timer \+ systemd/shirudo-xdp-reconcile.service \+ systemd/shirudo-xdp-reconcile.timer \systemd/shirudo-bpm-repo-update.service \systemd/shirudo-bpm-repo-update.timer \systemd/shirudo-bpm-tree-sync.service \systemd/shirudo-bpm-tree-sync.timer \$(DESTDIR)$(systemdunitdir)/+ @printf ' INSTALL $(DESTDIR)$(udevrulesdir)/90-shirudo-xdp-reconcile.rules\n'+ $(Q)install -d $(DESTDIR)$(udevrulesdir)+ $(Q)install -m 0644 systemd/90-shirudo-xdp-reconcile.rules \+ $(DESTDIR)$(udevrulesdir)/install-operator: install shirudo-build $(VMLINUX_H) $(BPF_LIBBPF_HEADERS) $(BPF_LIB_HEADERS)@printf ' INSTALL $(DESTDIR)$(libexecdir)/shirudo/shirudo-build\n'diff --git a/packaging/deb/builddeb.sh b/packaging/deb/builddeb.shindex d47f6c24..d25a688d 100755--- a/packaging/deb/builddeb.sh+++ b/packaging/deb/builddeb.sh@@ -114,12 +114,15 @@ if [ "$1" = configure ] && command -v systemctl >/dev/null 2>&1; thensystemctl enable shirudo.service >/dev/null 2>&1 || truesystemctl enable shirudo-map-export.timer >/dev/null 2>&1 || truesystemctl enable shirudo-keepalive.timer >/dev/null 2>&1 || true+ systemctl enable shirudo-xdp-reconcile.timer >/dev/null 2>&1 || true+ udevadm control --reload >/dev/null 2>&1 || truesystemctl enable shirudo-bpm-repo-update.timer >/dev/null 2>&1 || truesystemctl enable shirudo-bpm-tree-sync.timer >/dev/null 2>&1 || trueecho "shirudo: shirudo.service enabled; it runs 'shirudo init' early on the"echo "shirudo: next boot. To enforce now: systemctl start shirudo.service"echo "shirudo: shirudo-map-export.timer enabled for the next boot"echo "shirudo: shirudo-keepalive.timer enabled for the next boot"+ echo "shirudo: shirudo-xdp-reconcile.timer enabled for the next boot"echo "shirudo: shirudo-bpm-repo-update.timer enabled for the next boot"echo "shirudo: shirudo-bpm-tree-sync.timer enabled for the next boot"fi@@ -133,6 +136,8 @@ if [ "$1" = remove ] && command -v systemctl >/dev/null 2>&1; then>/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-keepalive.timer \>/dev/null 2>&1 || true+ systemctl --no-reload disable --now shirudo-xdp-reconcile.timer \+ >/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-bpm-repo-update.timer \>/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-bpm-tree-sync.timer \diff --git a/packaging/rpm/buildrpm.sh b/packaging/rpm/buildrpm.shindex 4d69e001..e37097d2 100755--- a/packaging/rpm/buildrpm.sh+++ b/packaging/rpm/buildrpm.sh@@ -128,12 +128,15 @@ if [ "$1" -eq 1 ] && command -v systemctl >/dev/null 2>&1; thensystemctl enable shirudo.service >/dev/null 2>&1 || truesystemctl enable shirudo-map-export.timer >/dev/null 2>&1 || truesystemctl enable shirudo-keepalive.timer >/dev/null 2>&1 || true+ systemctl enable shirudo-xdp-reconcile.timer >/dev/null 2>&1 || true+ udevadm control --reload >/dev/null 2>&1 || truesystemctl enable shirudo-bpm-repo-update.timer >/dev/null 2>&1 || truesystemctl enable shirudo-bpm-tree-sync.timer >/dev/null 2>&1 || trueecho "shirudo: shirudo.service enabled; it runs 'shirudo init' early on the"echo "shirudo: next boot. To enforce now: systemctl start shirudo.service"echo "shirudo: shirudo-map-export.timer enabled for the next boot"echo "shirudo: shirudo-keepalive.timer enabled for the next boot"+ echo "shirudo: shirudo-xdp-reconcile.timer enabled for the next boot"echo "shirudo: shirudo-bpm-repo-update.timer enabled for the next boot"echo "shirudo: shirudo-bpm-tree-sync.timer enabled for the next boot"fi@@ -145,6 +148,8 @@ if [ "$1" -eq 0 ] && command -v systemctl >/dev/null 2>&1; then>/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-keepalive.timer \>/dev/null 2>&1 || true+ systemctl --no-reload disable --now shirudo-xdp-reconcile.timer \+ >/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-bpm-repo-update.timer \>/dev/null 2>&1 || truesystemctl --no-reload disable --now shirudo-bpm-tree-sync.timer \diff --git a/systemd/90-shirudo-xdp-reconcile.rules b/systemd/90-shirudo-xdp-reconcile.rulesnew file mode 100644index 00000000..9f2d6882--- /dev/null+++ b/systemd/90-shirudo-xdp-reconcile.rules@@ -0,0 +1,7 @@+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# Through systemd rather than RUN+=: systemd-udevd runs under a seccomp+# filter that its children inherit, and a filtered exec gets no task mark.++SUBSYSTEM=="net", ACTION!="remove", KERNEL!="lo", TAG+="systemd", ENV{SYSTEMD_WANTS}+="shirudo-xdp-reconcile.service"diff --git a/systemd/shirudo-xdp-reconcile.service.in b/systemd/shirudo-xdp-reconcile.service.innew file mode 100644index 00000000..3c551fc2--- /dev/null+++ b/systemd/shirudo-xdp-reconcile.service.in@@ -0,0 +1,14 @@+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++[Unit]+Description=shirudo: attach XDP upatches to new network devices+After=shirudo.service+ConditionPathExists=/run/shirudo/bpffs/lsm_link+StartLimitIntervalSec=0++[Service]+Type=oneshot+LimitMEMLOCK=infinity+TimeoutStartSec=2min+ExecStart=@bindir@/shirudo upatch reconcilediff --git a/systemd/shirudo-xdp-reconcile.timer b/systemd/shirudo-xdp-reconcile.timernew file mode 100644index 00000000..a3f2ca57--- /dev/null+++ b/systemd/shirudo-xdp-reconcile.timer@@ -0,0 +1,14 @@+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++[Unit]+Description=shirudo: periodically attach XDP upatches to new network devices++[Timer]+OnBootSec=5s+OnUnitInactiveSec=5s+AccuracySec=1s+Unit=shirudo-xdp-reconcile.service++[Install]+WantedBy=timers.targetdiff --git a/testing/vm/guest.sh b/testing/vm/guest.shindex b2ff30a9..61323de9 100755--- a/testing/vm/guest.sh+++ b/testing/vm/guest.sh@@ -307,6 +307,8 @@ TARGET_UNITS=(shirudo-map-export.timershirudo-keepalive.serviceshirudo-keepalive.timer+ shirudo-xdp-reconcile.service+ shirudo-xdp-reconcile.timershirudo-bpm-repo-update.serviceshirudo-bpm-repo-update.timershirudo-bpm-tree-sync.service@@ -449,6 +451,10 @@ if [[ "$VM_MODE" == interactive ]]; thensystemctl enable shirudo.servicesystemctl enable --now shirudo-map-export.timersystemctl enable --now shirudo-keepalive.timer+ install -D -m 0644 "$BUNDLE/root/usr/lib/udev/rules.d/90-shirudo-xdp-reconcile.rules" \+ /usr/lib/udev/rules.d/90-shirudo-xdp-reconcile.rules+ udevadm control --reload+ systemctl enable --now shirudo-xdp-reconcile.timersystemctl enable --now shirudo-bpm-repo-update.timersystemctl enable --now shirudo-bpm-tree-sync.timer