Skip to content

eBPF-based security platform

init: size the init event from the restored set

Daniel Borkmanna0c27a09fedf
diff --git a/Documentation/operate/plan/scalability.rst b/Documentation/operate/plan/scalability.rst
index 941bc09c..30092cb0 100644
--- a/Documentation/operate/plan/scalability.rst
+++ b/Documentation/operate/plan/scalability.rst
@@ -124,14 +124,10 @@ shirudo limits
- Limit
- When it is reached
* - Boot restore
- - The init record of a boot holds at most 64 KiB: about 1.9 KiB, plus
- 95 bytes and the name for every restored upatch. About 550
- upatches with 20-character names fit, 400 with 63-character names.
- - ``init`` extends the register and then fails to append its
- record, with ``eventlog: append failed after extend -- chain/log
- desync; operator must reconcile``. ``shirudo status`` then
- reports a register its replay cannot explain. See U18 in the
- :doc:`/security/threat-model`.
+ - The init record of a boot grows with the restored set: about
+ 1.9 KiB, plus 95 bytes and the name for every restored upatch, in
+ a buffer sized for the set.
+ - The eventlog limits apply, see the next row.
* - Eventlog
- Readers accept at most 8 MiB, across all boots, and the log is never
rotated. A load or an unload adds about 330 bytes plus the name,
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index ba33c460..c389afb6 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -907,7 +907,7 @@ tree operations run without it.
:Counters: ``TpmExtend``
:Tests: ``t4002``, ``t4003``, ``t4102``, ``t4103``, ``t6115``,
``t6122``, ``t6128``
-:Residual: R4, R12, R20, U6, U8, U9, U18
+:Residual: R4, R12, R20, U6, U8, U9
T6 Boot window
~~~~~~~~~~~~~~
@@ -942,7 +942,7 @@ either system call (``Kexec``).
:Refusal: ``EPERM`` from ``kexec_load(2)`` and ``kexec_file_load(2)``
:Counters: ``Kexec``
:Tests: ``t4003``, ``t4101``, ``t6126``
-:Residual: R6, R7, R12, U11, U16, U18
+:Residual: R6, R7, R12, U11, U16
.. _tm-t7:
@@ -1697,22 +1697,6 @@ U17 A stopped runtime command keeps its descriptors
list; compare the loaded links with the measured set when one is
found.
-U18 Restoring many upatches overflows the init record
- :Affects: ``init`` (T5, T6).
- :Consequence: ``init`` encodes the init record of a boot in a fixed
- 64 KiB buffer after it has extended the register. The record takes
- about 1.9 KiB, plus 95 bytes and the name for every restored
- upatch, so about 550 upatches with 20-character names fit. With
- more, every boot extends the register, fails to append the record
- and logs ``eventlog: append failed after extend -- chain/log
- desync; operator must reconcile``. The register is then ahead of
- the log, ``shirudo status`` reports a register its replay cannot
- explain, and attestation fails for want of an init record.
- :Status: Confirmed in code; the count is computed from the record's
- fields, not reproduced.
- :Meanwhile: Keep the archived upatches of a target well below the
- limit; :doc:`/operate/plan/scalability` gives the sizes.
-
U19 A decoder cannot name a long upatch
:Affects: Lua decoders and map export (T13).
:Consequence: A decoder names its upatch in a 64-byte field, and
diff --git a/builtin-init.c b/builtin-init.c
index 064cc1f9..799bddca 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -29,6 +29,7 @@
#include <bpf/libbpf.h>
#include <shirudo/misc.h>
+#include <shirudo/overflow.h>
#include <shirudo/string.h>
#include <shirudo/upatch.h>
@@ -1040,14 +1041,20 @@ static int append_init_event(const struct measured_upatch *set,
const __u8 init_digest[32],
const struct chain_init_info *info)
{
- char writer_hex[HEXLEN(TPM_NV_RSA_BYTES)];
- char buf[64 * 1024];
- struct json_emit e = { .buf = buf, .cap = sizeof(buf) };
char pcr_hex[HEXLEN(32)], anchor_hex[HEXLEN(32)], chain_hex[HEXLEN(32)];
+ /* Every set entry is a name, its digest and their keys. */
+ size_t cap = size_add(64 * 1024, size_mul(n, UPATCH_NAME_MAX + 128));
char name_hex[HEXLEN(TPM_NAME_LEN)], tree_hex[HEXLEN(32)];
+ char writer_hex[HEXLEN(TPM_NV_RSA_BYTES)];
char cert_hex[HEXLEN(32)], set_hex[HEXLEN(32)];
+ struct json_emit e = { .cap = cap };
char phase_hex[HEXLEN(32)];
size_t i;
+ int ret;
+
+ e.buf = xmalloc(cap);
+ if (!e.buf)
+ return -ENOMEM;
hex_encode(cert_sha, 32, cert_hex);
hex_encode(set_digest, 32, set_hex);
@@ -1097,15 +1104,18 @@ static int append_init_event(const struct measured_upatch *set,
if (e.err) {
pr_err("eventlog: init entry encode failed: %s",
strerror(-e.err));
+ xfree(e.buf, cap);
return e.err;
}
/*
* From the initrd the record waits under /run for the root file
* system's init: the eventlog is on a root that is read-only here.
*/
- return eventlog_append_to(initrd_mode ?
- eventlog_pending_path() :
- eventlog_path(), buf);
+ ret = eventlog_append_to(initrd_mode ?
+ eventlog_pending_path() :
+ eventlog_path(), e.buf);
+ xfree(e.buf, cap);
+ return ret;
}
static bool phase_unmeasured(const __u8 pcr[32])