Skip to content

eBPF-based security platform

seal: count a signal to a shirudo task from outside as SealSignal

Daniel Borkmannebba4e571967
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 4d351fa9..480b59e9 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -375,8 +375,8 @@ signed config image.
* - ``t6142-policy-socket-inheritance``
- Task policy is inherited by a listener and its accepted socket
* - ``t6143-unmeasured-load``
- - A load stopped before its extend is reported by status and undone
- by the next upatch command
+ - A load stopped before its extend is counted, reported by status
+ and undone by the next upatch command
``bpm`` (7)
~~~~~~~~~~~
@@ -716,6 +716,8 @@ tests assert that a refusal moves its counter:
- ``t6124``
* - ``SealPtrace``
- ``t6135``
+ * - ``SealSignal``
+ - ``t6143``
* - ``ExecTraced``
- ``t6137``
* - ``Kexec``
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rst
index 4cb34b2a..73336360 100644
--- a/Documentation/internals/enforcement.rst
+++ b/Documentation/internals/enforcement.rst
@@ -207,7 +207,7 @@ order:
``sb_remount`` and the ``file_open`` recorder, open the bpffs root so
the recorder notes the mount, and freeze that record.
#. Load ``seal`` on the shared maps, freeze its scratch map, and attach
- its twenty-six hooks, then ``mmap_file`` and ``file_mprotect``.
+ its twenty-seven hooks, then ``mmap_file`` and ``file_mprotect``.
#. Attach ``lsm/bpf_map``, then ``lsm/bpf_prog_load``, then ``lsm/bpf``.
``init`` pins every link as it attaches it, before the next fallible
@@ -443,6 +443,16 @@ when the record it needs is missing.
- ``ENOMEM``
- None
- Closed: no storage refuses the fork of a marked parent.
+ * - ``lsm/task_kill`` (``seal``)
+ - A signal other than 0 to a marked task from a task without
+ authority. Let through, root may end a command that hangs and
+ systemd stops the runs its timers start, and counted, so that a
+ load stopped between its pins and its extend shows before the
+ next command undoes what it left.
+ - none
+ - ``SealSignal``
+ - Which signal is an attack: a stop by root and one by systemd
+ count alike (R2).
* - ``lsm/ptrace_access_check`` (``seal``)
- Every ptrace access mode against a marked task, which covers
attach, ``/proc/<pid>/mem``, ``pidfd_getfd()`` and
diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rst
index ff8107fb..a71f2610 100644
--- a/Documentation/internals/seal.rst
+++ b/Documentation/internals/seal.rst
@@ -124,6 +124,10 @@ it. ``lsm/ptrace_access_check`` refuses every ptrace access to a marked
task (``SealPtrace``), which also covers ``/proc/<pid>/mem``,
``pidfd_getfd()`` and ``process_vm_readv()``. ``lsm/perf_event_alloc``
refuses a perf event bound to a marked task (``SealPerf``).
+``lsm/task_kill`` lets a signal to a marked task through, since root
+may end a command that hangs and systemd stops the runs its timers
+start, and counts one from a task without authority (``SealSignal``),
+so that a command stopped on purpose shows in the counters.
``lsm/mmap_file`` and ``lsm/file_mprotect`` refuse a marked task
executable memory that is writable or that does not come from the
runtime image. ``bpf2`` makes every exec of a runtime file a secure-exec,
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index e756458d..552297ac 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -71,7 +71,7 @@ loaded, captured from the test VM:
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config dc90bacc356f.. is active
- Tamper attempts (refused this boot):
+ Tamper attempts (this boot):
LoadNotLoader 21 program load that is not a signed loader
MapCreate 1 map creation by another executable
BpfCommand 10 detach, update, delete or unclassified bpf() command
@@ -200,7 +200,8 @@ verdict is derived from them.
Tamper attempts
~~~~~~~~~~~~~~~
-The counters of refused attempts this boot, one per guard point, with the
+The counters of attempts this boot, one per guard point, each refused
+there except ``SealSignal``, which is let through and counted, with the
counters that are not zero listed by name, count and meaning. ``none``
means every counter is zero. ``(none recorded: init has not pinned the
counters this boot)`` means ``init`` did not get that far.
@@ -592,9 +593,12 @@ makes ``status`` itself fail with ``shirudo: image state:``.
Read the tamper counters
------------------------
-Each counter counts the attempts that one guard point refused this boot.
-The refusal worked, so a counter alone does not change any condition or
-the verdict. It tells you that something on the host tried.
+Each counter counts the attempts at one guard point this boot, refused
+there except ``SealSignal``. A refusal worked, so a counter alone does
+not change any condition or the verdict. It tells you that something on
+the host tried. A ``SealSignal`` tells you that a shirudo command was
+signalled from outside; a load stopped that way shows under
+``UpatchesMeasured`` until the next upatch command undoes it.
These four attempts, made as root without shirudo's runtime authority,
were each refused:
@@ -618,7 +622,7 @@ LSM returns. The report afterwards lists one more count under
target# shirudo status
...
- Tamper attempts (refused this boot):
+ Tamper attempts (this boot):
LoadNotLoader 39 program load that is not a signed loader
MapCreate 1 map creation by another executable
BpfCommand 16 detach, update, delete or unclassified bpf() command
diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rst
index 93b67f0d..f512fbe1 100644
--- a/Documentation/reference/cli/status.rst
+++ b/Documentation/reference/cli/status.rst
@@ -185,7 +185,7 @@ Show the state of a target:
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config dc90bacc356f.. is active
- Tamper attempts (refused this boot):
+ Tamper attempts (this boot):
LoadNotLoader 21 program load that is not a signed loader
MapCreate 1 map creation by another executable
BpfCommand 10 detach, update, delete or unclassified bpf() command
diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rst
index eec3c77a..57a86ef9 100644
--- a/Documentation/reference/formats/status-json.rst
+++ b/Documentation/reference/formats/status-json.rst
@@ -120,7 +120,8 @@ determined, as noted.
- Persistent state, see `assets`_.
* - ``tamper_attempts``
- object or ``null``
- - Refusals counted this boot, see `tamper_attempts`_. ``null``
+ - Attempts counted this boot, refused except ``SealSignal``, see
+ `tamper_attempts`_. ``null``
until ``init`` has pinned the counters.
* - ``config``
- object or ``null``
@@ -838,7 +839,8 @@ indented here:
"SealWrite": 0, "SealUnlink": 0, "SealRename": 0, "SealSetattr": 0,
"SealXattr": 0, "SealLabel": 0, "SealPtrace": 7, "SealPerf": 0,
"ExecTraced": 0, "SealEntry": 0, "PerfAttach": 0, "PinEntry": 0,
- "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 0
+ "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 0,
+ "SealSignal": 0
}
},
"config": {
@@ -893,7 +895,8 @@ of the same target read:
"SealWrite": 1, "SealUnlink": 0, "SealRename": 0, "SealSetattr": 0,
"SealXattr": 0, "SealLabel": 0, "SealPtrace": 7, "SealPerf": 0,
"ExecTraced": 0, "SealEntry": 0, "PerfAttach": 0, "PinEntry": 0,
- "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 1
+ "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 1,
+ "SealSignal": 0
}
}
diff --git a/Documentation/security/tamper-counters.rst b/Documentation/security/tamper-counters.rst
index bb79b412..773e0564 100644
--- a/Documentation/security/tamper-counters.rst
+++ b/Documentation/security/tamper-counters.rst
@@ -9,7 +9,9 @@ Tamper counters
===============
Each point at which one of shirudo's guards refuses a caller has a
-counter. The guard adds one to it when it refuses. The counters live in
+counter. The guard adds one to it when it refuses. One point counts
+what it lets through: ``SealSignal``, a signal to a shirudo task from a
+task without authority, which no hook refuses. The counters live in
the array map ``shirudo_tamper``, which ``init`` creates, freezes and
pins at ``/run/shirudo/bpffs/tamper`` at every boot, so they count this
boot's refusals. No task resets them from userspace; only the hooks add
@@ -162,6 +164,11 @@ counter.
- perf event bound to a shirudo task
- ``lsm/perf_event_alloc``
- ``EACCES``
+ * - ``SealSignal``
+ - a signal other than 0 to a shirudo task from a task without
+ authority; let through
+ - ``lsm/task_kill``
+ - none
* - ``ExecTraced``
- exec of shirudo by a traced task
- ``lsm.s/bprm_check_security`` in the seal object, and
@@ -264,7 +271,7 @@ image, the way the drop-in that ``shirudo-gen-runtime --unit-output``
generates starts ``init``. A binary outside the runtime image cannot
open the counter map, and its attempt moves ``ObjGet``.
-``shirudo status`` prints the section ``Tamper attempts (refused this
+``shirudo status`` prints the section ``Tamper attempts (this
boot):`` with one line per counter that is not zero: its name, its
count and its meaning. It prints ``none`` when every counter is zero,
and ``(none recorded: init has not pinned the counters this boot)``
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 7e219ea3..8971f783 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -762,6 +762,9 @@ An authorized process is protected against being taken over:
- ``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 a
task before the exec that marks it, are not checked (D9).
+- ``lsm/task_kill`` counts a signal to a marked task from a task
+ without authority (``SealSignal``) and lets it through: root can stop
+ a command (R2, U17), and the count shows that it did.
- The exec of a runtime file by a traced task is refused
(``ExecTraced``), and so is one under a seccomp filter, without a
counter.
@@ -800,7 +803,7 @@ An authorized process is protected against being taken over:
:Counters: ``SealWrite``, ``SealUnlink``, ``SealRename``,
``SealSetattr``, ``SealXattr``, ``SealLabel``, ``SealEntry``,
``SealCopyUp``, ``KeyringWrite``, ``SealPtrace``, ``SealPerf``,
- ``ExecTraced``, ``ExeIdentity``
+ ``SealSignal``, ``ExecTraced``, ``ExeIdentity``
:Tests: ``t6001``, ``t6006``, ``t6007``, ``t6110``, ``t6111``,
``t6112``, ``t6113``, ``t6114``, ``t6115``, ``t6118``, ``t6123``,
``t6124``, ``t6127``, ``t6129``, ``t6131``, ``t6133``, ``t6134``,
@@ -891,7 +894,8 @@ leaves. A load whose archive copy or extension fails is undone, pins
and archive. An unload or a purge is measured before it detaches, so an
interruption leaves a register that claims more than happened, never a
detach it does not know. A load that root stops between its pins and
-its extend, with ``SIGKILL`` say, leaves pins the register does not
+its extend, with ``SIGKILL`` say (counted as ``SealSignal``), leaves
+pins the register does not
cover and the upatch attached: ``shirudo status`` reports them
(``UpatchesMeasured``, verdict ``tampered``) and the next upatch
command, ``bpm``'s included, undoes them before it acts. A measuring
@@ -1280,9 +1284,10 @@ R2 The command interface of the runtime binary is the boundary
signed artifact (R16), apply any published directive (R1), drain a
serializer with ``shirudo upatch map`` and send the output where it
chooses, and hold the lock files shirudo serializes on. No hook
- covers signals, so root can also stop a running command, which
- keeps open whatever descriptors it holds (U17); a load stopped
- before its extend is reported and undone (T5).
+ refuses signals, so root can also stop a running command, which
+ ``lsm/task_kill`` counts (``SealSignal``) and which keeps open
+ whatever descriptors it holds (U17); a load stopped before its
+ extend is reported and undone (T5).
``CAP_SYS_RESOURCE`` can rewrite a process's executable link, which
``lsm/task_prctl`` refuses and the mark does not depend on. The
initrd's bootstrap binary and the memory of authorized tasks stay
@@ -1709,7 +1714,8 @@ U16 Boot restore is not all or nothing
U17 A stopped runtime command keeps its descriptors
:Affects: The descriptor checks of T2.
:Consequence: Runtime commands open link pins for short checks. No
- hook covers signals, so root can stop such a command while it
+ hook refuses signals, ``lsm/task_kill`` only counts them
+ (``SealSignal``), so root can stop such a command while it
holds a link descriptor, and that link then stays attached after
its pin is removed by an unload or a revocation.
:Status: Code-path reading, not reproduced.
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index 9d9a052a..8dc7f86f 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -162,7 +162,7 @@ Check enforcement
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config dc90bacc356f.. is active
- Tamper attempts (refused this boot):
+ Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
MapCreate 1 map creation by another executable
BpfCommand 8 detach, update, delete or unclassified bpf() command
diff --git a/bpf/lib/tamper.h b/bpf/lib/tamper.h
index 2605d8c5..49214403 100644
--- a/bpf/lib/tamper.h
+++ b/bpf/lib/tamper.h
@@ -3,7 +3,8 @@
* Copyright (c) 2026 Authors of shirudo
*
* The tamper counters: one per point at which a guard refuses a caller,
- * counted where the refusal happens and read back by `shirudo status`.
+ * counted where the refusal happens, and one, SealSignal, at which the
+ * seal counts what it lets through; read back by `shirudo status`.
* On the BPF side, include after vmlinux.h and the libbpf headers.
*/
@@ -47,6 +48,7 @@ enum tamper_point {
TAMPER_KEXEC,
TAMPER_TPM_EXTEND,
TAMPER_OBJ_GET,
+ TAMPER_SEAL_SIGNAL,
TAMPER_MAX
};
@@ -58,8 +60,7 @@ struct {
__type(value, __u64);
} shirudo_tamper SEC(".maps");
-static __always_inline int shirudo_tamper_deny(enum tamper_point point,
- int err)
+static __always_inline void shirudo_tamper_count(enum tamper_point point)
{
__u32 key = point;
__u64 *count;
@@ -67,6 +68,12 @@ static __always_inline int shirudo_tamper_deny(enum tamper_point point,
count = bpf_map_lookup_elem(&shirudo_tamper, &key);
if (count)
__sync_fetch_and_add(count, 1);
+}
+
+static __always_inline int shirudo_tamper_deny(enum tamper_point point,
+ int err)
+{
+ shirudo_tamper_count(point);
return err;
}
#endif /* __BPF__ */
diff --git a/bpf/seal.c b/bpf/seal.c
index 725b4eec..a8dd29cf 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -254,6 +254,25 @@ int BPF_PROG(shirudo_seal_ptrace_access_check,
return 0;
}
+/*
+ * A signal from outside is let through: root may end a command that
+ * hangs, and systemd stops the runs its timers start. It is counted, so
+ * that a load stopped between its pins and its extend shows in the
+ * counters before the next command finds what it left. Signal 0 only
+ * probes.
+ */
+SEC("lsm/task_kill")
+int BPF_PROG(shirudo_seal_task_kill, struct task_struct *p,
+ struct kernel_siginfo *info, int sig, const struct cred *cred,
+ int ret)
+{
+ if (ret)
+ return ret;
+ if (sig && shirudo_marked(p) && !seal_task_authorized())
+ shirudo_tamper_count(TAMPER_SEAL_SIGNAL);
+ return 0;
+}
+
SEC("lsm.s/file_open")
int BPF_PROG(shirudo_seal_file_open, struct file *file, int ret)
{
diff --git a/builtin-status.c b/builtin-status.c
index 102b9d4a..fd5d2288 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -1214,7 +1214,7 @@ int cmd_status(int argc, const char **argv)
json_kv_bool(&e, "bpffs_mounted", assets.bpffs_mounted);
json_obj_close(&e);
/*
- * What the guards refused this boot, every counter by name
+ * What the guards counted this boot, every counter by name
* so a collector's keys stay the same from one record to
* the next; null until init has pinned the map.
*/
@@ -1447,7 +1447,7 @@ int cmd_status(int argc, const char **argv)
printf("\n");
conditions_print(conds, nc);
- printf("\nTamper attempts (refused this boot):\n");
+ printf("\nTamper attempts (this boot):\n");
if (tamper_rc == -ENOENT)
printf(" (none recorded: init has not pinned the counters "
"this boot)\n");
diff --git a/testing/functional/tamperproof/t6143-unmeasured-load.sh b/testing/functional/tamperproof/t6143-unmeasured-load.sh
index bfa29a1c..cd0b80f3 100755
--- a/testing/functional/tamperproof/t6143-unmeasured-load.sh
+++ b/testing/functional/tamperproof/t6143-unmeasured-load.sh
@@ -3,9 +3,10 @@
# Copyright (c) 2026 Authors of shirudo
#
# t6143 -- a load stopped between its pins and its extend cannot keep a
-# upatch running unmeasured: status reports the pins the register does
-# not cover as tampered, and the next upatch command, a load or an
-# unload of another upatch, undoes them before it acts.
+# upatch running unmeasured: the signal that stopped it is counted,
+# status reports the pins the register does not cover as tampered, and
+# the next upatch command, a load or an unload of another upatch, undoes
+# them before it acts.
cd "$(dirname "$0")/../.."
. ./integration-lib.sh
@@ -35,6 +36,13 @@ for f in "$LOAD" "$UNLOAD" "$FIXTURES/$OTHER.upatch" \
[ -s "$f" ] || test_skip_all "missing fixture $f"
done
[ -s "$EVENTLOG" ] || test_skip_all "no eventlog"
+counter() {
+ "$SHIRUDO_BIN" status --json | python3 -c '
+import json, sys
+print(json.load(sys.stdin)["tamper_attempts"]["counters"][sys.argv[1]])
+' "$1"
+}
+before=$(counter SealSignal) || test_skip_all "no tamper counters"
# An earlier test of the family may have left either loaded.
[ ! -e "$PINDIR" ] || "$SHIRUDO_BIN" upatch unload "$UNLOAD" >/dev/null 2>&1
[ ! -e "$OTHERDIR" ] ||
@@ -86,6 +94,9 @@ test_expect_success 'a load stopped before its extend leaves pins without a reco
[ -e "$PINDIR/link" ] &&
[ ! -e "$ARCHIVE" ]
'
+test_expect_success 'the signal that stopped the load is counted as SealSignal' '
+ [ "$(counter SealSignal)" -ge $((before + 1)) ]
+'
test_expect_success 'status reports the unmeasured pins as tampered' '
"$SHIRUDO_BIN" status --json >"$W/status.json" 2>/dev/null &&
measured_condition "$W/status.json" >"$W/cond" &&
diff --git a/util/image_guards.c b/util/image_guards.c
index ad92a77c..17ceab1c 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -61,6 +61,7 @@ shirudo_seal_guards[SEAL_HOOK_COUNT] = {
SEAL_PTRACE_PIN },
{ "shirudo_seal_perf_event_alloc",
SEAL_PERF_PIN },
+ { "shirudo_seal_task_kill", SEAL_TASK_KILL_PIN },
};
const struct image_guard
diff --git a/util/image_guards.h b/util/image_guards.h
index 3ba30be7..26cb8b1a 100644
--- a/util/image_guards.h
+++ b/util/image_guards.h
@@ -8,7 +8,7 @@
#include <stdint.h>
-#define SEAL_HOOK_COUNT 26
+#define SEAL_HOOK_COUNT 27
#define IMAGE_SEAL_HOOK_COUNT 2
#define MOUNT_HOOK_COUNT 5
#define OBSERVER_HOOK_COUNT 9
diff --git a/util/paths.h b/util/paths.h
index e2933fdc..8ca3c9b8 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -81,6 +81,7 @@
#define SEAL_TASK_ALLOC_PIN BPFFS_DIR "/seal_task_alloc_link"
#define SEAL_PTRACE_PIN BPFFS_DIR "/seal_ptrace_access_check_link"
#define SEAL_PERF_PIN BPFFS_DIR "/seal_perf_event_alloc_link"
+#define SEAL_TASK_KILL_PIN BPFFS_DIR "/seal_task_kill_link"
#define SEAL_UNLINK_PIN BPFFS_DIR "/seal_inode_unlink_link"
#define SEAL_RENAME_PIN BPFFS_DIR "/seal_inode_rename_link"
#define SEAL_SETATTR_PIN \
diff --git a/util/tamper.c b/util/tamper.c
index 48546519..41a237cc 100644
--- a/util/tamper.c
+++ b/util/tamper.c
@@ -92,6 +92,8 @@ static const struct {
"extension of shirudo's TPM NV index by another executable" },
[TAMPER_OBJ_GET] = { "ObjGet",
"pin, map or link opened by another executable" },
+ [TAMPER_SEAL_SIGNAL] = { "SealSignal",
+ "signal to a shirudo task (let through)" },
};
const char *tamper_name(enum tamper_point point)