eBPF-based security platform
seal: keep the kernel from stopping a command by its limits
Daniel Borkmannc81f3eb171d0
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 8def7256..71c6cf8d 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -515,6 +515,10 @@ signed config image.- From a namespace without ``/run``, an ``rmdir`` and a rename ofthe directory init's ``/run`` covers are refused and counted, andthe private bpffs stays mounted+ * - ``t6156-rlimit``+ - A command writes past the file size limit it was started with,+ outlives an interval timer set before its exec, and refuses+ another task's ``prlimit``, counted as ``SealRlimit````bpm`` (7)~~~~~~~~~~~@@ -1042,6 +1046,8 @@ tests assert that a refusal moves its counter:- ``t6153``, on a kernel with XFS* - ``Lockdown``- ``t6154``+ * - ``SealRlimit``+ - ``t6156``* - ``Kexec``- ``t6126``diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex 680baae5..8a78bfa6 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -496,7 +496,15 @@ when the record it needs is missing.- None- ``SealSignal``- Which signal is an attack: a stop by root and one by systemd- count alike (R2).+ count alike (R2). The kernel's own signals and the freezer pass+ no hook.+ * - ``lsm/task_setrlimit`` (``seal``)+ - A change of a marked task's resource limits by another task+ without authority, ``prlimit``, which could have the kernel+ signal it. The task resets its own limits when it starts.+ - ``EPERM``+ - ``SealRlimit``+ - Closed.* - ``lsm/ptrace_access_check`` (``seal``)- Every ptrace access mode against a marked task, which coversattach, ``/proc/<pid>/mem``, ``pidfd_getfd()``,diff --git a/Documentation/internals/kernel-interfaces.rst b/Documentation/internals/kernel-interfaces.rstindex f58d0152..7f440f03 100644--- a/Documentation/internals/kernel-interfaces.rst+++ b/Documentation/internals/kernel-interfaces.rst@@ -299,7 +299,8 @@ LSM hooks``inode_rmdir``, ``inode_setattr``, ``inode_setxattr``,``inode_removexattr``, ``inode_post_setxattr``,``inode_post_removexattr`` (all sleepable); ``task_alloc``,- ``task_kill``, ``ptrace_access_check``, ``socket_post_create``,+ ``task_kill``, ``task_setrlimit``, ``ptrace_access_check``,+ ``socket_post_create``,``inode_init_security``, ``mmap_file``, ``file_mprotect``- ``seal``- None@@ -425,6 +426,11 @@ Process setup and prctl- Drops the personality flags the caller passed down, ``UNAME26``among them, which would have ``uname()`` report a 2.6 release tothe tree selector. A failure ends the command.+ * - ``setrlimit(RLIMIT_FSIZE, RLIMIT_CPU)`` to unlimited,+ ``setitimer()`` of the three interval timers to zero+ - Exec keeps the limits and timers the caller set, with which the+ kernel would stop the command by ``SIGXFSZ``, ``SIGXCPU`` or+ ``SIGALRM``. A failure ends the command.* - ``prctl(PR_SET_DUMPABLE, 0)``, ``prctl(PR_SET_NO_NEW_PRIVS, 1)``,``prctl(PR_SET_PTRACER, 0)``- Process hardening before every command.diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rstindex 57484aa1..841c27a1 100644--- a/Documentation/internals/seal.rst+++ b/Documentation/internals/seal.rst@@ -162,7 +162,13 @@ refuses a perf event bound to a marked task (``SealPerf``).``lsm/task_kill`` lets a signal to a marked task through, since rootmay end a command that hangs and systemd stops the runs its timersstart, and counts one from a task without authority (``SealSignal``),-so that a command stopped on purpose shows in the counters.+so that a command stopped on purpose shows in the counters. The+kernel's own signals pass no hook: those a file size or CPU time limit+or an interval timer raise, the command forestalls by resetting its+limits and disarming the timers it inherited when it starts, and+``lsm/task_setrlimit`` refuses another task a change of its limits+(``SealRlimit``). ``SIGKILL`` from ``cgroup.kill`` or the OOM killer,+``SIGPIPE`` and the cgroup freezer stay uncounted.``lsm/mmap_file`` and ``lsm/file_mprotect`` refuse a marked taskexecutable memory that is writable or that does not come from theruntime image. ``bpf2`` makes every exec of a runtime file a secure-exec,diff --git a/Documentation/reference/cli/shirudo.rst b/Documentation/reference/cli/shirudo.rstindex 833168fa..ab695344 100644--- a/Documentation/reference/cli/shirudo.rst+++ b/Documentation/reference/cli/shirudo.rst@@ -86,7 +86,8 @@ Every invocation goes through the same steps before the command runs:#. Standard input, output and error that are closed are reopened on``/dev/null``.#. The process hardens itself: it drops the personality flags of its- caller, is not dumpable, sets ``no_new_privs``, writes no core file,+ caller, lifts its file size and CPU time limits, disarms its interval+ timers, is not dumpable, sets ``no_new_privs``, writes no core file,loads no OpenSSL configuration file, resolves host names through``files`` and ``dns`` only and locks all its memory with``mlockall()``. When the lock fails, ``shirudo`` printsdiff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rstindex 1b07be9b..54027a04 100644--- a/Documentation/reference/cli/status.rst+++ b/Documentation/reference/cli/status.rst@@ -408,7 +408,7 @@ Print the keepalive body of the same target, which follows no tree:.. code-block:: consoletarget# shirudo status --keepalive- {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}+ {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}Add this boot's eventlog to the report:diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex b48ae21f..5ebe94b4 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -331,9 +331,10 @@ every verdict, ``tampered`` included. Parse ``.status`` of* - Unknown or ambiguous command- 1.* - Any command- - 1 when the personality cannot be reset (``hardening: cannot reset- the personality``), when ``mlockall()`` fails (``hardening: cannot- lock process memory``) or when the gate refuses.+ - 1 when the hardening fails (``hardening: cannot reset the+ personality``, ``cannot reset the resource limits``, ``cannot+ disarm the interval timers``, ``cannot lock process memory``) or+ when the gate refuses.* - ``genkey``- 0; 1 on failure or when keys exist without ``--force``; 2 for anunknown option.diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rstindex 0a90f2a1..1a5a1e88 100644--- a/Documentation/reference/formats/status-json.rst+++ b/Documentation/reference/formats/status-json.rst@@ -960,7 +960,8 @@ indented here:"SealUprobe": 0,"ExecShared": 0,"XattrHandle": 0,- "Lockdown": 0+ "Lockdown": 0,+ "SealRlimit": 0}},"config": {@@ -1017,7 +1018,7 @@ of the same target read:"ExecTraced": 0, "SealEntry": 0, "PerfAttach": 0, "PinEntry": 0,"SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 1,"SealSignal": 0, "SealCoreDump": 0, "SealUprobe": 0,- "ExecShared": 0, "XattrHandle": 0, "Lockdown": 0+ "ExecShared": 0, "XattrHandle": 0, "Lockdown": 0, "SealRlimit": 0}}diff --git a/Documentation/security/tamper-counters.rst b/Documentation/security/tamper-counters.rstindex 55588506..0d5c3643 100644--- a/Documentation/security/tamper-counters.rst+++ b/Documentation/security/tamper-counters.rst@@ -219,7 +219,11 @@ counter.* - ``SealSignal``- signal to a shirudo task (let through)- ``lsm/task_kill``: a signal other than 0 to a marked task from a- task without authority; the signal is delivered+ task without authority; the signal is delivered. The kernel's+ own signals pass no hook and are not counted: ``SIGKILL`` from+ ``cgroup.kill`` or the OOM killer, ``SIGPIPE`` on a pipe whose+ reader is gone. Nor is the cgroup freezer, which stops a task+ without a signal- none* - ``SealCoreDump``- core dump of a shirudo task, which acts without authority@@ -248,6 +252,12 @@ counter.while another process shares the task's root and workingdirectory (``CLONE_FS``)- ``EACCES``+ * - ``SealRlimit``+ - resource limit of a shirudo task changed by another task+ - ``lsm/task_setrlimit``: ``prlimit`` on a marked task from a task+ without authority, which could have the kernel stop it with+ ``SIGXFSZ`` or ``SIGXCPU``+ - ``EPERM``* - ``Lockdown``- change or read of the running kernel that lockdown refuses- ``lsm/locked_down``: every reason of integrity mode but modulediff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 1eed97f4..73d05ba2 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -849,7 +849,11 @@ An authorized process is protected against being taken over:task before the exec that marks it, are not checked (D9).- ``lsm/task_kill`` counts a signal to a marked task from a taskwithout authority (``SealSignal``) and lets it through: root can stop- a command (R2, U17), and the count shows that it did.+ a command (R2, U17), and the count shows that it did. A command resets+ its file size and CPU time limits and disarms its interval timers+ when it starts, since exec keeps them and the kernel would signal it+ by them, and ``lsm/task_setrlimit`` refuses another task a change of+ its limits (``SealRlimit``, ``t6156``).- The exec of a runtime file by a traced task is refused(``ExecTraced``), and so is one by a task that shares its root andworking directory with another process (``ExecShared``), which could@@ -896,6 +900,7 @@ An authorized process is protected against being taken over:``lsm.s/bprm_check_security``, ``lsm.s/bprm_committed_creds``,``lsm/task_alloc``, ``lsm/bprm_check_security``,``lsm/ptrace_access_check``, ``lsm/perf_event_alloc``,+ ``lsm/task_setrlimit``,``lsm/task_prctl``, ``lsm/mmap_file``, ``lsm/file_mprotect``; insupport, ``lsm.s/bprm_creds_for_exec`` and ``lsm/socket_post_create``carry the policy bits, ``lsm.s/inode_post_setxattr`` and@@ -907,14 +912,14 @@ An authorized process is protected against being taken over::Counters: ``SealWrite``, ``SealUnlink``, ``SealRename``,``SealSetattr``, ``SealXattr``, ``SealLabel``, ``SealEntry``,``SealCopyUp``, ``KeyringWrite``, ``SealPtrace``, ``SealPerf``,- ``SealSignal``, ``SealCoreDump``, ``SealUprobe``, ``ExecTraced``,- ``ExecShared``, ``XattrHandle``,+ ``SealSignal``, ``SealCoreDump``, ``SealUprobe``, ``SealRlimit``,+ ``ExecTraced``, ``ExecShared``, ``XattrHandle``,``ExeIdentity``:Tests: ``t6001``, ``t6006``, ``t6007``, ``t6110``, ``t6111``,``t6112``, ``t6113``, ``t6114``, ``t6115``, ``t6118``, ``t6123``,``t6124``, ``t6127``, ``t6129``, ``t6131``, ``t6133``, ``t6134``,``t6135``, ``t6136``, ``t6137``, ``t6144``, ``t6145``, ``t6146``,- ``t6149``, ``t6150``, ``t6152``, ``t6153``+ ``t6149``, ``t6150``, ``t6152``, ``t6153``, ``t6156``:Residual: R2, R19, R22T4 Substituting artifacts@@ -1476,7 +1481,9 @@ R2 The command interface of the runtime binary is the boundaryrefuses signals, so root can also stop a running command, which``lsm/task_kill`` counts (``SealSignal``) and which keeps openwhatever descriptors it holds (U17); a load stopped before its- extend is reported and undone (T5).+ extend is reported and undone (T5). A stop by the kernel, through+ ``cgroup.kill``, the OOM killer, a pipe root closes or the cgroup+ freezer, passes no hook and is not counted.``CAP_SYS_RESOURCE`` can rewrite a process's executable link, which``lsm/task_prctl`` refuses and the mark does not depend on. Theinitrd's bootstrap binary and the memory of authorized tasks stay@@ -1940,7 +1947,8 @@ U17 A stopped runtime command keeps its descriptors:Affects: The descriptor checks of T2.:Consequence: Runtime commands open link pins for short checks. Nohook refuses signals, ``lsm/task_kill`` only counts them- (``SealSignal``), so root can stop such a command while it+ (``SealSignal``), and the kernel's own signals and the cgroup+ freezer pass uncounted, so root can stop such a command while itholds a link descriptor, and that link then stays attached afterits pin is removed by an unload or a revocation.:Status: Code-path reading, not reproduced.diff --git a/bpf/lib/tamper.h b/bpf/lib/tamper.hindex 242b2724..d0688f7a 100644--- a/bpf/lib/tamper.h+++ b/bpf/lib/tamper.h@@ -54,6 +54,7 @@ enum tamper_point {TAMPER_EXEC_SHARED,TAMPER_XATTR_HANDLE,TAMPER_LOCKDOWN,+ TAMPER_SEAL_RLIMIT,TAMPER_MAX};diff --git a/bpf/seal.c b/bpf/seal.cindex 3eb19175..1b91059c 100644--- a/bpf/seal.c+++ b/bpf/seal.c@@ -291,6 +291,23 @@ int BPF_PROG(shirudo_seal_task_kill, struct task_struct *p,return 0;}+/*+ * A file size or CPU time limit has the kernel itself signal a command,+ * which task_kill never sees. A command resets its own limits when it+ * starts, and no one else changes them while it runs.+ */+SEC("lsm/task_setrlimit")+int BPF_PROG(shirudo_seal_task_setrlimit, struct task_struct *p,+ unsigned int resource, struct rlimit *new_rlim, int ret)+{+ if (ret)+ return ret;+ if (p == bpf_get_current_task_btf() || !shirudo_marked(p) ||+ seal_task_authorized())+ return 0;+ return shirudo_tamper_deny(TAMPER_SEAL_RLIMIT, -EPERM);+}+SEC("lsm.s/file_open")int BPF_PROG(shirudo_seal_file_open, struct file *file, int ret){diff --git a/testing/fixtures/keepalive/node-a-1.0.0.json b/testing/fixtures/keepalive/node-a-1.0.0.jsonindex f5e8d052..c27c8b3d 100644--- a/testing/fixtures/keepalive/node-a-1.0.0.json+++ b/testing/fixtures/keepalive/node-a-1.0.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-a-1.1.0.json b/testing/fixtures/keepalive/node-a-1.1.0.jsonindex f54bc154..7e6be6df 100644--- a/testing/fixtures/keepalive/node-a-1.1.0.json+++ b/testing/fixtures/keepalive/node-a-1.1.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.0.0.json b/testing/fixtures/keepalive/node-b-1.0.0.jsonindex 21a0df0e..aca50f27 100644--- a/testing/fixtures/keepalive/node-b-1.0.0.json+++ b/testing/fixtures/keepalive/node-b-1.0.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.1.0.json b/testing/fixtures/keepalive/node-b-1.1.0.jsonindex 6bbfccb3..24ce8552 100644--- a/testing/fixtures/keepalive/node-b-1.1.0.json+++ b/testing/fixtures/keepalive/node-b-1.1.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/ops-16.json b/testing/fixtures/keepalive/ops-16.jsonindex 9df18416..bb5e6ef8 100644--- a/testing/fixtures/keepalive/ops-16.json+++ b/testing/fixtures/keepalive/ops-16.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/quotes.tsv b/testing/fixtures/keepalive/quotes.tsvindex ba594b47..066d53e6 100644--- a/testing/fixtures/keepalive/quotes.tsv+++ b/testing/fixtures/keepalive/quotes.tsv@@ -1,4 +1,4 @@-node-a-1.0.0.json /1RDR4AYACIAC9r407nH/GvK8V9whbAN5W7sd2p12DUEBzWU9gX+X5F+ACDBq8Ey3FnZcZW5twnTWwgqghfDQfxSIJGiAXQLM1JgyAAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgJa6K6HT4NUOIpYrKZMT1WSAIqTbPTZSPyJNlol0Oz+UAIK+McjKFWyZIwDzN6oOG2Gpbfj1yycCFxNfey3UUDEB5 ACMACwAFAHIAAAAQABgACwADABAAIFgoZ+6XpoE3/sWCmSM1pcwh/u/2dcY1yp9JTBykdK4VACDxEkc5rBHAtnOjNZU5z2JcpfeQoxoI4EAi7B82iAxENQ== c1abc132dc59d97195b9b709d35b082a8217c341fc522091a201740b335260c8-node-a-1.1.0.json /1RDR4AYACIAC9r407nH/GvK8V9whbAN5W7sd2p12DUEBzWU9gX+X5F+ACBL5BSxrlAgv/czzo6Npa3nDCgBplxNeWkiz0a377iOZAAAAAAAAAAcAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgvPwaGD+j3TtrVgxHJ0t5fPKmaBMRJt9nZ0a7QTNEugAAIOdeUmwxksi9TCKjgMZfipjvlT8ViuDgXWrqEXsP68Zk ACMACwAFAHIAAAAQABgACwADABAAIFgoZ+6XpoE3/sWCmSM1pcwh/u/2dcY1yp9JTBykdK4VACDxEkc5rBHAtnOjNZU5z2JcpfeQoxoI4EAi7B82iAxENQ== 4be414b1ae5020bff733ce8e8da5ade70c2801a65c4d796922cf46b7efb88e64-node-b-1.0.0.json /1RDR4AYACIAC4uo0JNu1oyV5LHEf1eoRpvUYhLfP7wWm47zs8F5wYMvACAVvcdjo5tKQjrKpnWHIVA5iHp6dV4jpXcSpKUNcei55AAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgr+a9fOKJepTH4mNlKNdZhkwhKmLoIu6EIpZu6u4tiwcAIPklMlQuhF+ETAdpoWPnvFLHUDhW6nK2lCMUXQuIOwlV ACMACwAFAHIAAAAQABgACwADABAAIBx9ipOlM3Ji7QgU2dFw5fZX/LoFvN5xtPNstPrsmqHIACDYv6gg5uomNm5wuoUI/1N7Eetlrgr8oGdHCyw//Vmm9Q== 15bdc763a39b4a423acaa67587215039887a7a755e23a57712a4a50d71e8b9e4-node-b-1.1.0.json /1RDR4AYACIAC4uo0JNu1oyV5LHEf1eoRpvUYhLfP7wWm47zs8F5wYMvACBd2XyVD/RPGFJZ3rDyPRS/iKgt8hpf6SI0iBqhBM9/GQAAAAAAAAAcAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgVaTtxFQQaKrUent++6r+Z8joRGOiOMzyEAIiJ53lAKMAICQtAIwuTtYId300XkTrrKvI9o4Zb0/fXTPwKsw6SK99 ACMACwAFAHIAAAAQABgACwADABAAIBx9ipOlM3Ji7QgU2dFw5fZX/LoFvN5xtPNstPrsmqHIACDYv6gg5uomNm5wuoUI/1N7Eetlrgr8oGdHCyw//Vmm9Q== 5dd97c950ff44f185259deb0f23d14bf88a82df21a5fe92234881aa104cf7f19+node-a-1.0.0.json /1RDR4AYACIACxNJbfFIbCzNEVI4hr7MwUEl2i/dk2o14cQnfgA11ZJiACClpyPhqCULTp7znABpnqXOsUGVgsw+AzUrr/mbPZVxxQAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgmlgt0HOBFHdOE1O8XsEor2yjIjj5bq74a8NeIRpuujMAIKM4n+odypRP6CAoKTSLGp2xk9y2koqwauqR9fuZ0n4v ACMACwAFAHIAAAAQABgACwADABAAIAB0eTd0WyLf8saUGUqdVbbi8+dRaGLQHYwB7tOxf/TFACAzdeo6El8az+BGQowcDXmiLbZxNGeyYWv1lRtuXTuvEg== a5a723e1a8250b4e9ef39c00699ea5ceb1419582cc3e03352baff99b3d9571c5+node-a-1.1.0.json /1RDR4AYACIACxNJbfFIbCzNEVI4hr7MwUEl2i/dk2o14cQnfgA11ZJiACAVyBxfaY9/t3NO8neIGvgExVQnkt1HHUqf1hvuRBvaYgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgepyM0Gp9nljLdTTCMl4ipUVcMQ6NUKiZq4Vr253dGzcAIBM5wF2mqt1YqA6pk5Jd49Fwnl5yhFH125Oxo+xyaBCF ACMACwAFAHIAAAAQABgACwADABAAIAB0eTd0WyLf8saUGUqdVbbi8+dRaGLQHYwB7tOxf/TFACAzdeo6El8az+BGQowcDXmiLbZxNGeyYWv1lRtuXTuvEg== 15c81c5f698f7fb7734ef277881af804c5542792dd471d4a9fd61bee441bda62+node-b-1.0.0.json /1RDR4AYACIAC0uSx5ABSfNXIGebbaY8HpgpjnZdmiUGoDOMSLFbyFNVACBGpG64qfutWE2Ya4QJ+wVtoClds0UXHnWbB6OZqcVtfAAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgwoeZG/DOwdM3N/dbOKjIyYLefUcZqVORWKlPZPldt48AIIXAyYHWjeHkbQOBZ5g+KaMoPS/j7AnRaM2EtQqYb1Dd ACMACwAFAHIAAAAQABgACwADABAAIGBI6SBUTMr4QsNzP2P3XZGifD6Iz6ueQRTOlU08ZtXyACBOOmUl0mrqCMlUF7EN+0AxeO5ynxm9gHnunTpRWWSLIg== 46a46eb8a9fbad584d986b8409fb056da0295db345171e759b07a399a9c56d7c+node-b-1.1.0.json /1RDR4AYACIAC0uSx5ABSfNXIGebbaY8HpgpjnZdmiUGoDOMSLFbyFNVACALvQW8P8t/OcFSDoK956JiA7rvICZ6MqNDONOqueXtVgAAAAAAAAAaAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgIB1R21P0AU+7BdGJONnLmpzAoo5MlnldmiwpAKdj/cYAIBQ8YA2P58uoICyX/FEl4GMh4/Xo256ojqfOQGfSBAys ACMACwAFAHIAAAAQABgACwADABAAIGBI6SBUTMr4QsNzP2P3XZGifD6Iz6ueQRTOlU08ZtXyACBOOmUl0mrqCMlUF7EN+0AxeO5ynxm9gHnunTpRWWSLIg== 0bbd05bc3fcb7f39c1520e82bde7a26203baef20267a32a34338d3aab9e5ed56diff --git a/testing/fixtures/keepalive/recompute.py b/testing/fixtures/keepalive/recompute.pyindex 428d3aa9..104746da 100755--- a/testing/fixtures/keepalive/recompute.py+++ b/testing/fixtures/keepalive/recompute.py@@ -24,7 +24,7 @@ BODY_KEYS = ["projection_root", "mask", "set_sha256", "count", "not_ok",]CANONICAL_KEYS = ["seq", "op", "id", "selector", "artifact"]-TAMPER_COUNTERS = 42+TAMPER_COUNTERS = 43ALL_OK = 0x1555OPERATION_DIGESTS = [@@ -51,9 +51,9 @@ MASKS = [# The body the example pages print for node A after release 1.1.0: six# conditions and no image keys.-PAGE_BODY_LEN = 742+PAGE_BODY_LEN = 744PAGE_BODY_SHA256 = \- "0c0f36b05c35208895de17fe355810a9c6632c907fde8e3eb9cbbf20f4882e8e"+ "3b7aac94ab7c0145070d6fd82862a0b98e2f20f8da1e34f9db2d570ae926215b"PAGE_COND = 0x555VERSION_ID = "d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f"diff --git a/testing/functional/tamperproof/t6156-rlimit.sh b/testing/functional/tamperproof/t6156-rlimit.shnew file mode 100755index 00000000..0b278892--- /dev/null+++ b/testing/functional/tamperproof/t6156-rlimit.sh@@ -0,0 +1,84 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t6156 -- the kernel signals a command by the limits and interval timers+# it runs with, and no hook sees those signals: a command lifts its file+# size and CPU time limits and disarms its interval timers when it+# starts, and root cannot change the limits of one that runs, which+# counts as SealRlimit. Counters are read while no command holds the+# config lock.++cd "$(dirname "$0")/../.."+. ./integration-lib.sh+target_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"+W=$(mktemp -d) || test_skip_all "cannot make a scratch directory"+PID=+cleanup() {+ if [ -n "$PID" ] && [ -d "/proc/$PID" ]; then+ fifo_release "$W/fifo" || :+ wait "$PID" 2>/dev/null || :+ fi+ rm -rf "$W"+}+trap cleanup EXIT+counter() {+ "$SHIRUDO_BIN" status --json | python3 -c '+import json, sys+print(json.load(sys.stdin)["tamper_attempts"]["counters"][sys.argv[1]])+' "$1"+}+# Wait for pid $1 to be shirudo asleep, as a command blocked on its fifo.+sleeping() {+ i=0+ while [ "$i" -lt 50 ]; do+ [ -d "/proc/$1" ] || return 1+ [ "$(awk '{print $2 $3}' "/proc/$1/stat" 2>/dev/null)" = "(shirudo)S" ] &&+ return 0+ sleep 0.1+ i=$((i + 1))+ done+ return 1+}+before=$(counter SealRlimit) || test_skip_all "no tamper counters"+mkfifo "$W/fifo" || test_skip_all "cannot make a fifo"++test_expect_success 'a command writes past the file size limit it was given' '+ (ulimit -f 1 && "$SHIRUDO_BIN" status --json >"$W/status.json") &&+ [ "$(wc -c <"$W/status.json")" -gt 4096 ]+'+test_expect_success 'root cannot change the limits of a running command' '+ "$SHIRUDO_BIN" bpm info "$W/fifo" >/dev/null 2>&1 &+ PID=$! &&+ sleeping "$PID" &&+ python3 -c "+import errno, resource, sys+try:+ resource.prlimit(int(sys.argv[1]), resource.RLIMIT_FSIZE, (1, 1))+ sys.exit(1)+except OSError as e:+ sys.exit(0 if e.errno == errno.EPERM else 2)+" "$PID" &&+ fifo_release "$W/fifo" &&+ { wait "$PID" || :; } &&+ PID= &&+ [ "$(counter SealRlimit)" -gt "$before" ]+'+test_expect_success 'an interval timer set before exec does not stop it' '+ python3 - "$SHIRUDO_BIN" "$W/fifo" <<-\PY &&+ import os, signal, subprocess, sys, time+ child = subprocess.Popen(+ [sys.argv[1], "bpm", "info", sys.argv[2]],+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,+ preexec_fn=lambda: signal.setitimer(signal.ITIMER_REAL, 0.3))+ time.sleep(1.5)+ alive = child.poll() is None+ fd = os.open(sys.argv[2], os.O_WRONLY | os.O_NONBLOCK)+ os.close(fd)+ child.wait()+ sys.exit(0 if alive and child.returncode != -signal.SIGALRM else 1)+ PY+ :+'+test_donediff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex 2c5f903c..6e98532c 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -56,7 +56,7 @@ log-escape --unwind 7 LEN=0-5json-emit-string --unwind 5 --unwindset json_string.0:27,put_string_n.0:5,put_raw.0:7,well_formed.0:27,replaced.0:5,memchr.0:9,memcmp.0:13 LEN=0-4json-emit-buffer --unwind 1 --unwindset json_raw_value.0:5,harness.0:5 --malloc-may-fail --malloc-fail-null LEN=0-4json-emit-nest --object-bits 12 --unwind 1 --unwindset json_text.0:57,sequences.0:4,sequences.1:5,any_depth.0:4,any_depth.1:4,strcmp.0:12,memchr.0:9,put_string_n.0:2,put_string_n.1:2,put_raw.0:8,json_kv_raw.0:3,json_raw_value.0:3,json_raw.0:5,strlen.0:3,vsnprintf.2:5,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3-keepalive-emit -I ../../.. --object-bits 12 --max-field-sensitivity-array-size 832 --unwind 1 --unwindset json_members.0:833,power_of_ten.0:6,put_string_n.0:5,put_string_n.1:66,put_raw.0:7,strlen.0:66,hex_is_lower.0:66,kv_tamper.0:43,kv_no_tree.0:8,json_raw_value.0:6,vsnprintf.2:4,vsnprintf.0:2,format_number.0:6,format_number.2:5,format_number.3:6,ends_in_any_number.0:6,ends_in_any_number.1:833,ends_in_any_number.2:5 LEN=0-3+keepalive-emit -I ../../.. --object-bits 12 --max-field-sensitivity-array-size 832 --unwind 1 --unwindset json_members.0:833,power_of_ten.0:6,put_string_n.0:5,put_string_n.1:66,put_raw.0:7,strlen.0:66,hex_is_lower.0:66,kv_tamper.0:44,kv_no_tree.0:8,json_raw_value.0:6,vsnprintf.2:4,vsnprintf.0:2,format_number.0:6,format_number.2:5,format_number.3:6,ends_in_any_number.0:6,ends_in_any_number.1:833,ends_in_any_number.2:5 LEN=0-3json-string --unwind 5 --unwindset json_string.0:7,parse_string.0:5,parse_string.1:7,memchr.0:9,memcmp.0:7,harness.0:8 LEN=0-6json-escape --unwind 5 --unwindset parse_string.0:4,memcmp.0:9json-roundtrip --unwind 1 --unwindset put_string_n.0:5,put_string_n.1:5,put_raw.0:7,vsnprintf.2:4,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3,parse_string.1:6,parse_string.0:4,hex4.0:5,utf8_width.0:4,memcmp.0:5 LEN=0-4diff --git a/testing/unit/keepalive.c b/testing/unit/keepalive.cindex 8ad5332c..d3e45e73 100644--- a/testing/unit/keepalive.c+++ b/testing/unit/keepalive.c@@ -596,16 +596,17 @@ static const char * const tamper_order[] = {"SealPerf", "ExecTraced", "SealEntry", "PerfAttach", "PinEntry","SealCopyUp", "Kexec", "TpmExtend", "ObjGet", "SealSignal","SealCoreDump", "SealUprobe", "ExecShared", "XattrHandle", "Lockdown",+ "SealRlimit",};static void tamper_counters_keep_their_places(void){size_t i;- ASSERT_EQ(ARRAY_SIZE(tamper_order), 42);+ ASSERT_EQ(ARRAY_SIZE(tamper_order), 43);ASSERT_EQ(TAMPER_MAX, ARRAY_SIZE(tamper_order));EXPECT_EQ(TAMPER_LOAD_NOT_LOADER, 0);- EXPECT_EQ(TAMPER_LOCKDOWN, TAMPER_MAX - 1);+ EXPECT_EQ(TAMPER_SEAL_RLIMIT, TAMPER_MAX - 1);for (i = 0; i < ARRAY_SIZE(tamper_order); i++)EXPECT_STREQ(tamper_name(i), tamper_order[i]);}@@ -622,7 +623,7 @@ static void body_lists_the_counters_in_enum_order(void)in.tamper = tamper;expect_member(&in, ",\"tamper\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,""16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,"- "34,35,36,18446744073709551615,38,39,40,41,42],\"tree_id\":");+ "34,35,36,18446744073709551615,38,39,40,41,42,43],\"tree_id\":");}static void body_refuses_a_missing_string(void)@@ -742,7 +743,7 @@ static void body_of_the_largest_values_fits(void)in.tamper = tamper;ASSERT_EQ(keepalive_emit(&in, body, sizeof(body), &whole), 0);- EXPECT_EQ(whole, 3403);+ EXPECT_EQ(whole, 3424);EXPECT_LT(whole, KEEPALIVE_BODY_MAX);EXPECT_EQ(keepalive_emit(&in, body, whole, &len), -ENOSPC);EXPECT_EQ(keepalive_emit(&in, body, whole + 1, &len), 0);diff --git a/util/harden.c b/util/harden.cindex 0147521d..e0a9a3a2 100644--- a/util/harden.c+++ b/util/harden.c@@ -13,10 +13,13 @@#include <sys/personality.h>#include <sys/prctl.h>#include <sys/resource.h>+#include <sys/time.h>#include <unistd.h>#include <openssl/crypto.h>+#include <shirudo/misc.h>+#include "harden.h"#include "log.h"@@ -47,11 +50,17 @@ void harden_stdio(void)* lookups without a module, in a static binary too. The personality* comes from the caller too: UNAME26 has uname() report a 2.6 release* to the tree selector, READ_IMPLIES_EXEC makes later mappings- * executable.+ * executable. So do the file size and CPU time limits and the interval+ * timers, which exec keeps and with which the kernel would stop the+ * command midway by SIGXFSZ, SIGXCPU or SIGALRM.*/int harden_self(void){- struct rlimit no_core = {};+ static const int signalling[] = { RLIMIT_FSIZE, RLIMIT_CPU };+ static const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };+ struct rlimit no_core = {}, unlimited = { RLIM_INFINITY, RLIM_INFINITY };+ struct itimerval off = {};+ size_t i;if (personality(PER_LINUX) < 0) {int err = -errno;@@ -60,6 +69,24 @@ int harden_self(void)strerror(-err));return err;}+ for (i = 0; i < ARRAY_SIZE(signalling); i++) {+ if (setrlimit(signalling[i], &unlimited)) {+ int err = -errno;++ pr_err("hardening: cannot reset the resource limits: %s",+ strerror(-err));+ return err;+ }+ }+ for (i = 0; i < ARRAY_SIZE(timers); i++) {+ if (setitimer(timers[i], &off, NULL)) {+ int err = -errno;++ pr_err("hardening: cannot disarm the interval timers: %s",+ strerror(-err));+ return err;+ }+ }prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);diff --git a/util/image_guards.c b/util/image_guards.cindex 0aaeea71..545ea769 100644--- a/util/image_guards.c+++ b/util/image_guards.c@@ -62,6 +62,8 @@ shirudo_seal_guards[SEAL_HOOK_COUNT] = {{ "shirudo_seal_perf_event_alloc",SEAL_PERF_PIN },{ "shirudo_seal_task_kill", SEAL_TASK_KILL_PIN },+ { "shirudo_seal_task_setrlimit",+ BPFFS_DIR "/seal_task_setrlimit_link" },};const struct image_guarddiff --git a/util/image_guards.h b/util/image_guards.hindex af71a2d8..af59062a 100644--- a/util/image_guards.h+++ b/util/image_guards.h@@ -8,7 +8,7 @@#include <stdint.h>-#define SEAL_HOOK_COUNT 27+#define SEAL_HOOK_COUNT 28#define IMAGE_SEAL_HOOK_COUNT 2#define MOUNT_HOOK_COUNT 5#define OBSERVER_HOOK_COUNT 10diff --git a/util/tamper.c b/util/tamper.cindex 8290f125..17841078 100644--- a/util/tamper.c+++ b/util/tamper.c@@ -104,6 +104,8 @@ static const struct {"XFS attribute change by file handle, which passes no xattr hook" },[TAMPER_LOCKDOWN] = { "Lockdown","change or read of the running kernel that lockdown refuses" },+ [TAMPER_SEAL_RLIMIT] = { "SealRlimit",+ "resource limit of a shirudo task changed by another task" },};const char *tamper_name(enum tamper_point point)