feat: add ReadIMARuntimeMeasurementsCount exported helper#58
Merged
Conversation
Exposes the IMA runtime measurement count from /sys/kernel/security/ima/runtime_measurements_count. No side effects. Useful for diagnostics and for callers building before/after probes. Co-authored-by: Ona <no-reply@ona.com>
Extract path parameter from readMeasurementCount so tests can supply temp files instead of requiring /sys/kernel/security/ima. Co-authored-by: Ona <no-reply@ona.com>
Covers valid count, zero, whitespace, malformed content, empty file, and missing file. Co-authored-by: Ona <no-reply@ona.com>
This was referenced May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
ReadIMARuntimeMeasurementsCount() (int, error)— exported helper that reads/sys/kernel/security/ima/runtime_measurements_countand returns the current count. No side effects, no caching. Linux-only (same build constraint as the other IMA probes).Motivation
Callers building eBPF/IMA integrations need the raw measurement count to construct their own before/after probes (e.g., "did executing this binary increase the count?"). The existing
probeIMAAnyMeasurementActiveuses this internally but doesn't expose the count. Exporting it gives callers a building block without duplicating the file-read logic.This is the first of three follow-up PRs after #57:
ReadIMARuntimeMeasurementsCountProbeIMAExecMeasurementActive— fresh temp binary, no count>1 shortcutProbeIMAFileCheckMeasurementActive— fresh temp file, same patternDesign notes
SystemFeaturesorformat.goString()output: the count is a point-in-time read, not a cached probe result. Adding it toSystemFeatureswould change the struct's semantics from "snapshot of feature availability" to "snapshot of runtime state".ProbeIMAAnyMeasurementActive(Linux-only exported function, compiles cleanly on other platforms because nothing cross-platform references it).