eBPF-based security platform
util: cut the comments down to why
Daniel Borkmann08470c89541c
diff --git a/util/attest.c b/util/attest.cindex 9f73319c..b91c3bea 100644--- a/util/attest.c+++ b/util/attest.c@@ -41,7 +41,6 @@extern const char shirudo_version_id[];-/* Read a log file (bounded) and base64 it into an xmalloc'd string. */static int read_file_base64(const char *path, char **out, size_t *out_cap){unsigned char *raw;@@ -370,8 +369,6 @@ out:return rc;}-/* ---- verification ---------------------------------------------------- */-struct record {char type[16];char label[SHIRUDO_UPATCH_NAME_MAX + 64];@@ -395,7 +392,6 @@ struct init_record {};struct parse {- /* scalars straight from the document */char nonce_hex[2 * SHIRUDO_ATTEST_NONCE_MAX + 1];int64_t pcr_mask;char ak_public_hex[2 * SHIRUDO_TPM_PUBLIC_MAX + 1];@@ -412,12 +408,10 @@ struct parse {char reg_value_hex[65];char reg_attest_hex[2 * SHIRUDO_TPM_ATTEST_MAX + 1];char reg_sig_hex[2 * SHIRUDO_TPM_SIGNATURE_MAX + 1];- /* pcrs[] element scratch and result */int64_t pcr_index;char pcr_value_hex[65];uint32_t pcr_have;uint8_t pcrs[24][32];- /* eventlog[] element scratch */char type[16];char digest_hex[65];char pcr_before_hex[65];@@ -435,7 +429,6 @@ struct parse {char tree_op[16];int64_t tree_seq;char key_fingerprint[65];- /* results */struct record *recs;size_t n_recs;unsigned int inits; /* init records this boot */@@ -604,7 +597,6 @@ static int hex_bytes(const char *hex, uint8_t *out, size_t cap, size_t *len)return shirudo_hex_decode(hex, out, n / 2);}-/* Structure and signature checks the quote and the certification share. */static int check_signed(struct reporter *rep, const char *what,const char *attest_hex, const char *sig_hex,const struct shirudo_tpm_ecc_public *ak,@@ -820,7 +812,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,shirudo_ct_eq(nonce, expect->nonce, nonce_len)),"nonce matches the request");- /* The attestation key: a restricted signer with the pinned name. */if (hex_bytes(p->ak_public_hex, ak_public, sizeof(ak_public),&ak_public_len) ||hex_bytes(p->ak_name_hex, ak_name, sizeof(ak_name), &ak_name_len) ||@@ -851,7 +842,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,note(&rep, "attestation key not pinned: name %s",p->ak_name_hex);- /* The endorsement key beside it, and the credential it opened. */if (have_ek) {uint8_t ek_public[SHIRUDO_TPM_PUBLIC_MAX];uint8_t ek_name[SHIRUDO_TPM_NAME_LEN], computed[SHIRUDO_TPM_NAME_LEN];@@ -904,7 +894,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,note(&rep, "a credential was activated but none is expected ""(--expect-credential)");- /* The quote over the PCR bank. */rc = check_signed(&rep, "quote", p->quote_attest_hex, p->quote_sig_hex,&ak_pub, ak_name, nonce, nonce_len, attest,sizeof(attest), &attest_len, "e);@@ -933,7 +922,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,"quote: PCR digest matches the listed values");}- /* The register certification. */rc = check_signed(&rep, "register", p->reg_attest_hex, p->reg_sig_hex,&ak_pub, ak_name, nonce, nonce_len, attest,sizeof(attest), &attest_len, &certify);@@ -1021,7 +1009,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,"register: init record is of the TPM's current reset ""count");- /* The replay: this boot's records reproduce the certified value. */for (i = 0; i < p->n_recs; i++) {shirudo_chain_fold(chain, p->recs[i].digest);if (i)@@ -1031,7 +1018,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,"eventlog: %zu record%s replay to the certified value", p->n_recs,p->n_recs == 1 ? "" : "s");- /* The anchor: PCR holds the record of the binding. */{char anchor[SHIRUDO_CHAIN_ANCHOR_MAX];@@ -1060,7 +1046,6 @@ int shirudo_attest_verify(const char *evidence, size_t len,}}- /* The expected state. */if (expect->have_init)say(&rep, shirudo_ct_eq(p->init.digest, expect->init_event, 32),"state: init event covers the expected certificate, set "@@ -1101,8 +1086,6 @@ out:return rc;}-/* ---- the challenge ---------------------------------------------------- */-static int read_file(const char *path, char **out, size_t *len, size_t *cap){struct stat st;@@ -1350,7 +1333,6 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,goto out;}- /* The seed the endorsement key alone can recover, then the blob. */rc = -EIO;if (getrandom(credential, SHIRUDO_TPM_CREDENTIAL_LEN, 0) !=SHIRUDO_TPM_CREDENTIAL_LEN)diff --git a/util/bpm_tree.c b/util/bpm_tree.cindex 5182ae92..b7f46774 100644--- a/util/bpm_tree.c+++ b/util/bpm_tree.c@@ -656,7 +656,6 @@ static size_t tree_selector_kv_bound(const struct shirudo_tree_selector_kv *kv)return n;}-/* Upper bound on the serialised size of one operation. */static size_t tree_operation_bound(const struct shirudo_tree_operation *op){const struct shirudo_tree_selector *s = &op->selector;diff --git a/util/chain.c b/util/chain.cindex fc95f58a..dfdee39a 100644--- a/util/chain.c+++ b/util/chain.c@@ -196,7 +196,6 @@ static bool name_equals(const struct shirudo_tpm_nv_info *info,shirudo_ct_eq(info->name, name, SHIRUDO_TPM_NAME_LEN);}-/* Define the register under policy, undefining a stale index first. */static int register_define(struct shirudo_tpm *tpm, bool defined,const uint8_t policy[32]){diff --git a/util/config.c b/util/config.cindex cd65e3bb..f99146de 100644--- a/util/config.c+++ b/util/config.c@@ -257,10 +257,8 @@ int shirudo_config_load(struct shirudo_config *cfg)set_owner_auth(cfg, env);/*- * TCTI env override -- mirrors the pre-existing- * SHIRUDO_TPM_TCTI behaviour in util/tpm.c so the env wins- * over the on-disk config (handy when the conf file is shared- * but a single dev run wants swtpm).+ * The env wins over the file, as in util/tpm.c, so one dev run can+ * point at swtpm while the file is shared.*/env = getenv("SHIRUDO_TPM_TCTI");if (env && *env) {diff --git a/util/crypto_openssl.c b/util/crypto_openssl.cindex 1664dce1..17fc5b3c 100644--- a/util/crypto_openssl.c+++ b/util/crypto_openssl.c@@ -247,11 +247,9 @@ int shirudo_cert_key_algorithm(const struct shirudo_cert *cert,}/*- * Verify a detached CMS signature against one operator certificate. The- * signature algorithm comes from the SignerInfo, so an ML-DSA signature- * (signedAttrs + SHA-512, or no attributes on OpenSSL 4) and an RSA- * signature verify through the same call; libcrypto >= 3.5 is needed for- * ML-DSA.+ * The algorithm comes from the SignerInfo, so an ML-DSA signature,+ * with signedAttrs and SHA-512 or bare on OpenSSL 4, and an RSA one+ * verify through one call; ML-DSA needs libcrypto >= 3.5.*/int shirudo_verify_detached(const uint8_t *payload, size_t payload_len,const uint8_t *signature, size_t signature_len,diff --git a/util/eventlog.c b/util/eventlog.cindex add713e5..7a54c652 100644--- a/util/eventlog.c+++ b/util/eventlog.c@@ -2,10 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * /var/lib/shirudo/eventlog appender. Append-only JSON-lines, one- * line per register extension. The eventlog and the register must- * stay in lockstep: replaying this boot's records must reproduce the- * live value, so a caller only appends here after a successful extend.+ * The eventlog: one JSON line per register extension, appended only+ * after the extend succeeded so a replay reproduces the live value.*/#include <errno.h>@@ -118,7 +116,6 @@ static int read_file(const char *path, char **out, size_t *out_len)return 0;}-/* The log and, after it, whatever the initrd phase left pending. */static int read_log(char **out, size_t *out_len){size_t base_len = 0, pending_len = 0, off;@@ -171,10 +168,8 @@ out:}/*- * Walk this boot's records in <buf>: every line whose boot_id is the- * running boot's, from the last "init" line on. The callback learns- * whether a line is that init so a replay can start over from zero.- * -ENOENT when no init of this boot exists. Consumes <buf>.+ * This boot's records from its last init line on; the callback learns+ * which line that is so a replay can start from zero.*/static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,bool is_init, void *ctx), void *ctx)@@ -246,7 +241,6 @@ static int adopt_seen(const char *line, size_t len, bool is_init, void *ctx)return 0;}-/* Whether this boot's part of the log already holds <line>. */static int log_holds(const char *line, size_t len){struct adopt_ctx a = { .line = line, .len = len };diff --git a/util/help.c b/util/help.cindex 44a28189..26bc2fa8 100644--- a/util/help.c+++ b/util/help.c@@ -17,12 +17,6 @@/* Wrap target for help-item summaries; covers a 100-col terminal with slack. */#define SHIRUDO_HELP_WIDTH 90-/*- * Word-wrap <text> at <avail> chars. The first word continues whatever- * the caller already printed; every subsequent line starts with- * <indent> spaces so continuation aligns under the summary column.- * Single-spaces between words; trailing whitespace dropped.- */static void wrap_print(const char *text, size_t indent, size_t avail){const char *p = text;@@ -100,10 +94,8 @@ void shirudo_print_help(const struct shirudo_help *h)if (s->n_items == 0)continue;/*- * Per-section column width: align the summaries under the- * longest name + a 2-char gutter. Computing it here so an- * "Options:" section with --include-eventlog reads as- * cleanly as a "Subcommands:" section with `add`/`rm`.+ * Per section, so an Options section reads as cleanly as a+ * Subcommands one.*/for (j = 0; j < s->n_items; j++) {size_t l = strlen(s->items[j].name);@@ -184,7 +176,6 @@ const char *shirudo_resolve_subcommand(const char *cmd_label,subcmds, n_subcmds);return NULL;}- /* Ambiguous: list the colliding matches so the user can pick. */fprintf(stderr, "%s: '%s' is ambiguous; matches:\n", cmd_label, input);for (i = 0; i < n; i++)fprintf(stderr, "\t%s\n", names[matches[i]]);diff --git a/util/json.c b/util/json.cindex f55a814b..e8e480e7 100644--- a/util/json.c+++ b/util/json.c@@ -2,10 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * In-tree JSON emitter and schema-callback parser. The emitter is- * streaming with a caller-supplied buffer, automatic comma placement- * and string escaping; the parser dispatches declared keys into caller- * structs and parses-and-discards everything else.+ * JSON emitter and schema parser; the parser dispatches declared keys+ * and parses and discards the rest.*/#include <errno.h>@@ -61,9 +59,8 @@ static void put_raw(struct shirudo_json_emit *e, const char *s)}/*- * Emit one escaped JSON string (surrounding quotes included). Escapes- * the mandatory characters and rejects malformed UTF-8 with -EILSEQ so- * a stray byte can never produce invalid JSON.+ * Malformed UTF-8 is -EILSEQ, so a stray byte can never produce+ * invalid JSON.*/static void put_string(struct shirudo_json_emit *e, const char *s){@@ -96,7 +93,6 @@ static void put_string(struct shirudo_json_emit *e, const char *s)put(e, (char)c);p++;} else {- /* Validate a UTF-8 multi-byte sequence. */int n;if ((c & 0xE0) == 0xC0)@@ -123,7 +119,6 @@ static void put_string(struct shirudo_json_emit *e, const char *s)put(e, '"');}-/* Comma before the next member of the innermost open container. */static void sep(struct shirudo_json_emit *e){if (e->err)@@ -261,8 +256,6 @@ int shirudo_json_emit_flush(struct shirudo_json_emit *e)return flush_sink(e);}-/* ---- Schema-driven parser ---------------------------------------- */-struct pctx {const char *p;const char *end;@@ -308,7 +301,6 @@ static int hex4(const char *s)return v;}-/* Append one byte to dst (if non-NULL), tracking decoded length. */static int emit_byte(char *dst, size_t cap, size_t *len, unsigned char b){size_t n = *len;@@ -344,10 +336,6 @@ static int utf8_emit(char *dst, size_t cap, size_t *len, unsigned cp)return rc;}-/*- * Parse a JSON string starting at *p == '"'. Decodes escapes into dst- * (NUL-terminated) when dst != NULL, or just consumes when dst == NULL.- */static int parse_string(struct pctx *c, char *dst, size_t cap){size_t len = 0;@@ -526,12 +514,6 @@ static int parse_array(struct pctx *c)return 0;}-/*- * Parse a '['-led array into a declared SHIRUDO_JSON_T_ARRAY field:- * each element is dispatched against f->sub[] (an object element uses- * the whole sub-schema; a scalar element goes to sub[0]), then the- * sink's on_elem(ctx) is called so the caller can copy the element out.- */static int parse_array_into(struct pctx *c, struct shirudo_json_field *f){struct shirudo_json_array *sink = f->dst;@@ -565,7 +547,6 @@ static int parse_array_into(struct pctx *c, struct shirudo_json_field *f)c->fields = save_f;c->n_fields = save_n;} else {- /* Scalar (or nested array/object) element -> sub[0]. */rc = parse_value(c, f->n_sub ? &f->sub[0] : NULL);}if (rc)diff --git a/util/keyring.c b/util/keyring.cindex edecd727..7f9a9db7 100644--- a/util/keyring.c+++ b/util/keyring.c@@ -27,7 +27,6 @@#define KEY_SPEC_USER_KEYRING (-4)#endif-/* keyring permission bits (avoid a libkeyutils dependency). */#define KEY_POS_VIEW 0x01000000#define KEY_POS_READ 0x02000000#define KEY_POS_WRITE 0x04000000@@ -152,7 +151,6 @@ static int describe_key(key_serial_t serial,return 0;}-/* "type;uid;gid;perm;description" -> &type, &description */static void split_describe(char *desc, const char **type,const char **description){diff --git a/util/keys.c b/util/keys.cindex 55643aaa..f9202c08 100644--- a/util/keys.c+++ b/util/keys.c@@ -227,12 +227,11 @@ static size_t count_der(const char *dir)if (n < 0)return 0;for (i = 0; i < n; i++)- shirudo_libc_free(names[i]); /* scandir-owned */- shirudo_libc_free(names); /* scandir-owned */+ shirudo_libc_free(names[i]);+ shirudo_libc_free(names);return (size_t)n;}-/* <name>.der has its vouch at <name>.vouch. */static int vouch_path_for(const char *der_path, char *out, size_t cap){size_t n = strlen(der_path) - 4;@@ -348,8 +347,8 @@ static int scan_trusted(const char *keys_dir, const char *revoked_dir,(*n_cand)++;}for (i = 0; i < n; i++)- shirudo_libc_free(names[i]); /* scandir-owned */- shirudo_libc_free(names); /* scandir-owned */+ shirudo_libc_free(names[i]);+ shirudo_libc_free(names);return rc;}diff --git a/util/kmodules.c b/util/kmodules.cindex 70ad5a73..7c04fe6f 100644--- a/util/kmodules.c+++ b/util/kmodules.c@@ -2,10 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * /proc/modules parser + ASCII dependency-tree printer. Roots are- * modules nothing else depends on (the operator-loaded entry points);- * each root descends into its `Depends:` chain. Shared subtrees- * expand once and are marked `(shared)` thereafter.+ * /proc/modules parser and dependency-tree printer.*/#include <ctype.h>@@ -25,7 +22,6 @@#include "malloc.h"#include "timefmt.h"-/* Read /proc/modules into a heap-grown buffer. */static int slurp(char **buf_out, size_t *len_out){size_t cap = 16384, len = 0;@@ -78,7 +74,6 @@ static int kmod_cmp(const void *a, const void *b)((const struct shirudo_kmod *)b)->name);}-/* Find module index by name; -1 if not present (a stale dep entry). */static int kmod_find(const struct shirudo_kmod_set *set, const char *name){size_t lo = 0, hi = set->n;@@ -180,10 +175,6 @@ int shirudo_kmodules_read(struct shirudo_kmod_set *set)m->n_deps = 0;m->deps_off = 0;- /*- * Dep column is `dep1,dep2,...,` (trailing comma) or `-`.- * Stash raw name slices; resolve to indices after sort.- */if (*p && *p != '-') {const char *q = p;@@ -219,13 +210,7 @@ int shirudo_kmodules_read(struct shirudo_kmod_set *set)qsort(set->mods, set->n, sizeof(*set->mods), kmod_cmp);- /* qsort scrambled indices; rebuild raws[].mod_idx by lookup. */for (size_t i = 0; i < n_raw; i++) {- /*- * The original raws[i].mod_idx is invalid post-sort. We- * stored the *raw* name slice but lost which module it- * belonged to. Re-discover by reparsing.- */(void)0;}/*@@ -332,7 +317,6 @@ skip:}}- /* Compact raws[] into set->deps[]. Group by mod_idx. */for (size_t i = 0; i < set->n; i++) {set->mods[i].deps_off = (uint16_t)set->n_deps;for (size_t j = 0; j < n_raw; j++) {@@ -403,12 +387,6 @@ void shirudo_kmodules_free(struct shirudo_kmod_set *set)memset(set, 0, sizeof(*set));}-/*- * Print one module + its dependency subtree. `prefix` carries the- * accumulated `│ `/` ` indent for nested levels. `is_last` picks- * `└── ` vs `├── `. `seen[]` is a bitset of "already expanded- * somewhere above"; on a hit, the subtree collapses to `(shared)`.- */static void print_subtree(const struct shirudo_kmod_set *set, size_t i,const char *prefix, int is_last, uint8_t *seen){@@ -493,7 +471,6 @@ void shirudo_kmodules_print_tree(const struct shirudo_kmod_set *set)xfree(roots, set->n * sizeof(*roots));}-/* Format an int64 epoch seconds value as ISO-8601 UTC. */static void iso_utc(int64_t sec, char *out, size_t out_cap){struct tm tm = {};@@ -554,7 +531,6 @@ void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,}qsort(all, set->n, sizeof(*all), recent_cmp);take = set->n < last_n ? set->n : last_n;- /* qsort already put the freshest first -- print in that order. */for (i = 0; i < take; i++) {const struct shirudo_kmod *m = &set->mods[all[i].idx];char ts[32], size_s[16], age[24];diff --git a/util/kmsg.c b/util/kmsg.cindex 90eb15a4..b56dfd95 100644--- a/util/kmsg.c+++ b/util/kmsg.c@@ -2,10 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * /dev/kmsg reader with ISO wallclock timestamps. Records carry a- * monotonic microsecond timestamp; we offset against the realtime/- * monotonic delta computed at open to produce wallclock UTC, the- * same approach `dmesg --time-format=iso` uses.+ * /dev/kmsg reader; the records' monotonic timestamps become wallclock+ * UTC the way `dmesg --time-format=iso` does.*/#include <errno.h>@@ -24,13 +22,6 @@/* Per-record buffer size accepted by /dev/kmsg: kernel allows up to 8 KiB. */#define KMSG_READ_BUF 8192-/*- * Read one record from <fd>. Returns:- * >0 bytes read- * 0 EOF / EAGAIN at tail- * -EPIPE reader fell behind the ring buffer; caller may continue- * other negative errno on hard failure- */static ssize_t read_record(int fd, char *buf, size_t cap){ssize_t n = read(fd, buf, cap);@@ -46,13 +37,6 @@ static ssize_t read_record(int fd, char *buf, size_t cap)return -errno;}-/*- * Parse one /dev/kmsg record. Format (one line, terminated by '\n'):- * <prio,seq,monotonic_us,flags[,extra]>;message_text\n- * [optional ' KEY=value\n' continuation lines until '\n']- *- * Returns 0 on success, -EINVAL on malformed header.- */static int parse_record(const char *rec, size_t len,uint64_t *monotonic_us_out,const char **msg_out, size_t *msg_len_out)@@ -66,11 +50,6 @@ static int parse_record(const char *rec, size_t len,if (!semi)return -EINVAL;- /*- * Walk the header counting commas until the third one, which- * sits immediately after monotonic_us. We don't care about the- * prio or seq columns -- just the timestamp.- */for (p = rec; p < semi; p++) {if (*p == ',') {commas++;@@ -91,7 +70,6 @@ static int parse_record(const char *rec, size_t len,return -EINVAL;*msg_out = semi + 1;- /* Message ends at first '\n' (continuation lines start with ' '). */{const char *nl = memchr(*msg_out, '\n',(size_t)(end - *msg_out));@@ -117,12 +95,10 @@ static void copy_msg(char *dst, size_t dst_cap,dst[o++] = (char)c;else if (c >= 0x80)dst[o++] = (char)c;- /* drop other control bytes silently */}dst[o] = '\0';}-/* Compute the wallclock instant corresponding to monotonic_us-since-boot. */static void monotonic_to_iso(uint64_t mono_us,const struct timespec *rt_at_open,const struct timespec *mt_at_open,@@ -178,11 +154,6 @@ int shirudo_kmsg_tail(struct shirudo_kmsg_record *out, size_t cap)return -errno;}- /*- * Ring-buffer of size <cap> over <out> indexed by head. Walk- * every record from the buffer head to tail; only the last <cap>- * survive. O(N), but N is bounded by the kernel ring buffer.- */for (;;) {uint64_t mono_us = 0;const char *msg = NULL;diff --git a/util/preflight.c b/util/preflight.cindex 313f030f..ea269f7f 100644--- a/util/preflight.c+++ b/util/preflight.c@@ -379,17 +379,10 @@ static void check_tpm(struct shirudo_preflight_result *r)next_slot(r, SHIRUDO_PRE_TPM, "tpm2_reachable");/*- * Either SHIRUDO_TPM_TCTI env or tpm.tcti in shirudo.conf- * redirects the TCTI string consumed by util/tpm.c (e.g.- * "swtpm:host=127.0.0.1,port=2321" for a socket-backed- * software TPM in dev/CI). When set, the kernel resource- * manager isn't in play -- the device check would spuriously- * refuse a perfectly valid swtpm setup. Trust the override and- * let TPM-open report any real connectivity problem; the- * operator-side chain expectation still rejects any value a- * fake TPM produces, so this is a dev convenience, not a- * security relaxation. shirudo_config_load consults the env- * after the file, so checking cfg.tpm_tcti is sufficient.+ * A TCTI override points at a software TPM, where the kernel resource+ * manager is not in play, so the device check would refuse a valid+ * setup. The operator's expectation still rejects what a fake TPM+ * produces, so this is a convenience, not a relaxation.*/{struct shirudo_config cfg = {};diff --git a/util/seal.c b/util/seal.cindex da2d2228..b7f26b38 100644--- a/util/seal.c+++ b/util/seal.c@@ -104,7 +104,6 @@ static ssize_t seal_lget(const char *path, char label[SEAL_LABEL_LEN])SEAL_LABEL_LEN));}-/* Open the directory of path to create in it; *name is the last component. */static int seal_open_parent(const char *path, const char **name){const char *slash = strrchr(path, '/');diff --git a/util/sign.c b/util/sign.cindex 7d7662c3..eaa5f54b 100644--- a/util/sign.c+++ b/util/sign.c@@ -122,10 +122,6 @@ static bool pkey_is_mldsa(const EVP_PKEY *pkey)int shirudo_cms_sign(struct shirudo_sign_io *io,const char *pkey_path, const char *cert_path){- /*- * TODO: add an issuerAndSerialNumber signing mode so signed BPF- * upatches can exercise both kernel-supported CMS forms.- */unsigned int signer_flags = CMS_NOCERTS | CMS_BINARY | CMS_NOSMIMECAP |#ifdef CMS_NO_SIGNING_TIMECMS_NO_SIGNING_TIME |diff --git a/util/similar.c b/util/similar.cindex f36f75da..0275549c 100644--- a/util/similar.c+++ b/util/similar.c@@ -2,16 +2,13 @@/** Copyright (c) 2026 Authors of shirudo*- * Levenshtein edit distance + a top-N "closest match" helper. Used by- * the top-level dispatcher to suggest a real subcommand when the user- * mistypes one.+ * Levenshtein distance and the did-you-mean helpers of the dispatcher.*/#include <string.h>#include "similar.h"-/* Two-row Levenshtein DP, allocation-free, early-out at `max`. */int shirudo_edit_distance(const char *s, const char *t, int max){int prev[SHIRUDO_SIMILAR_MAX_LEN + 1];@@ -111,7 +108,6 @@ size_t shirudo_resolve(const char *input,{size_t i, m = 0, len = strlen(input);- /* Tier 1: exact match. Unique by definition; short-circuit. */for (i = 0; i < n; i++) {if (strcmp(input, candidates[i]) == 0) {if (cap >= 1)@@ -119,7 +115,6 @@ size_t shirudo_resolve(const char *input,return 1;}}- /* Tier 2: input is a prefix of a candidate ("node" -> "nodes"). */for (i = 0; i < n; i++) {size_t clen = strlen(candidates[i]);@@ -131,7 +126,6 @@ size_t shirudo_resolve(const char *input,}if (m)return m;- /* Tier 3: candidate is a prefix of input ("remotes" -> "remote"). */for (i = 0; i < n; i++) {size_t clen = strlen(candidates[i]);diff --git a/util/sysinfo.c b/util/sysinfo.cindex a75038bb..9f82e01c 100644--- a/util/sysinfo.c+++ b/util/sysinfo.c@@ -20,7 +20,6 @@#include "malloc.h"#include "sysinfo.h"-/* Read the first line of a file into buf, trimming the trailing newline. */static void read_first_line(const char *path, char *buf, size_t cap){ssize_t n;@@ -40,10 +39,6 @@ static void read_first_line(const char *path, char *buf, size_t cap)buf[strcspn(buf, "\r\n")] = '\0';}-/*- * Pull PRETTY_NAME from /etc/os-release into buf, stripping the- * surrounding double quotes os-release uses for the human label.- */static void read_os_pretty(char *buf, size_t cap){char line[512];@@ -72,7 +67,6 @@ static void read_os_pretty(char *buf, size_t cap)fclose(f);}-/* Seconds since boot from /proc/uptime's first (float) field, or -1. */static long read_uptime_sec(void){char buf[64];@@ -90,12 +84,6 @@ static long read_uptime_sec(void)return (long)strtod(buf, NULL);}-/*- * MemTotal + MemAvailable in KiB from /proc/meminfo. -1 each on failure.- * MemAvailable is the modern "free + reclaimable" measure introduced in- * 3.14; on a kernel that old we leave it as -1 and the renderer omits- * the "used" half.- */static void read_mem(long *total_kb, long *avail_kb){char line[256];@@ -121,7 +109,6 @@ static void read_mem(long *total_kb, long *avail_kb)fclose(f);}-/* statvfs("/") -> total + used in KiB. -1 each on failure. */static void read_root_disk(long *total_kb, long *used_kb){struct statvfs s;@@ -273,7 +260,6 @@ static void emit_kernel_config_entry(void *ctx, const char *key,shirudo_json_kv_string(ctx, key, value);}-/* Emit set entries from /boot/config-<uname -r> as a JSON object. */static void emit_kernel_config(struct shirudo_json_emit *e,const char *kernel_release){diff --git a/util/tpm.c b/util/tpm.cindex 4a2ee323..c3542e8b 100644--- a/util/tpm.c+++ b/util/tpm.c@@ -48,15 +48,9 @@ int shirudo_tpm_open(struct shirudo_tpm **out)setenv("TSS2_LOG", "all+none", 0);/*- * Default to the kernel resource manager. Precedence:- * 1. SHIRUDO_TPM_TCTI env var (highest)- * 2. tpm.tcti in /etc/shirudo/shirudo.conf- * 3. compiled-in default `device:/dev/tpmrm0`- * Override is for VMs/CI whose /dev/tpmrm0 is- * owner-provisioned and for tests against a software TPM.- * Redirecting the TCTI on a target cannot defeat the- * operator-side guarantee: the evidence is signed by the key- * the operator pinned, so a substitute TPM fails verification.+ * The env, then the file, then /dev/tpmrm0. An override is for VMs,+ * CI and a software TPM; it cannot defeat the operator-side guarantee,+ * since evidence is signed by the key the operator pinned.*/tcti = getenv("SHIRUDO_TPM_TCTI");if ((!tcti || !*tcti) && shirudo_config_load(&cfg) == 0 &&@@ -96,7 +90,6 @@ void shirudo_tpm_close(struct shirudo_tpm *t)xfree(t, sizeof(*t));}-/* Compare a TPM return code with a base code, masking handle numbers. */static bool rc_is(TSS2_RC rc, TSS2_RC code){if ((rc & 0xFFFF0000u) != 0)@@ -240,7 +233,6 @@ int shirudo_tpm_nv_info(struct shirudo_tpm *t, uint32_t index,return 0;}-/* Owner-hierarchy auth for DefineSpace/UndefineSpace; cleared after use. */static int owner_auth_set(struct shirudo_tpm *t, const void *auth, size_t len){TPM2B_AUTH owner = {};@@ -522,7 +514,6 @@ static size_t put2b(uint8_t *p, const uint8_t *data, uint16_t len)return 2u + len;}-/* The marshalled form of a public area libtss2 handed back. */static int public_from_tss(const TPMT_PUBLIC *p, uint8_t *out, size_t cap,size_t *len){diff --git a/util/tpm_wire.c b/util/tpm_wire.cindex 614ec128..f1ad1ec9 100644--- a/util/tpm_wire.c+++ b/util/tpm_wire.c@@ -75,7 +75,6 @@ static int get64(struct reader *r, uint64_t *v)return 0;}-/* A TPM2B: 16-bit size then that many bytes, returned by reference. */static int get2b(struct reader *r, const uint8_t **data, size_t *len,size_t max){diff --git a/util/upatch.c b/util/upatch.cindex bdcc3deb..f247c52c 100644--- a/util/upatch.c+++ b/util/upatch.c@@ -136,7 +136,6 @@ static int validate_bounds(const struct shirudo_upatch_header *h, size_t n,return -EINVAL;if (!section_inside(h->data_off, h->data_len, n, header_size))return -EINVAL;- /* loader insns and signature are mandatory; data may be empty */if (h->loader_insns_len == 0 || h->signature_len == 0)return -EINVAL;return 0;diff --git a/util/upatch_decode.c b/util/upatch_decode.cindex 5e6db05c..d6785224 100644--- a/util/upatch_decode.c+++ b/util/upatch_decode.c@@ -2,10 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * Signed userspace decoders for serialized upatch maps. The decoder source- * lives inside the upatch's signature-covered data trailer; this file only- * supplies a small LuaJIT host API and JSON/OTLP serialization of the- * returned value.+ * Signed Lua decoders for serialized maps: a small LuaJIT host API and+ * the serialisation of what they return.*/#include <errno.h>@@ -776,7 +774,6 @@ static void lua_split_page_slots(lua_State *L, int slots_idx,for (i = 0; i < local_slots; i++) {uint64_t page_slot = chunk * slots_per_chunk + i;- /* Every serialized page starts with its header slot. */if (page_slot == 0)continue;lua_store_slot(L, slots_idx, cursor + page_slot,@@ -795,10 +792,6 @@ static void lua_split_page_slots(lua_State *L, int slots_idx,static void lua_push_u64_string(lua_State *L, uint64_t value);-/*- * Every slot of one serialized page in order, header first, honouring- * the per-chunk packing of records that do not divide the chunk payload.- */static int lua_shirudo_page_slots(lua_State *L){const char *hex;@@ -890,7 +883,6 @@ static int lua_shirudo_u64_sub(lua_State *L)return 1;}-/* Little-endian u64 at a byte offset of a hex string, as a decimal string. */static int lua_shirudo_hex_u64(lua_State *L){const char *hex;diff --git a/util/upatch_maps.c b/util/upatch_maps.cindex 4464af1d..db29ba57 100644--- a/util/upatch_maps.c+++ b/util/upatch_maps.c@@ -2,15 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * Pinned upatch maps reader. Walks /run/shirudo/bpffs/upatches/- * <name>/maps/<map>, opens each pin via BPF_OBJ_GET, dispatches to a- * per-type reader for the entries. BTF type names come from- * libbpf::btf__name_by_offset() when the map carries a btf_id.- *- * Generic map reads are read-only. Serializer-backed reads also clear- * the reserved output map and run the pinned serializer program with- * BPF_PROG_TEST_RUN; the serializer writes serialized chunks back to- * that reserved map for userspace to print.+ * Reader of the pinned upatch maps, generic or through the upatch's+ * serializer.*/#include <dirent.h>@@ -48,7 +41,6 @@*/#define SHIRUDO_BTF_MAX_DEPTH 6-/* Resolve the parent upatch location without making it required for reads. */static void resolve_map_location(struct shirudo_map_view *v){struct btf *vbtf;@@ -101,7 +93,6 @@ static bool is_hash_type(uint32_t type)type == BPF_MAP_TYPE_LRU_PERCPU_HASH;}-/* Resolve a BTF type id to a printable type name in dst[]. */static void btf_type_name(struct btf *btf, uint32_t type_id,char *dst, size_t dst_cap){@@ -143,13 +134,8 @@ static void btf_type_name(struct btf *btf, uint32_t type_id,}}-/* Forward decl: defined further down, used by the BTF formatters. */static char *fmt_alloc(const char *fmt, ...) __attribute__((format(printf,1,2)));-/*- * Unwrap qualifier / typedef chains. Returns the resolved type id- * (or `id` unchanged if no unwrap was possible / depth exceeded).- */static uint32_t btf_unwrap(const struct btf *btf, uint32_t id){const struct btf_type *t;@@ -190,13 +176,6 @@ static const char *btf_kind_prefix(uint16_t kind)}}-/*- * `btf_type_signature_into` writes a multi-line definition of `id`- * into the caller-owned buffer at offset *off (bounded by cap). For- * struct/union it emits `struct foo {\n type field;\n ...\n}`; for- * anything else, just the type name. Truncates with `; ...` rather- * than failing if the buffer is too small. depth bounds recursion.- */static void btf_type_signature_into(const struct btf *btf, uint32_t id,char *buf, size_t cap, size_t *off,int depth);@@ -313,18 +292,10 @@ static void btf_type_signature_into(const struct btf *btf, uint32_t id,append_str(buf, cap, off, name && name[0] ? name : "?");}-/*- * Compose a heap-owned formatted-value string for a BTF type. For- * structs/unions: `{ field=val, field=val }`. For arrays: `[v0, v1, ...]`.- * For primitives: decimal (signed/unsigned by BTF_INT_SIGNED); for ptr,- * hex; for enum, the symbol name when known.- * Returns NULL only on allocation failure.- */static char *btf_format_value(const struct btf *btf, uint32_t type_id,const void *bytes, uint32_t bytes_size,int depth);-/* Append one heap-formatted token to an open `out` buffer; takes ownership. */static int strbuf_append_take(char **out, size_t *cap, size_t *off,char *piece){@@ -373,7 +344,6 @@ static char *btf_format_int(const struct btf_type *t, const void *bytes,for (i = 0; i < bytes_used; i++)v |= (int64_t)((const uint8_t *)bytes)[i] << (8 * i);- /* Sign-extend from `bits`. */if (bits < 64 && (v & ((int64_t)1 << (bits - 1))))v |= ~(((int64_t)1 << bits) - 1);return fmt_alloc("%" PRId64, v);@@ -546,7 +516,6 @@ static char *btf_format_value(const struct btf *btf, uint32_t type_id,return NULL;}-/* Heap snprintf into a fresh buffer with the printf result. */static char *fmt_alloc(const char *fmt, ...){char small[64];@@ -577,11 +546,6 @@ static int nproc_possible(void)return n > 0 ? (int)n : 1;}-/*- * Dispatch on (size, signedness) to render a primitive value. Falls- * back to a hex dump for anything else (string, struct, unknown).- * out_buf is heap-owned; caller xfree's. value_bytes are read-only.- */static char *format_value(const void *value, uint32_t value_size,const char *btf_type){@@ -684,7 +648,6 @@ char *shirudo_upatch_map_format_percpu_sum(const struct shirudo_map_view *v,return xstrdup("(unsupported width)");}-/* Open a pinned map and return its fd + filled info. -errno on failure. */static int open_map_pin(const char *upatch, const char *map_name,int *fd_out, struct bpf_map_info *info_out){@@ -906,10 +869,6 @@ out_chunk:return rc;}-/*- * Return 1 when a serializer was found and populated out, 0 when none- * exists for this map, or -errno on serializer/output failure.- */static int try_read_serialized(const char *upatch, const char *map,uint32_t flags, struct shirudo_map_view *out){@@ -1044,7 +1003,6 @@ out:return rc;}-/* Iterate every entry of a map with cap; populate v->entries. */static int read_entries(int fd, struct shirudo_map_view *v,uint32_t cap){@@ -1285,8 +1243,6 @@ int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,return rc;}-/* === Listing === */-static void summary_append(struct shirudo_map_summary **list, size_t *n,size_t *cap, const struct shirudo_map_summary *one){@@ -1302,7 +1258,6 @@ static void summary_append(struct shirudo_map_summary **list, size_t *n,(*list)[(*n)++] = *one;}-/* Read /run/shirudo/bpffs/upatches/<upatch>/maps/<entry> dir. */static void scan_upatch_maps(const char *upatch,struct shirudo_map_summary **list, size_t *n,size_t *cap)@@ -1396,8 +1351,6 @@ void shirudo_map_summary_free(struct shirudo_map_summary *list, size_t n)xfree(list, n * sizeof(*list));}-/* === Human render === */-void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,size_t n){@@ -1425,12 +1378,6 @@ void shirudo_upatch_map_print_inline(const struct shirudo_map_summary *m)m->n_cpus > 1 ? " (per-cpu)" : "");}-/*- * Format one (key, value) cell. Prefer the BTF-aware recursive- * renderer (struct/union/array/enum expansion) when the view carries- * the loaded BTF; fall back to the primitive/hex formatter for raw- * scalars and the no-BTF case.- */char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,uint32_t type_id, const void *bytes,uint32_t bytes_size,@@ -1445,13 +1392,6 @@ char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,return s;}-/*- * Render a captured multi-line type-def block under a "<label>:" header,- * indenting continuation lines so the block lines up under the header- * column. The first line stays inline with the label; every subsequent- * '\n' gets 21 spaces of indent (the width of the existing- * "Value type: " label).- */static void print_type_def(const char *label, const char *def, uint32_t size){const char *p = def;@@ -1614,8 +1554,6 @@ void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v)}}-/* === JSON === */-void shirudo_upatch_maps_emit_json_fields(struct shirudo_json_emit *e,const struct shirudo_map_view *v){diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.cindex 4a281b2b..067fe796 100644--- a/util/upatch_maps_otel.c+++ b/util/upatch_maps_otel.c@@ -2,11 +2,9 @@/** Copyright (c) 2026 Authors of shirudo*- * OTLP/HTTP JSON export for pinned upatch map snapshots. Automatic mode- * chooses a signal from the map's structural BTF; explicit log and metric- * modes bypass that classifier. S3 mode stores the complete snapshot in S3- * and sends a small OTLP log reference. Network delivery is synchronous and- * bounded by the caller-selected retry count.+ * OTLP/HTTP JSON export of map snapshots: a signal chosen from the+ * map's BTF or named by the caller, or a snapshot in S3 behind a log+ * reference.*/#include <ctype.h>@@ -183,8 +181,6 @@ int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,return 0;}-/* ---- OTLP JSON AnyValue helpers ------------------------------------ */-static void otlp_kv_string(struct shirudo_json_emit *e, const char *key,const char *value){@@ -806,8 +802,6 @@ int shirudo_upatch_maps_otel_build_log_file(return build_log_payload(path, v, out, out_len);}-/* ---- Metrics ------------------------------------------------------- */-static int read_integer(const void *p, const struct metric_type *mt,__int128 *signed_out, unsigned __int128 *unsigned_out){@@ -1080,7 +1074,6 @@ static int build_metric_decoded_payload(return rc;decoded_buf = decoded;decoded_alloc_len = decoded_len;- /* Metric decoders return an array of OTLP Metric objects. */while (decoded_len && isspace((unsigned char)decoded[0])) {decoded++;decoded_len--;@@ -1125,8 +1118,6 @@ static int build_metric_decoded_payload(return 0;}-/* ---- Configuration and HTTP --------------------------------------- */-static const char *signal_name(enum shirudo_otel_signal signal){return signal == SHIRUDO_OTEL_LOG ? "LOGS" : "METRICS";@@ -1708,8 +1699,6 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)return rc;}-/* ---- Export lifecycle --------------------------------------------- */-static int otel_open_transport(enum shirudo_otel_signal signal,const char *spec,const struct shirudo_otel_opts *opts,@@ -1942,8 +1931,6 @@ int shirudo_otel_send_log_json(const struct shirudo_otel_opts *opts,return rc;}-/* ---- S3-backed log references ------------------------------------ */-struct snapshot_writer {FILE *file;z_stream z;diff --git a/util/upatch_resolve.c b/util/upatch_resolve.cindex c94635d9..1d6c5657 100644--- a/util/upatch_resolve.c+++ b/util/upatch_resolve.c@@ -2,8 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Lifted out of builtin-status.c so `shirudo upatch get` can share- * the same hook-string + loaded_at resolvers.+ * The hook string and load time of a loaded upatch, from its pin.*/#include <errno.h>