eBPF-based security platform
util: cut the headers' comments down to why
Daniel Borkmann8efc55d43359
diff --git a/include/shirudo/upatch.h b/include/shirudo/upatch.hindex 63ed5353..7656fad3 100644--- a/include/shirudo/upatch.h+++ b/include/shirudo/upatch.h@@ -21,7 +21,6 @@#define SHIRUDO_UPATCH_LEGACY_HEADER_SIZE 352u#define SHIRUDO_UPATCH_HEADER_SIZE 360u-/* Flag bits in struct shirudo_upatch_header.flags. */#define SHIRUDO_DIRECTIVE_UNLOAD (1u << 0)enum shirudo_upatch_type {diff --git a/util/attest.h b/util/attest.hindex 9d1647e3..847379cf 100644--- a/util/attest.h+++ b/util/attest.h@@ -43,10 +43,8 @@ int shirudo_attest_challenge_read(const char *path,struct shirudo_attest_challenge *out);/*- * Target side: the evidence document for nonce over the PCRs in- * pcr_mask, activating the challenge when one is given. The buffer is- * xmalloc'd to *cap bytes and NUL-terminated; the caller frees it with- * xfree(buf, cap). -EKEYREJECTED when the TPM refuses the challenge.+ * Target side. The buffer is xmalloc'd to *cap and NUL-terminated;+ * -EKEYREJECTED when the TPM refuses the challenge.*/int shirudo_attest_evidence(const uint8_t *nonce, size_t nonce_len,uint32_t pcr_mask,@@ -54,13 +52,9 @@ int shirudo_attest_evidence(const uint8_t *nonce, size_t nonce_len,char **out, size_t *len, size_t *cap);/*- * Operator side: from an evidence document, a challenge for its- * attestation key under its endorsement key. The credential the- * target has to recover is handed to the caller and kept nowhere- * else. ek_ca names a PEM bundle the endorsement certificate must- * chain to, or NULL. report receives one line per check; the document- * is xmalloc'd to *cap bytes. -EKEYREJECTED when a check failed and no- * challenge was made.+ * Operator side. The credential the target has to recover is handed+ * to the caller and kept nowhere else; ek_ca is a PEM bundle or NULL.+ * -EKEYREJECTED when a check failed and no challenge was made.*/struct shirudo_attest_challenge_policy {const char *ek_ca; /* issuer bundle, or NULL */@@ -98,10 +92,8 @@ struct shirudo_attest_expect {};/*- * Operator side: check an evidence document against the expectation.- * report receives one line per check. Returns 0 when every check- * passed, -EKEYREJECTED when one failed, -EINVAL when the document is- * malformed.+ * Operator side: 0 when every check passed, -EKEYREJECTED when one+ * failed, -EINVAL when the document is malformed.*/int shirudo_attest_verify(const char *evidence, size_t len,const struct shirudo_attest_expect *expect,diff --git a/util/bpm_oci.h b/util/bpm_oci.hindex 3a08b60b..13435ee0 100644--- a/util/bpm_oci.h+++ b/util/bpm_oci.h@@ -74,7 +74,6 @@ struct bpm_descriptor {int64_t size;};-/* Small helpers shared by every BPM command. */void bpm_copy_string(char *dst, size_t dst_sz, const char *src);void bpm_trim(const char *in, char *out, size_t out_sz);bool bpm_name_ok(const char *s);diff --git a/util/bpm_package.h b/util/bpm_package.hindex c7a4019a..c059f41b 100644--- a/util/bpm_package.h+++ b/util/bpm_package.h@@ -33,15 +33,12 @@ struct bpm_package_info {size_t cert_len;};-/* Parse and validate shirudo/bpm-index:stable; at most BPM_MAX_ENTRIES. */int bpm_index_parse(const unsigned char *body, size_t len,struct bpm_index_entry *entries, int *n_entries);-/* Detached CMS over payload against the certificate at cert_path. */int bpm_verify_cms(const unsigned char *payload, size_t payload_len,const unsigned char *sig, size_t sig_len,const char *cert_path);-/* ustar helpers shared with the installer's extractor. */int bpm_tar_octal(const char *p, size_t n, uint64_t *out);bool bpm_archive_rel_ok(const char *name);@@ -57,7 +54,6 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,size_t *out_len, size_t max);int bpm_pkg_read_member(const char *archive, const char *member,unsigned char **out, size_t *out_len, size_t max);-/* Name, version, signer fingerprint and cert.der (xmalloc'd) of a .bee. */int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info);/*diff --git a/util/bpm_source_config.h b/util/bpm_source_config.hindex e4d7ce51..93564176 100644--- a/util/bpm_source_config.h+++ b/util/bpm_source_config.h@@ -8,7 +8,6 @@#include <stddef.h>-/* Parse one line from a target-local BPM repository source file. */int shirudo_bpm_parse_source_line(char *line,char *endpoint, size_t endpoint_sz,char *key_file, size_t key_file_sz);diff --git a/util/bpm_tree.h b/util/bpm_tree.hindex 490f29f3..70e81224 100644--- a/util/bpm_tree.h+++ b/util/bpm_tree.h@@ -81,10 +81,8 @@ struct shirudo_tree_state {char manifest_digest[128];};-/* Parse the signed tree payload. Unknown JSON fields are ignored. */int shirudo_tree_parse(const char *body, size_t len,struct shirudo_tree_publication *out);-/* Grow the operations array by one copied operation (publisher side). */int shirudo_tree_publication_append(struct shirudo_tree_publication *pub,const struct shirudo_tree_operation *op);void shirudo_tree_publication_free(struct shirudo_tree_publication *pub);@@ -106,14 +104,12 @@ int shirudo_tree_emit_publication(const struct shirudo_tree_publication *pub,*/int shirudo_tree_selector_matches(const struct shirudo_tree_selector *selector);-/* Persistent tree state and selected-operation eventlog. */int shirudo_tree_state_read(struct shirudo_tree_state *out);int shirudo_tree_state_write(const struct shirudo_tree_state *state);int shirudo_tree_event_append(int64_t seq, const char *operation_digest,const uint8_t projection_root[32]);int shirudo_tree_event_replay(uint8_t out[32]);-/* Emit report-only tree state into an already-open JSON object. */void shirudo_tree_emit_status(struct shirudo_json_emit *e);#endif /* SHIRUDO_BPM_TREE_H */diff --git a/util/chain.h b/util/chain.hindex caf48c08..0f690d75 100644--- a/util/chain.h+++ b/util/chain.h@@ -36,16 +36,14 @@void shirudo_sha256(const void *data, size_t len,uint8_t out[SHIRUDO_CHAIN_DIGEST_LEN]);-/* SHA-256 over the concatenation a || b, without allocating a joined buffer. */void shirudo_sha256_2(const void *a, size_t a_len,const void *b, size_t b_len,uint8_t out[SHIRUDO_CHAIN_DIGEST_LEN]);-/* Constant-time equality of two equal-length buffers (1 == equal). */+/* Constant time; 1 when equal. */int shirudo_ct_eq(const void *a, const void *b, size_t n);-/* One upatch of the set an init event covers. */struct shirudo_measured_upatch {char name[SHIRUDO_UPATCH_NAME_MAX + 1];char payload_hex[2 * SHIRUDO_UPATCH_PAYLOAD_HASH_LEN + 1];@@ -86,17 +84,12 @@ struct shirudo_chain_init_info {};/*- * Bind the register to this boot and perform its first write with the- * init event: define (or redefine) the index under a policy computed- * from the anchoring PCR, extend it through the init branch, then- * extend the PCR with the index name so the branch can never be- * satisfied again until the next reset. A register written this boot- * and on record for the TPM's current reset count is reused untouched;- * a record for this reset count whose index is gone, unwritten or- * renamed refuses with -EEXIST, since binding another would restart- * the history the record vouches for. -ENODEV without a TPM, -EACCES+ * Bind the register to this boot and write the init event. A register+ * written this boot and on record is reused; a record whose index is+ * gone, unwritten or renamed is -EEXIST, since binding again would+ * restart the history it vouches for. -ENODEV without a TPM, -EACCES* when the owner hierarchy refuses, -EPROTO when the TPM's name is not- * the computed one, or another -errno.+ * the computed one.*/int shirudo_chain_init(const uint8_t event[SHIRUDO_CHAIN_DIGEST_LEN],struct shirudo_chain_init_info *info);diff --git a/util/conditions.h b/util/conditions.hindex 3b4c7a0d..f40f557e 100644--- a/util/conditions.h+++ b/util/conditions.h@@ -14,11 +14,8 @@#include <stdint.h>/*- * Fields mirror the `shirudo status` JSON one-for-one. `reachable`- * and `parsed` are true for the local caller.- * The *_seen flags reflect "did the JSON carry a non-null value for- * this nullable scalar," since the schema parser leaves them untouched- * on null.+ * The *_seen flags say whether the JSON carried a non-null value,+ * since the parser leaves a null untouched.*/struct shirudo_conditions_input {bool reachable;@@ -51,17 +48,9 @@ struct shirudo_condition {*/#define SHIRUDO_CONDITIONS_MAX 4-/*- * Fill `out[0..cap)` with the security-operator conditions derived- * from `in`. Returns the number actually written (<= cap).- */size_t shirudo_conditions(const struct shirudo_conditions_input *in,struct shirudo_condition *out, size_t cap);-/*- * Print a `Conditions:` block in the same describe-style table the- * rest of the project uses, with consistent column widths.- */void shirudo_conditions_print(const struct shirudo_condition *c, size_t n);/*@@ -72,10 +61,6 @@ void shirudo_conditions_print(const struct shirudo_condition *c, size_t n);*/const char *shirudo_status_verdict(const struct shirudo_conditions_input *in);-/*- * Short reason (no surrounding parens) suitable for inlining on a- * `Status:` line when the verdict isn't ok. Empty when ok.- */void shirudo_status_reason(const struct shirudo_conditions_input *in,char *buf, size_t cap);diff --git a/util/config.h b/util/config.hindex eacdd171..f46fb7ae 100644--- a/util/config.h+++ b/util/config.h@@ -30,18 +30,11 @@ struct shirudo_config {char tpm_owner_auth[SHIRUDO_OWNER_AUTH_MAX];size_t tpm_owner_auth_len;/*- * TCTI override for util/tpm.c. Empty (default) means- * `device:/dev/tpmrm0`. A non-empty value (e.g.- * `swtpm:host=127.0.0.1,port=2321`) redirects to a- * software TPM for dev/CI. The pre-flight skips the- * /dev/tpmrm0 check when the override is set. The- * SHIRUDO_TPM_TCTI env var overrides this in turn.+ * The TCTI of util/tpm.c, empty for /dev/tpmrm0; the environment+ * overrides it.*/char tpm_tcti[SHIRUDO_TPM_TCTI_MAX];- /*- * Periodic `shirudo upatch map --all` export settings. Empty sinks- * are intentionally idle.- */+ /* Empty sinks are idle. */bool map_export_valid;char map_export_json_path[SHIRUDO_MAP_EXPORT_PATH_MAX];char map_export_otel_endpoint[SHIRUDO_MAP_EXPORT_ENDPOINT_MAX];@@ -53,11 +46,7 @@ struct shirudo_config {unsigned int map_export_otlp_max_bytes;};-/*- * Load shirudo.conf into <cfg>, applying defaults first. A missing file- * is not an error (defaults stand). Returns 0, or -errno on an I/O error- * other than ENOENT.- */+/* A missing file is not an error. */int shirudo_config_load(struct shirudo_config *cfg);/* Testable path-specific loader; unlike shirudo_config_load(), no env. */diff --git a/util/crypto.h b/util/crypto.hindex 0f9f0ee4..bef5866c 100644--- a/util/crypto.h+++ b/util/crypto.h@@ -2,12 +2,9 @@/** Copyright (c) 2026 Authors of shirudo*- * Small crypto interface shared by the operator and target profiles.- * Hashing, X.509, CMS verification and the libcurl TLS policy all run- * on OpenSSL (shared on the operator, static on the target), so every- * key algorithm the kernel verifies and the hybrid ML-KEM key exchange- * come from one implementation. Callers must not depend on the- * provider's types.+ * The crypto interface of both profiles, on OpenSSL alone, so every key+ * algorithm the kernel verifies and the hybrid key exchange come from+ * one implementation.*/#ifndef SHIRUDO_CRYPTO_H@@ -36,11 +33,7 @@ int shirudo_sha256_buffer(const void *data, size_t len,int shirudo_base64_encode(const uint8_t *data, size_t len,char *out, size_t out_sz);-/*- * Verify an ECDSA P-256 signature (r, s) over a SHA-256 digest with- * the public point (x, y). Returns 0 when valid, -EKEYREJECTED when- * not, another -errno when the key or signature cannot be built.- */+/* 0 when valid, -EKEYREJECTED when not. */int shirudo_ecdsa_p256_verify(const uint8_t x[32], const uint8_t y[32],const uint8_t digest[SHIRUDO_CRYPTO_SHA256_LEN],const uint8_t r[32], const uint8_t s[32]);@@ -87,7 +80,6 @@ CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr);*/int shirudo_tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca);-/* HMAC-SHA-256 of data under key. */int shirudo_hmac_sha256(const uint8_t *key, size_t key_len,const void *data, size_t len,uint8_t out[SHIRUDO_CRYPTO_SHA256_LEN]);@@ -119,7 +111,6 @@ int shirudo_base64_decode(const char *in, size_t in_len, uint8_t *out,int shirudo_cert_read_der(const uint8_t *der, size_t len,struct shirudo_cert *cert);-/* The raw public key of a certificate: RSA (n, e) or EC P-256 (x, y). */struct shirudo_cert_pubkey {bool rsa;uint8_t n[512];diff --git a/util/elf_target.h b/util/elf_target.hindex f46a62d1..68028b4c 100644--- a/util/elf_target.h+++ b/util/elf_target.h@@ -17,11 +17,9 @@ struct shirudo_elf_target {uint32_t nr_offsets;};-/* Resolve libbpf-style '*'/'?' function glob matches and GNU build ID. */int shirudo_elf_target_resolve(const char *path, const char *pattern,struct shirudo_elf_target *out);-/* Read the GNU build ID from an already-open ELF file descriptor. */int shirudo_elf_build_id_fd(int fd,uint8_t build_id[SHIRUDO_UPATCH_BUILD_ID_MAX],uint32_t *build_id_len);diff --git a/util/eventlog.h b/util/eventlog.hindex 185cb63e..6c2da159 100644--- a/util/eventlog.h+++ b/util/eventlog.h@@ -34,11 +34,7 @@ const char *shirudo_eventlog_pending_path(void);int shirudo_eventlog_append(const char *json_line);int shirudo_eventlog_append_to(const char *path, const char *json_line);-/*- * Fold the pending record into the eventlog: every pending line this- * boot's part of the log does not already hold is appended, then the- * pending file goes. 0 when nothing was pending.- */+/* 0 when nothing was pending. */int shirudo_eventlog_adopt_pending(void);/*@@ -69,7 +65,6 @@ struct shirudo_eventlog_init {int shirudo_eventlog_boot_init(struct shirudo_eventlog_init *out);-/* This boot's records in order, from its last init record on. */int shirudo_eventlog_boot_lines(int (*cb)(const char *line, size_t len,void *ctx), void *ctx);@@ -81,7 +76,6 @@ int shirudo_eventlog_boot_lines(int (*cb)(const char *line, size_t len,*/int shirudo_eventlog_would_exceed(unsigned long max_bytes);-/* Helpers for building eventlog entries. */void shirudo_eventlog_timestamp(char *out, size_t cap); /* ISO-8601 UTC */void shirudo_eventlog_boot_id(char *out, size_t cap); /* /proc boot_id */diff --git a/util/help.h b/util/help.hindex f4579177..801da762 100644--- a/util/help.h+++ b/util/help.h@@ -2,12 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Shared structured-help printer. Every top-level subcommand defines- * a `struct shirudo_help` and prints it through shirudo_print_help()- * on `help` / `--help` / `-h`, so the UX stays consistent with the- * top-level `shirudo help` block: usage line, optional summary,- * one or more named sections of (name, one-line summary), optional- * footer (examples, see-also).+ * The structured help every subcommand prints.*/#ifndef SHIRUDO_HELP_H@@ -34,46 +29,24 @@ struct shirudo_help {const char *footer;};-/* Does argv match "help", "--help" or "-h"? Safe on NULL. */int shirudo_is_help(const char *arg);-/* Does argv match "--list-cmds"? */int shirudo_is_list_cmds(const char *arg);-/* Print to stderr in the top-level `shirudo help` style. */void shirudo_print_help(const struct shirudo_help *h);-/*- * Print the bare names from an items[] array to stdout, one per line.- * The hook bash completion uses (via `shirudo <command> --list-cmds`)- * so newly added subcommands appear in tab-completion without editing- * the completion script.- */+/* What bash completion reads through --list-cmds. */void shirudo_print_subcmd_list(const struct shirudo_help_item *items,size_t n_items);-/*- * Render the unknown-subcommand error for a dispatcher (`shirudo- * unknown command, `shirudo upatch foo`, ...) in the same style the- * top-level `shirudo` dispatcher already uses for unknown commands:- * a "'<bad>' is not a known subcommand" line, a "See ... --help"- * pointer, and Levenshtein-derived "Did you mean one of:" matches- * drawn from `subcmds`. cmd_label identifies the current dispatcher.- */void shirudo_help_unknown_subcommand(const char *cmd_label,const char *bad,const struct shirudo_help_item *subcmds,size_t n_subcmds);/*- * Resolve `input` against `subcmds` using shirudo_resolve()'s tiered- * matching (exact, then unique prefix-of-candidate, then candidate-- * is-prefix-of-input) so that abbreviated supported commands work.- *- * Returns the canonical name on a unique match. Returns NULL on- * failure with stderr already populated: a Levenshtein "Did you- * mean" block when nothing matched, or a "is ambiguous; matches:"- * listing when more than one candidate matched the same tier.+ * NULL on failure with stderr already written: a did-you-mean block,+ * or the ambiguous matches.*/const char *shirudo_resolve_subcommand(const char *cmd_label,const char *input,diff --git a/util/initrd.h b/util/initrd.hindex 873f7bdd..526264e7 100644--- a/util/initrd.h+++ b/util/initrd.h@@ -16,7 +16,6 @@*/bool shirudo_in_initrd(void);-/* The root file system's mount point while the initrd runs. */const char *shirudo_sysroot(void);/*diff --git a/util/io.h b/util/io.hindex 7c42bb7c..6b434f56 100644--- a/util/io.h+++ b/util/io.h@@ -6,7 +6,6 @@#include <stddef.h>-/* Write the complete buffer, retrying EINTR and short writes. */int shirudo_write_all(int fd, const void *buf, size_t len);#endif /* SHIRUDO_IO_H */diff --git a/util/json.h b/util/json.hindex 65e85443..623a794b 100644--- a/util/json.h+++ b/util/json.h@@ -21,7 +21,6 @@#define SHIRUDO_JSON_MAX_STRING_BYTES (16u * 1024u * 1024u)#endif-/* Emitter -- streaming, caller-supplied output buffer. */struct shirudo_json_emit {char *buf;size_t cap;@@ -30,22 +29,17 @@ struct shirudo_json_emit {unsigned depth; /* open-container nesting */uint32_t nonempty; /* bit d set: container at depth d has a member *//*- * Optional streaming sink. Buffer-only callers leave these NULL and- * retain the historical NUL-terminated output contract. Sink callers- * provide a small staging buffer; it is flushed whenever full and once- * explicitly with shirudo_json_emit_flush().+ * Buffer-only callers leave the sink NULL; a sink is flushed when the+ * buffer fills and by shirudo_json_emit_flush().*/int (*sink)(void *ctx, const char *data, size_t len);void *sink_ctx;};/*- * Streaming emitter. Commas and string escaping are handled- * automatically; the caller pairs opens with closes. obj_open emits a- * bare object (the document root, or an array element); arr_open emits- * a keyed array ("key":[...]). On any error (buffer full, bad UTF-8,- * over-nesting) the sticky err latches and further calls are no-ops --- * check e->err once after the final close.+ * Commas and escaping are automatic. On any error the sticky err+ * latches and later calls are no-ops: check it once after the final+ * close.*/void shirudo_json_obj_open(struct shirudo_json_emit *e);void shirudo_json_obj_open_key(struct shirudo_json_emit *e, const char *key);@@ -62,22 +56,16 @@ void shirudo_json_kv_null(struct shirudo_json_emit *e, const char *key);/* Insert an internally-generated, already-valid JSON value verbatim. */void shirudo_json_kv_raw(struct shirudo_json_emit *e, const char *key,const char *value, size_t value_len);-/* Bare array element (string), for arrays of scalars. */void shirudo_json_str(struct shirudo_json_emit *e, const char *val);-/* Bare array element copied verbatim: an already encoded JSON value. */void shirudo_json_raw(struct shirudo_json_emit *e, const char *value,size_t value_len);-/* Flush pending bytes to a configured sink. A no-op for buffer emitters. */int shirudo_json_emit_flush(struct shirudo_json_emit *e);/*- * Schema-driven parser. Not a generic deserialiser: the caller- * declares the top-level keys it cares about and where each value- * goes; the parser dispatches matches and fully parses-and-discards- * everything else (unknown keys, nested objects/arrays). Bounded by- * SHIRUDO_JSON_MAX_BYTES / _DEPTH / _STRING_BYTES so hostile input- * cannot exhaust the stack or a buffer.+ * Not a generic deserialiser: declared keys are dispatched, everything+ * else is parsed and discarded, within bounds so hostile input cannot+ * exhaust the stack or a buffer.*/enum shirudo_json_vtype {SHIRUDO_JSON_T_STRING, /* dst: char[dst_cap] (NUL-terminated) */@@ -88,15 +76,9 @@ enum shirudo_json_vtype {};/*- * Sink for SHIRUDO_JSON_T_ARRAY: the parser dispatches each element- * into the field's sub[] schema (an object element against the whole- * sub[]; a scalar element into sub[0]), resets the sub fields' `seen`- * per element, then calls on_elem(ctx) so the caller can snapshot the- * just-parsed element out of its scratch dst buffers before the next- * element overwrites them. on_elem returns 0 to continue or a negative- * errno to abort the parse. An ARRAY field stores a pointer to this in- * its `dst` (so the field struct itself stays at the original layout- * and existing positional initializers keep compiling).+ * The sub fields' seen flags reset per element; on_elem may copy the+ * element out of the scratch dst buffers before the next one overwrites+ * them, and returns a negative errno to abort.*/struct shirudo_json_array {int (*on_elem)(void *ctx);@@ -114,11 +96,8 @@ struct shirudo_json_field {};/*- * Parse one top-level JSON object. Returns 0 on a well-formed object,- * -EINVAL on malformed input or a scalar/struct type mismatch on a- * declared key, -E2BIG on a bounds violation (size/depth/string),- * -ENOSPC if a declared string value exceeds its dst_cap. Each matched- * field's `seen` is set; callers check it for required keys.+ * -EINVAL on malformed input or a type mismatch, -E2BIG on a bounds+ * violation, -ENOSPC when a string exceeds its dst_cap.*/int shirudo_json_parse(const char *data, size_t len,struct shirudo_json_field *fields, size_t n_fields);diff --git a/util/kernel_abi.h b/util/kernel_abi.hindex 8556d6f9..c2ee9bd9 100644--- a/util/kernel_abi.h+++ b/util/kernel_abi.h@@ -22,7 +22,6 @@ struct btf;int shirudo_kernel_abi_validate_btf(const struct btf *btf,char *detail, size_t detail_sz);-/* Load the running kernel's BTF and validate signed-loader capabilities. */int shirudo_kernel_abi_check(char *detail, size_t detail_sz);#endif /* SHIRUDO_KERNEL_ABI_H */diff --git a/util/kernel_build_id.h b/util/kernel_build_id.hindex a638a276..7c433399 100644--- a/util/kernel_build_id.h+++ b/util/kernel_build_id.h@@ -10,11 +10,9 @@#define SHIRUDO_KERNEL_BUILD_ID_STRING_MAX \(SHIRUDO_KERNEL_BUILD_ID_MAX * 2u + 1u)-/* Parse raw Linux kernel note records and return the GNU build ID as hex. */int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);-/* Read the running kernel's GNU build ID from /sys/kernel/notes. */int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);diff --git a/util/kernel_release.h b/util/kernel_release.hindex a13fedf7..038f6e67 100644--- a/util/kernel_release.h+++ b/util/kernel_release.h@@ -6,7 +6,6 @@#include <stdbool.h>-/* Match a complete kernel release component prefix, such as 6.1. */bool shirudo_kernel_release_prefix_matches(const char *release,const char *prefix);diff --git a/util/keyring.h b/util/keyring.hindex a948a337..308fd379 100644--- a/util/keyring.h+++ b/util/keyring.h@@ -18,10 +18,7 @@ typedef void (*shirudo_keyring_cb)(key_serial_t serial,const char *description,void *ud);-/*- * Look up a named keyring under the user keyring (@u). Returns the- * serial, -ENOKEY if absent, or another -errno on failure.- */+/* -ENOKEY if absent. */key_serial_t shirudo_keyring_find(const char *name);/*@@ -34,9 +31,6 @@ key_serial_t shirudo_keyring_open_or_create(const char *name);*/int shirudo_keyring_unlink_from_user(key_serial_t keyring);-/*- * Add an X.509 cert (DER bytes) as an "asymmetric" key.- */key_serial_t shirudo_keyring_add_cert(key_serial_t keyring,const void *cert, size_t cert_len);@@ -68,9 +62,6 @@ key_serial_t shirudo_keyring_find_cert(key_serial_t keyring,/* Unlink <key> from <keyring>; sealing does not stop this, the LSM may. */int shirudo_keyring_unlink_key(key_serial_t keyring, key_serial_t key);-/*- * Iterate every key linked into <keyring>. Returns 0 / -errno.- */int shirudo_keyring_list(key_serial_t keyring,shirudo_keyring_cb cb, void *ud);diff --git a/util/keys.c b/util/keys.cindex f9202c08..f84ae716 100644--- a/util/keys.c+++ b/util/keys.c@@ -431,7 +431,6 @@ void shirudo_keys_set_digest(const struct shirudo_trusted_set *set,shirudo_keys_anchor_digest(sha, set->n, out);}-/* Write whole, then rename into place; a stale .tmp is overwritten. */int shirudo_keys_write_file(const char *path, const void *data, size_t len){return shirudo_seal_write_file(path, data, len, 0644);diff --git a/util/keys.h b/util/keys.hindex fa545b6b..69e87d1e 100644--- a/util/keys.h+++ b/util/keys.h@@ -58,7 +58,6 @@ int shirudo_keys_load(const char *keys_dir, const char *revoked_dir,int shirudo_keys_read_der(const char *path, unsigned char **out,size_t *out_sz);-/* One certificate's digests, from its DER or from its file. */int shirudo_keys_digest_der(const unsigned char *der, size_t der_sz,uint8_t sha256[32], uint8_t fingerprint[32]);int shirudo_keys_digest_file(const char *path, uint8_t sha256[32],@@ -74,7 +73,6 @@ void shirudo_keys_anchor_digest(const uint8_t (*sha256)[32], size_t n,void shirudo_keys_set_digest(const struct shirudo_trusted_set *set,uint8_t out[32]);-/* Whether <revoked_dir>/<fingerprint>.der exists for this public key. */bool shirudo_keys_is_revoked(const char *revoked_dir,const uint8_t fingerprint[32]);@@ -96,7 +94,6 @@ int shirudo_keys_verify_vouch(const struct shirudo_trusted_set *set,const unsigned char *sig, size_t sig_sz,uint8_t voucher[32]);-/* Write a file whole and rename it into place, mode 0644. */int shirudo_keys_write_file(const char *path, const void *data, size_t len);/*diff --git a/util/kmodules.h b/util/kmodules.hindex d7c38e81..ccb71849 100644--- a/util/kmodules.h+++ b/util/kmodules.h@@ -2,8 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Parse /proc/modules and render an ASCII dependency tree. Used by- * `shirudo status --include-modules`.+ * /proc/modules as a dependency tree, for `status --include-modules`.*/#ifndef SHIRUDO_UTIL_KMODULES_H@@ -37,19 +36,14 @@ struct shirudo_kmod_set {size_t n_deps;};-/* Read /proc/modules into <set>. Returns 0 / -errno. */int shirudo_kmodules_read(struct shirudo_kmod_set *set);void shirudo_kmodules_free(struct shirudo_kmod_set *set);-/* Render as an ASCII tree with the describe-style 2-space indent. */void shirudo_kmodules_print_tree(const struct shirudo_kmod_set *set);/*- * Render the <last_n> most recently loaded modules in reverse-- * chronological order ([ISO ts] name (size, refs=K, Ts since boot)):- * newest at top, oldest at bottom. <boot_sec> is the wallclock instant- * of boot, used to compute the "since boot" column (elapsed time- * between boot and load, not time ago).+ * boot_sec is the wallclock instant of boot: the since-boot column is+ * elapsed from boot, not time ago.*/void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,size_t last_n, int64_t boot_sec);diff --git a/util/kmsg.h b/util/kmsg.hindex 06674160..675a7ca6 100644--- a/util/kmsg.h+++ b/util/kmsg.h@@ -2,8 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Read /dev/kmsg records with ISO wallclock timestamps. No subprocess- * fallback to dmesg(1) -- direct kernel interface only.+ * /dev/kmsg records with wallclock timestamps.*/#ifndef SHIRUDO_UTIL_KMSG_H@@ -20,11 +19,8 @@ struct shirudo_kmsg_record {};/*- * Read the last <cap> records from /dev/kmsg in chronological order- * into <out>. Returns the number written (<= cap) on success, -errno- * otherwise. Records older than the ring buffer's current head are- * silently skipped (the ring buffer wraps; kernel returns EPIPE which- * we treat as "restart and skip ahead").+ * Records the ring buffer has dropped are skipped: EPIPE restarts the+ * read.*/int shirudo_kmsg_tail(struct shirudo_kmsg_record *out, size_t cap);diff --git a/util/macros.h b/util/macros.hindex 3a26e29e..f17141f4 100644--- a/util/macros.h+++ b/util/macros.h@@ -15,13 +15,8 @@#define SHIRUDO_BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))/*- * ARRAY_SIZE(arr) -- element count of a true C array, with a- * compile-time gate that rejects a pointer that has decayed from an- * array (the classic bug). GCC's __builtin_types_compatible_p (also- * supported by clang) returns 1 when `arr` is a pointer (its type- * matches typeof(&arr[0]) = T*) and 0 for a real array (T[N] vs T*- * are not compatible). The bitfield trick then errors out on the- * pointer case while leaving the value unchanged for the array case.+ * ARRAY_SIZE() refuses a pointer: __builtin_types_compatible_p tells+ * T[N] from T*.*/#define ARRAY_SIZE(arr) \(sizeof(arr) / sizeof((arr)[0]) + \diff --git a/util/malloc.h b/util/malloc.hindex 330a549a..21e23c60 100644--- a/util/malloc.h+++ b/util/malloc.h@@ -11,95 +11,53 @@#include <stddef.h>/*- * Allocate size bytes, zero-initialised, returning NULL on failure --- * callers must check and surface -ENOMEM the same way they do for- * malloc(). Unlike git's xmalloc this deliberately does NOT die() on- * OOM: shirudo's one-shot CLIs report the error up their normal path. A- * zero size still returns a freeable non-NULL pointer, so a NULL return- * unambiguously means out-of-memory.+ * NULL on failure, never die(): a one-shot CLI reports -ENOMEM up its+ * normal path. A zero size still returns a freeable pointer, so NULL+ * means out of memory and nothing else.*/void *xmalloc(size_t size);-/*- * Zeroed array allocation. Returns NULL if nmemb * size would overflow- * size_t (checked explicitly, before allocating) or on allocation- * failure; same zero-size handling as xmalloc(). Free the result with- * xfree(ptr, nmemb * size).- */+/* NULL when nmemb * size would overflow. */void *xcalloc(size_t nmemb, size_t size);/*- * Resize an array from old_nmemb to new_nmemb elements of `size`,- * scrubbing the old block. Returns NULL -- leaving ptr untouched, the- * way realloc does on failure -- if either old_nmemb * size or- * new_nmemb * size would overflow size_t (both checked before- * allocating), or on allocation failure.- *- * Unlike realloc this always allocates a fresh zero-initialised block,- * copies the smaller of the two sizes, then explicit_bzero+free's the- * old block -- so the old contents are scrubbed even where a plain- * realloc would have shrunk in place or moved-and-freed without- * clearing. The grown tail is zeroed. Pass ptr == NULL (old_nmemb 0)- * for the initial allocation. Free the result with- * xfree(ptr, nmemb * size).+ * Always a fresh zeroed block, the old one scrubbed and freed, so no+ * content lingers where realloc would shrink in place or move. NULL on+ * overflow or failure leaves ptr untouched.*/void *xreallocarray(void *ptr, size_t old_nmemb, size_t new_nmemb,size_t size);/*- * strdup()/strndup() that return NULL on failure; free the result with- * xstrfree(). The bytes are not pre-zeroed (the copy fills them).- *- * WARNING: xstrdup() calls strlen(s) and so MUST only ever be given a- * trusted, definitely-NUL-terminated string. Never call it on user /- * network / file input or any buffer whose termination you do not- * control -- a missing NUL makes strlen run off the end (out-of-bounds- * read, possible crash or info leak). For anything untrusted or- * unbounded use xstrndup() with a hard upper bound instead; it caps the- * read with strnlen().+ * xstrdup() uses strlen, so it takes a trusted NUL-terminated string+ * alone; untrusted or unbounded input goes through xstrndup() with a+ * bound.*/char *xstrdup(const char *s);char *xstrndup(const char *s, size_t n);/*- * explicit_bzero(ptr, size) then free(ptr); a no-op when ptr is NULL.- * Scrubs so secrets (key material, signatures, TPM auth, verifier logs)- * do not linger in freed heap or a core dump. size is the size that was- * passed to the matching xmalloc()/xcalloc() (nmemb * size for the- * latter).+ * Scrubs, so key material, signatures and TPM auth do not linger in+ * freed heap or a core dump.*/void xfree(void *ptr, size_t size);/*- * Scrub strlen(s) + 1 bytes and free; a no-op when s is NULL. The- * scrub-free companion to xstrdup()/xstrndup(): the length is recovered- * with strlen, which matches the allocation as long as the string was- * not shortened in place (its tail would then go unscrubbed).+ * The length is strlen, so a string shortened in place leaves its tail+ * unscrubbed.*/void xstrfree(char *s);/*- * Escape hatch to release memory the C library allocated for us- * (scandir entry array and entries, getline buffer, realpath result,- * etc.) -- a no-op on NULL. The only legitimate user of libc's free()- * is util/malloc.c itself; everywhere else, code that needs to free- * a libc-owned pointer goes through this wrapper. The poison pragma- * below makes bare malloc/free/strdup a hard build error outside of- * util/malloc.c, so this is the *only* permitted path.+ * The one path for memory libc allocated, as scandir, getline and+ * realpath do; free() itself is poisoned below.*/void shirudo_libc_free(void *p);/*- * Hard build-time ban on libc's own allocators outside util/malloc.c.- * `#pragma GCC poison` rejects any subsequent token appearance of the- * named identifiers, so `malloc(...)`, `free(...)`, etc. become syntax- * errors -- the project must go through x...() / shirudo_libc_free instead.- * util/malloc.c sets SHIRUDO_MALLOC_INTERNAL before including this- * header to opt the implementations out (they're the ones that must- * call the real libc allocators). The pragma sits at the end of the- * header so that system declarations of malloc/free pulled in earlier- * (from <stdlib.h>, <string.h>, ...) are processed before the poison- * takes effect.+ * The poison sits at the end so that the system declarations pulled in+ * earlier are processed first; util/malloc.c opts out with+ * SHIRUDO_MALLOC_INTERNAL.*/#ifndef SHIRUDO_MALLOC_INTERNAL# pragma GCC poison malloc calloc realloc reallocarray free strdup strndup asprintf vasprintfdiff --git a/util/paths.h b/util/paths.hindex 9f5a10ed..d9fd68c8 100644--- a/util/paths.h+++ b/util/paths.h@@ -82,16 +82,13 @@#define SHIRUDO_SEAL_POST_RMXATTR_PIN SHIRUDO_BPFFS_DIR "/seal_inode_post_removexattr_link"#define SHIRUDO_SEAL_INIT_SECURITY_PIN SHIRUDO_BPFFS_DIR "/seal_inode_init_security_link"#define SHIRUDO_BPFFS_UPATCHES_DIR SHIRUDO_BPFFS_DIR "/upatches"-/* The frozen identity map: bpffs device, executable, trust anchor. */#define SHIRUDO_IDENTITY_PIN SHIRUDO_BPFFS_DIR "/identity"-/* The tamper counters: one per guard, counted where it refuses. */#define SHIRUDO_TAMPER_PIN SHIRUDO_BPFFS_DIR "/tamper"/* Operator-side. */#define SHIRUDO_SIGNING_KEY_FILE "signing_key.pem"#define SHIRUDO_SIGNING_KEY_PATH SHIRUDO_KEYS_DIR "/" SHIRUDO_SIGNING_KEY_FILE-/* Inode-xattr label of the filesystem seal (threat-model.rst, target hardening). */#define SHIRUDO_XATTR_NAME "security.bpf.shirudo"/*@@ -101,7 +98,6 @@*/#define SHIRUDO_XATTR_PAYLOAD "security.bpf.shirudo.payload"-/* Named kernel keyring that scopes signature verification. */#define SHIRUDO_KEYRING_NAME "shirudo"/*@@ -126,13 +122,10 @@ int shirudo_key_paths(const char *keys_dir,const char *shirudo_keys_dir_resolve(const char *keys_dir_arg);/*- * Convert a userspace upatch name to a bpffs path component. bpffs- * reserves dots in path components, while the userspace/persisted name- * format permits them (for example, kernel-version-qualified patches).- * The returned component is intentionally only a path representation; the- * Dots are escaped as "~d"; '~' is not permitted by safe_upatch_name, so- * this representation cannot collide with a raw userspace name. The- * original name remains the identity used by the upatch format and eventlog.+ * bpffs reserves dots in path components, which upatch names may+ * carry, so a dot becomes ~d; ~ is not a valid name character, so no+ * raw name collides. The raw name stays the identity in the format and+ * the eventlog.*/static inline int shirudo_upatch_bpffs_name(char *out, size_t out_sz,const char *name)@@ -156,7 +149,6 @@ static inline int shirudo_upatch_bpffs_name(char *out, size_t out_sz,return 0;}-/* Reverse shirudo_upatch_bpffs_name for names read back from bpffs. */static inline int shirudo_upatch_name_from_bpffs(char *out, size_t out_sz,const char *name){diff --git a/util/preflight.h b/util/preflight.hindex 50dc8e79..81343da6 100644--- a/util/preflight.h+++ b/util/preflight.h@@ -40,11 +40,9 @@ struct shirudo_preflight_result {};/*- * Run every prerequisite check. All checks always run and every one is- * hard: there is no opt-out for a missing TPM or a classical- * certificate. n_failed is the total number of failures. The function- * does not write to stdout/stderr/syslog -- the caller presents the- * outcome.+ * Every check runs and every one is hard: no opt-out for a missing TPM+ * or a classical certificate. Nothing is printed; the caller presents+ * the outcome.*/void shirudo_preflight_run(struct shirudo_preflight_result *out);diff --git a/util/report.h b/util/report.hindex ec4b36ed..43054d33 100644--- a/util/report.h+++ b/util/report.h@@ -2,10 +2,9 @@/** Copyright (c) 2026 Authors of shirudo*- * Per-operation JSON report for `upatch load`/`upatch unload --report`.- * The structured input AI agents iterate on -- category/phase tell the- * agent whether it's a policy problem or a code problem, and- * verifier_log carries the kernel's rejection verbatim.+ * The JSON report of `upatch load` and `unload --report`: category and+ * phase tell a policy problem from a code problem, and the verifier+ * log comes verbatim.*/#ifndef SHIRUDO_REPORT_H@@ -41,12 +40,9 @@ struct shirudo_op_report {char chain_after[65];};-/* Emit r as one JSON document to path ("-" for stdout). 0 / -errno. */int shirudo_report_emit(const char *path, const struct shirudo_op_report *r);-/* Copy a verifier log into the report (truncating to the cap). */void shirudo_report_set_log(struct shirudo_op_report *r, const char *log);-/* Free heap-owned report fields. */void shirudo_report_free(struct shirudo_op_report *r);#endif /* SHIRUDO_REPORT_H */diff --git a/util/seal.h b/util/seal.hindex f63cb9dd..039ac7b2 100644--- a/util/seal.h+++ b/util/seal.h@@ -19,20 +19,12 @@#define SHIRUDO_SEAL_LABEL \"94442b45cfcdc59aabc2a91364ed2ae129418e05a5c1985231b9c032e673f469"-/*- * Set security.bpf.shirudo = SHIRUDO_SEAL_LABEL on one inode, a- * symlink's own rather than its target's. Idempotent (create-or-replace).- * Call after creating any regular-fs file under /var/lib/shirudo/ so the- * seal LSM protects it. Returns 0 or -errno.- */+/* A symlink's own inode, not its target's. Idempotent. */int shirudo_seal_label(const char *path);/*- * Label the running binary's inode and walk /var/lib/shirudo/ labelling- * every inode on that filesystem (the bpffs mount is skipped -- bpf2- * guards it). Best-effort per entry. Call BEFORE the seal LSM attaches,- * so the bulk setxattr is not gated. Returns 0 or -errno on a fatal- * (stat/walk) failure.+ * Before the seal attaches, so the bulk setxattr is not gated; best+ * effort per entry.*/int shirudo_seal_label_tree(void);@@ -48,16 +40,11 @@ int shirudo_seal_label_tree(void);* failure, a sealed inode that could not be labelled included.*/-/* Open or create path under its directory. Returns the fd. */int shirudo_seal_open(const char *path, int flags, mode_t mode);/* mkdir -p, every directory created labelled as its parent is. */int shirudo_seal_mkdir_p(const char *path, mode_t mode);-/*- * Replace path by data atomically: written to <path>.tmp beside it,- * labelled and synced, renamed over path, the directory synced.- */int shirudo_seal_write_file(const char *path, const void *data, size_t len,mode_t mode);diff --git a/util/sign.h b/util/sign.hindex 36cf66a5..beb25bcd 100644--- a/util/sign.h+++ b/util/sign.h@@ -14,14 +14,9 @@#define SHIRUDO_SHA256_LEN 32/*- * Caller supplies the loader instructions and the gen_loader metadata- * blob (data), plus a signature buffer of capacity signature_sz. The- * signature and the payload hash both span the concatenation- * insns || data -- the exact bytes the kernel reconstructs and verifies- * at BPF_PROG_LOAD (see Documentation/bpf/signing.rst). data may be- * NULL/0 for a loader with no metadata. On success signature_sz is- * overwritten with the actual size and payload_sha256 holds- * SHA-256(insns || data).+ * The signature and payload_sha256 both span insns || data, the bytes+ * the kernel reconstructs at BPF_PROG_LOAD; data may be empty.+ * signature_sz comes back as the actual size.*/struct shirudo_sign_io {const void *insns;@@ -37,11 +32,8 @@ struct shirudo_sign_io {};/*- * CMS-sign io->insns || io->data with the PEM private key at pkey_path- * and the X.509 cert at cert_path (DER or PEM, auto-detected). Returns- * 0 on success or a negative errno: -ENOSPC if the signature buffer is- * too small, -EINVAL on parse failure, -EIO on OpenSSL marshalling- * failure, -ENOMEM on allocation failure.+ * -ENOSPC when the signature buffer is too small, -EINVAL on a parse+ * failure, -EIO on an OpenSSL failure.*/int shirudo_cms_sign(struct shirudo_sign_io *io,const char *pkey_path, const char *cert_path);diff --git a/util/similar.h b/util/similar.hindex ca208ef6..47358c9d 100644--- a/util/similar.h+++ b/util/similar.h@@ -2,9 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Edit-distance "did you mean ..." helper used by the top-level- * subcommand dispatcher when the user mistypes a command. Keep it- * small and allocation-free: shirudo's command set is tiny.+ * The did-you-mean helpers of the dispatchers, allocation-free.*/#ifndef SHIRUDO_SIMILAR_H@@ -24,37 +22,18 @@ struct shirudo_suggestion {int dist;};-/*- * Levenshtein edit distance between s and t, capped at `max`: returns- * the real distance when it fits, or any value > max otherwise (with- * early exit). NUL-terminated inputs; either side longer than- * SHIRUDO_SIMILAR_MAX_LEN is reported as "exceeds max".- */+/* Any value above max once the cap is exceeded, with an early exit. */int shirudo_edit_distance(const char *s, const char *t, int max);-/*- * Pick up to `cap` candidates from `commands[0..n_commands)` whose- * edit distance to `name` is at most `max_dist`. Writes them into- * `out` sorted by ascending distance and returns the count. `out` is- * a caller-provided stack array of size `cap`.- */size_t shirudo_suggest(const char *name,const char *const *commands, size_t n_commands,int max_dist,struct shirudo_suggestion *out, size_t cap);/*- * Resolve `input` against `candidates[0..n)` and fill `matches[]`- * with the indices that match, returning the count (clamped to cap).- *- * Three resolution tiers, short-circuit at the first that hits:- * 1. exact match (strcmp).- * 2. input is a prefix of candidate ("node" -> "nodes", "li" -> "list").- * 3. candidate is a prefix of input ("remotes" -> "remote").- *- * Caller dispatches on count: 1 = unique match (matches[0]), 0 = no- * match (let Levenshtein "did you mean" kick in), >1 = ambiguous- * (list `matches` to the user).+ * Three tiers, the first that hits wins: exact, input a prefix of a+ * candidate, candidate a prefix of input. The count tells unique from+ * none from ambiguous.*/size_t shirudo_resolve(const char *input,const char *const *candidates, size_t n,diff --git a/util/sysinfo.h b/util/sysinfo.hindex b6391b79..90afba01 100644--- a/util/sysinfo.h+++ b/util/sysinfo.h@@ -2,9 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Host system overview gathered from /proc, /etc and uname(2) -- no- * subprocess. Surfaced by `shirudo status --include-system` and- * rendered by `shirudo status`.+ * The host overview of `status --include-system`, without a subprocess.*/#ifndef SHIRUDO_SYSINFO_H@@ -25,11 +23,7 @@ struct shirudo_sysinfo {long mem_total_kb; /* total RAM in KiB, -1 if unknown */long mem_avail_kb; /* MemAvailable in KiB, -1 if unknown */long uptime_sec; /* seconds since boot, -1 if unknown */- /*- * Root-filesystem capacity, statvfs("/"). "Used" is total minus the- * non-reserved free space (matches `df` row's Used column). -1 when- * the statvfs call failed.- */+ /* Used is total minus the non-reserved free space, as df reports it. */long disk_total_kb;long disk_used_kb;};@@ -42,16 +36,10 @@ struct shirudo_json_emit;typedef void (*shirudo_kernel_config_cb)(void *ctx, const char *key,const char *value);-/* Visit each CONFIG_* entry ... in lexical key order. */int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,shirudo_kernel_config_cb cb,void *ctx);-/*- * Emit *si as a JSON "system":{...} object, including the string-valued- * kernel_config map loaded from /boot/config-<uname -r>. The single source- * of truth for the `shirudo status --include-system` JSON shape.- */void shirudo_sysinfo_emit_json(struct shirudo_json_emit *e,const struct shirudo_sysinfo *si);diff --git a/util/tamper.h b/util/tamper.hindex 846a60a8..3e5e9036 100644--- a/util/tamper.h+++ b/util/tamper.h@@ -16,9 +16,7 @@ struct shirudo_tamper_counts {uint64_t total;};-/* The name status and the keepalive report a point under. */const char *shirudo_tamper_name(enum shirudo_tamper_point point);-/* What a count at that point means. */const char *shirudo_tamper_meaning(enum shirudo_tamper_point point);/*diff --git a/util/timefmt.h b/util/timefmt.hindex b8bbbd28..971219f4 100644--- a/util/timefmt.h+++ b/util/timefmt.h@@ -2,10 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Compact duration formatting -- the single source of truth shared- * by local status and target inspection output, and any future column- * that wants the same look- * ("12s", "5m", "3h", "7d").+ * Compact durations: 12s, 5m, 3h, 7d.*/#ifndef SHIRUDO_TIMEFMT_H@@ -13,15 +10,7 @@#include <stddef.h>-/*- * Format `seconds` into `buf` using the largest sensible unit:- * < 60s -> "<n>s"- * < 60m -> "<n>m"- * < 24h -> "<n>h"- * else -> "<n>d"- * A negative `seconds` writes "?" (used for "unknown" durations).- * `cap` must be at least 24 bytes for the worst-case "%ldd" + NUL.- */+/* A negative seconds writes "?"; cap must hold the worst-case %ldd. */void shirudo_format_duration(long seconds, char *buf, size_t cap);#endif /* SHIRUDO_TIMEFMT_H */diff --git a/util/tpm.h b/util/tpm.hindex 38675c24..c6997fb1 100644--- a/util/tpm.h+++ b/util/tpm.h@@ -25,7 +25,6 @@ struct shirudo_tpm;int shirudo_tpm_open(struct shirudo_tpm **out);void shirudo_tpm_close(struct shirudo_tpm *t);-/* PCRs of the SHA-256 bank. */int shirudo_tpm_pcr_read(struct shirudo_tpm *t, unsigned int pcr,uint8_t out[SHIRUDO_TPM_DIGEST_LEN]);int shirudo_tpm_pcr_extend(struct shirudo_tpm *t, unsigned int pcr,diff --git a/util/tpm_wire.h b/util/tpm_wire.hindex cb2ffe3f..442fafea 100644--- a/util/tpm_wire.h+++ b/util/tpm_wire.h@@ -39,7 +39,6 @@#define SHIRUDO_TPM_REGISTER_ATTRS 0x0E060048u#define SHIRUDO_TPM_NV_WRITTEN 0x20000000u-/* Policy digest evolution for the assertions the register uses. */void shirudo_tpm_policy_nv_written(const uint8_t prev[SHIRUDO_TPM_DIGEST_LEN],bool written,uint8_t out[SHIRUDO_TPM_DIGEST_LEN]);@@ -63,7 +62,6 @@ void shirudo_tpm_register_policy(uint32_t pcr_mask,uint8_t branch_init[32],uint8_t policy[32]);-/* TPML_PCR_SELECTION with one SHA-256 bank over the 24 PCRs in mask. */void shirudo_tpm_pcr_selection(uint32_t pcr_mask,uint8_t out[SHIRUDO_TPM_PCR_SELECTION_LEN]);@@ -73,7 +71,6 @@ void shirudo_tpm_nv_name(uint32_t index, uint32_t attrs,uint16_t data_size,uint8_t name[SHIRUDO_TPM_NAME_LEN]);-/* Name of a SHA-256-named object from its marshalled TPMT_PUBLIC. */int shirudo_tpm_object_name(const uint8_t *public, size_t len,uint8_t name[SHIRUDO_TPM_NAME_LEN]);@@ -133,7 +130,6 @@ struct shirudo_tpm_ecc_public {uint8_t y[32];};-/* Parse a marshalled TPMT_PUBLIC of a P-256 ECDSA key. */int shirudo_tpm_ecc_public_parse(const uint8_t *buf, size_t len,struct shirudo_tpm_ecc_public *out);@@ -164,7 +160,6 @@ int shirudo_tpm_credential_protect(const uint8_t seed[32],const uint8_t credential[SHIRUDO_TPM_CREDENTIAL_LEN],uint8_t out[SHIRUDO_TPM_ID_OBJECT_LEN]);-/* Parse a marshalled TPMT_SIGNATURE carrying ECDSA/SHA-256 r and s. */int shirudo_tpm_ecdsa_signature_parse(const uint8_t *buf, size_t len,uint8_t r[32], uint8_t s[32]);diff --git a/util/upatch.h b/util/upatch.hindex e6ae8d7f..c74de307 100644--- a/util/upatch.h+++ b/util/upatch.h@@ -17,7 +17,6 @@ struct shirudo_upatch {const unsigned char *map;size_t map_size;size_t header_size;- /* Parsed signed decoder blob (all zero when absent). */const struct shirudo_upatch_decoder_blob *decoder_blob;uint32_t decoder_blob_len;uint32_t nr_decoders;diff --git a/util/upatch_decode.h b/util/upatch_decode.hindex 87e5b7fe..2985694a 100644--- a/util/upatch_decode.h+++ b/util/upatch_decode.h@@ -14,16 +14,9 @@struct shirudo_map_view;/*- * Try to decode a complete map view with a signed decoder embedded in- * /var/lib/shirudo/upatches/<upatch>.upatch.- *- * On success, *out receives an xmalloc-owned JSON document and *out_len- * receives strlen(*out). Free with xfree(*out, *out_len + 1).- *- * Returns:- * 0 decoded- * -ENOENT no usable decoder; export callers must fail the map- * -errno decoder/runtime error; caller should report failure+ * The decoder is the signed one in the archived upatch. *out is+ * xmalloc'd; -ENOENT without a usable decoder, which an export treats+ * as failing the map.*/int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,char **out, size_t *out_len);@@ -33,10 +26,6 @@ int shirudo_upatch_decode_map_json_limit(const struct shirudo_map_view *v,size_t max_bytes,char **out, size_t *out_len);-/*- * Decode the map and encode the Lua return value as an OTLP AnyValue JSON- * fragment. The caller owns *out as above. Return values match the JSON API.- */int shirudo_upatch_decode_map_otel(const struct shirudo_map_view *v,char **out, size_t *out_len);@@ -51,7 +40,6 @@ int shirudo_upatch_decode_map_file_otel(const char *path,const struct shirudo_map_view *v,char **out, size_t *out_len);-/* Return the static, signature-covered export signal of the matching decoder. */int shirudo_upatch_decode_map_signal(const struct shirudo_map_view *v,uint32_t *signal_out);diff --git a/util/upatch_maps.h b/util/upatch_maps.hindex 68e1e136..5904749a 100644--- a/util/upatch_maps.h+++ b/util/upatch_maps.h@@ -2,15 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * Read pinned upatch maps under /run/shirudo/bpffs/upatches/<name>/- * maps/<map>. Shared by `shirudo upatch map` (CLI), `shirudo status- * --include-maps` (target-local JSON/human), and direct target inspection- * (operator pulls the same JSON over SSH).- *- * Surface targets the common observability case (counters, small- * hash tables). Richer types degrade gracefully unless an upatch pins- * a serializer for the map; arena maps without a serializer are listed- * as skipped instead of being read generically.+ * The pinned maps of loaded upatches, for `upatch map` and status.+ * Arena maps are read through the upatch's serializer alone.*/#ifndef SHIRUDO_UTIL_UPATCH_MAPS_H@@ -30,11 +23,6 @@struct shirudo_json_emit;-/*- * One key+value pair as the reader produced it. The raw key/value- * bytes are heap-owned (xmalloc); render code decides how to- * format them based on the surrounding `shirudo_map_view`.- */struct shirudo_map_entry {void *key; /* key_size bytes */void *value; /* value_stride * (per-CPU ? n_cpus : 1) */@@ -94,11 +82,7 @@ struct shirudo_map_view {void shirudo_map_view_free(struct shirudo_map_view *v);-/*- * Lightweight directory enumeration: list every pinned map across- * every loaded upatch, with name/type/max_entries only (no entry- * read). out[] is xmalloc'd, free with shirudo_map_summary_free().- */+/* Name, type and max_entries alone, without reading entries. */struct shirudo_map_summary {char upatch[64];char name[SHIRUDO_MAP_NAME_MAX + 1];@@ -135,28 +119,18 @@ int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,uint32_t max_entries_cap, uint32_t flags,struct shirudo_map_view *out);-/* Human-readable describe-style render. */void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,size_t n);void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v);-/* Compact one-liner used inside the upatches loaded section. */void shirudo_upatch_map_print_inline(const struct shirudo_map_summary *m);-/*- * Emit one map view. The fields-only helper is for callers that are- * already inside the object that should carry the map details; the- * object helper is for callers wrapping map views in arrays.- *- * NULL `v` emits nothing. The shape is part of the status report format,- * so target-local status output remains stable.- */+/* NULL v emits nothing. The shape is part of the status report. */void shirudo_upatch_maps_emit_json_fields(struct shirudo_json_emit *e,const struct shirudo_map_view *v);void shirudo_upatch_maps_emit_json_object(struct shirudo_json_emit *e,const struct shirudo_map_view *v);-/* Shared value formatting used by local and telemetry emitters. */bool shirudo_upatch_map_is_percpu(uint32_t type);uint32_t shirudo_upatch_map_value_stride(const struct shirudo_map_view *v);char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,diff --git a/util/upatch_resolve.h b/util/upatch_resolve.hindex be8ce9a8..142b15fc 100644--- a/util/upatch_resolve.h+++ b/util/upatch_resolve.h@@ -2,13 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Per-upatch resolvers shared by `shirudo status` and- * `shirudo upatch get`: turn a loaded upatch's bpffs pin- * into the attach-hook string (lsm/foo, fentry/bar, ...) and the- * loaded-at timestamp (pin ctime).- *- * All operations are read-only bpf() ops + stat(2) on shirudo's- * private bpffs -- LSM-allowed for the calling exe.+ * The hook string and load time of a loaded upatch, from its pin.*/#ifndef SHIRUDO_UTIL_UPATCH_RESOLVE_H@@ -27,26 +21,13 @@ struct btf;*/int shirudo_upatch_open_first_link(const char *name);-/*- * Resolve an upatch name to its SEC()-style attach string in `out`- * (e.g. "lsm/socket_create", "fentry/tcp_v4_connect"). Returns 0 and- * empty-string out on success; -errno otherwise. `vbtf` may be NULL- * (the name resolution then degrades to bare prefix without hook).- */+/* vbtf may be NULL; the location then degrades to the bare prefix. */int shirudo_upatch_resolve_location(struct btf *vbtf, const char *name,char *out, size_t cap);-/*- * Stamp the pin directory ctime as an ISO-8601 UTC timestamp; "" on- * failure or absence. Used as the AGE basis in the upatches table.- */void shirudo_upatch_loaded_at(const char *name, char *out, size_t cap);-/*- * Read the bpffs `security.bpf.shirudo.payload` xattr (32 raw bytes)- * and lowercase-hex-encode it. `cap` should be >= 65. Empty out on- * any failure (pin absent, kernel without bpffs-xattr support, etc.).- */+/* Empty on any failure. */void shirudo_upatch_payload_sha256(const char *name, char *out, size_t cap);#endif /* SHIRUDO_UTIL_UPATCH_RESOLVE_H */diff --git a/util/upatch_table.h b/util/upatch_table.hindex 87129c4e..7e06fe71 100644--- a/util/upatch_table.h+++ b/util/upatch_table.h@@ -2,13 +2,7 @@/** Copyright (c) 2026 Authors of shirudo*- * Shared NAME / LOCATION / MAPS / AGE renderer for the "upatches- * loaded" section. Used by:- * - `shirudo status` (local view, both human and --json).- *- * The caller assembles a row[] vector from the target-local file walk;- * the renderer doesn't- * touch syscalls or eventlog state itself.+ * The upatches-loaded table of `shirudo status`.*/#ifndef SHIRUDO_UTIL_UPATCH_TABLE_H@@ -31,25 +25,13 @@ struct shirudo_upatch_table_row {char payload_sha256[65]; /* "" if unavailable; JSON only */};-/*- * Print the table to stdout. Renders the heading line "upatches- * loaded (N):" and an empty body when n == 0.- */void shirudo_upatch_table_print(const struct shirudo_upatch_table_row *rows,size_t n);-/*- * Emit the JSON "upatches_loaded": [...] array on the open emitter.- * Caller has already opened the parent object.- */void shirudo_upatch_table_emit_json(struct shirudo_json_emit *e,const struct shirudo_upatch_table_row *rows,size_t n);-/*- * Derive a wall-clock age in seconds from an ISO-8601 UTC timestamp.- * Returns -1 if ts is empty / unparseable.- */int64_t shirudo_upatch_age_sec(const char *ts);#endif /* SHIRUDO_UTIL_UPATCH_TABLE_H */