Skip to content

feat: add ProbeIMAFileCheckMeasurementActive#60

Merged
leodido merged 7 commits into
mainfrom
add-probe-ima-file-check-measurement-active
May 12, 2026
Merged

feat: add ProbeIMAFileCheckMeasurementActive#60
leodido merged 7 commits into
mainfrom
add-probe-ima-file-check-measurement-active

Conversation

@leodido
Copy link
Copy Markdown
Owner

@leodido leodido commented May 12, 2026

Added

ProbeIMAFileCheckMeasurementActive() ProbeResult — checks whether an IMA measurement rule covering file open (e.g., func=FILE_CHECK) is active by creating a fresh temporary file, then opening it O_RDONLY and checking for a measurement count increase.

Semantic contract

  • Returns Supported=true only when the controlled file-open stimulus increments the IMA measurement count
  • No count > 1 shortcut (unlike ProbeIMAAnyMeasurementActive)
  • Uses a fresh inode to avoid false negatives from IMA's per-inode measurement cache
  • Rewrites the file with unique random content before the baseline count — invalidates the per-inode cache from the initial create and ensures the digest has not been seen before in IMA's global hash table
  • Uses a non-tmpfs temp directory — prefers /var/tmp, then os.TempDir() if non-tmpfs; returns Error if no writable non-tmpfs candidate exists
  • Failed count read or failed file operations → Supported=false with Error set
  • Direct Linux-only helper, not wired into Feature/Check/SystemFeatures yet

Why FILE_CHECK needs different windowing than BPRM_CHECK

For the exec probe (#59), the temp binary is materialized before the baseline count and the exec is the only operation in the window. FILE_CHECK is trickier: the open() that creates the temp file may itself trigger a FILE_CHECK measurement. The probe handles this by:

  1. Creating the file (may trigger FILE_CHECK — doesn't matter, happens before baseline)
  2. Rewriting the file with unique random content to invalidate IMA's per-inode cache and avoid global hash-table deduplication
  3. Taking the baseline count
  4. Opening O_RDONLYthis is the stimulus
  5. Taking the count again

The O_RDONLY stimulus is consistent with IMA's documented FILE_CHECK behavior, where FILE_CHECK triggers on file open and can be qualified with mask=MAY_READ.

Correctness fixes (also applied to exec probe)

Two fixes applied to both ProbeIMAExecMeasurementActive and ProbeIMAFileCheckMeasurementActive:

  1. Unique content per invocation: IMA maintains a global hash table and may suppress measurements for content it has already seen. The exec probe now appends random bytes to the copied ELF (past the segment table, does not affect execution). The file-check probe rewrites with unique random content before the baseline.

  2. Non-tmpfs temp directory: Common IMA policies (e.g., the default tcb policy) exclude tmpfs before FILE_CHECK/BPRM_CHECK rules. Both probes now prefer /var/tmp, then os.TempDir() if non-tmpfs; they return Error if no writable non-tmpfs candidate exists rather than silently falling back to tmpfs.

Series

This is PR 3 of 3 after #57:

  1. feat: add ReadIMARuntimeMeasurementsCount exported helper #58ReadIMARuntimeMeasurementsCount
  2. feat: add ProbeIMAExecMeasurementActive #59ProbeIMAExecMeasurementActive
  3. This PRProbeIMAFileCheckMeasurementActive

leodido and others added 3 commits May 12, 2026 14:12
Checks whether an IMA measurement rule covering file open (e.g.,
func=FILE_CHECK) is active by creating a fresh temporary file,
rewriting it to invalidate any IMA measurement cache from the initial
create, then opening it O_RDONLY and checking for a count increase.

The measurement window contains only the O_RDONLY open — the canonical
FILE_CHECK stimulus. No count > 1 shortcut.

Co-authored-by: Ona <no-reply@ona.com>
Tests that createFreshTempFile creates a non-empty regular file and
that cleanup removes the temp directory.

Co-authored-by: Ona <no-reply@ona.com>
@github-actions github-actions Bot added the enhancement New feature or request label May 12, 2026
leodido and others added 2 commits May 12, 2026 14:22
Two correctness fixes for IMA exec and file-check probes:

1. Append unique random bytes per invocation so IMA's global hash-table
   deduplication does not suppress repeated measurements of the same
   content across probes in the same boot.

2. Prefer /var/tmp over the default temp dir to avoid tmpfs, which
   common IMA policies exclude before FILE_CHECK/BPRM_CHECK rules.
   Falls back to the default temp dir if /var/tmp is unavailable or
   itself on tmpfs.

Co-authored-by: Ona <no-reply@ona.com>
Tests uniqueness across calls, tmpfs detection for nonexistent paths,
and that imaProbeTempDir creates a directory on non-tmpfs when /var/tmp
is available.

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido self-assigned this May 12, 2026
leodido and others added 2 commits May 12, 2026 14:27
Try all candidates (/var/tmp, os.TempDir) and continue to the next on
write failure. Return an error with accumulated reasons if no writable
non-tmpfs directory is available, so the probe result is 'inconclusive'
rather than a misleading Supported=false from a tmpfs-excluded stimulus.

Co-authored-by: Ona <no-reply@ona.com>
Produces a proper error chain instead of formatting []error with %v.

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido changed the title feat: add ProbeIMAFileCheckMeasurementActive feat: add ProbeIMAFileCheckMeasurementActive May 12, 2026
@leodido leodido merged commit 6dc5c86 into main May 12, 2026
8 checks passed
@leodido leodido deleted the add-probe-ima-file-check-measurement-active branch May 12, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant