Skip to content

Scope analysis loggers to the firmware process subtree - #870

Merged
lacraig2 merged 3 commits into
mainfrom
scope-analysis-loggers
Jun 26, 2026
Merged

Scope analysis loggers to the firmware process subtree#870
lacraig2 merged 3 commits into
mainfrom
scope-analysis-loggers

Conversation

@lacraig2

Copy link
Copy Markdown
Collaborator

Problem

Per-process analysis loggers (shell coverage, syscalls, read/write, exec, binds, …) capture every process from boot — including Penguin's own infrastructure: the boot/init machinery and the backgrounded vpnguin/console/guesthopper helpers that run for the entire guest lifetime. The boundary we want is process attribution (the firmware-under-analysis subtree), not a temporal cutoff — a readiness gate can't exclude vpnguin, which runs the whole time.

bb_cov already hinted at this with a fragile, shell-only filename.startswith("/igloo/") filter; this replaces it with one principled mechanism covering all loggers.

Mechanism: inherited UTS-namespace marker, anchored on the initial namespace

init.sh runs the real guest init in a fresh UTS namespace at handoff (unshare -u, with a CONFIG_UTS_NS fallback so boot can't break). The firmware subtree inherits that namespace across fork/exec, so it lives outside the kernel's initial namespace while all Penguin infrastructure stays in it (including call_usermodehelper spawns). The igloo_driver gates syscall/exec/bind hypercall emission on current's namespace, which auto-scopes every logger fed by those hypercalls. Anchoring on the initial namespace means firmware that re-unshares its own namespace stays in scope.

Changes

  • pyplugins/core/scope.py (new) — enables driver-side gating when core.analysis_scope is set (via the set_scope_enabled portal op), early enough to also exclude pre-handoff boot machinery. Exposes plugins.scope.in_scope(pid), tracking in-scope pids from the (now driver-gated) exec_event stream.
  • pyplugins/apis/syscalls.py — new scope_filter param on syscall(), defaulting to a hook's read_only value and plumbed into the kernel hook's scope_filter_enabled. Read-only logging hooks auto-scope; intervention hooks are unaffected.
  • pyplugins/hyper/shell.py — replace the ad-hoc /igloo/ path filter with a lineage-correct plugins.scope.in_scope(pid) gate.
  • pyplugins/{apis/execs,loggers/rw_logger,analysis/ficd,analysis/interfaces}.py — opt into scope_filter=True (they don't pass read_only). syscalls_logger already auto-scopes via read_only=True.
  • src/resources/init.sh — handoff → exec /igloo/utils/busybox unshare -u "${igloo_init}".
  • src/penguin/penguin_config/structure.py (+ regenerated docs/schema_doc.md) — core.analysis_scope (default true; set false to capture every process for debugging).
  • src/penguin/defaults.py — enable the scope plugin by default.

env.py is intentionally left unscoped: its getenv/strstr hypercalls come from the libnvram LD_PRELOAD shim, which lib_inject injects only into firmware binaries, so it is already firmware-scoped by construction.

Testing

peng image (with the matching igloo_driver change) boots and runs the full test_target (rc 0) with scoping enabled; every logger subtest passes (netbinds, netbinds_lifecycle, env_cmp, env_unset, …), confirming in-scope firmware processes are still captured and the unshare doesn't break boot. The only failing subtest (indiv_debug+gdbserver) fails identically on the pre-scope baseline — environmental (broken vhost-vsock in the test runner), not a regression.

Dependencies

@lacraig2
lacraig2 force-pushed the workspace/fixanalysis branch from ef8f32a to 209eedf Compare June 25, 2026 13:12
@lacraig2
lacraig2 force-pushed the scope-analysis-loggers branch from a5a17e7 to e3b9569 Compare June 25, 2026 13:12
Base automatically changed from workspace/fixanalysis to main June 25, 2026 13:43
lacraig2 added 2 commits June 26, 2026 08:56
Per-process analysis loggers captured every process from boot, including
Penguin's own infrastructure (boot machinery and the backgrounded vpnguin/
console/guesthopper helpers that run the whole guest lifetime). Scope analysis
to the firmware-under-analysis subtree instead.

init.sh runs the real guest init in a fresh UTS namespace (unshare -u, with a
CONFIG_UTS_NS fallback), so the firmware subtree lives outside the kernel's
initial namespace while Penguin infrastructure stays in it. The igloo_driver
gates syscall/exec/bind hypercall emission on that distinction, which
auto-scopes every logger fed by those hypercalls.

- core/scope.py (new): enables driver-side gating when core.analysis_scope is
  set; exposes plugins.scope.in_scope(pid), tracking in-scope pids from the
  (now driver-gated) exec_event stream.
- apis/syscalls.py: new scope_filter param on syscall(), defaulting to a hook's
  read_only value and plumbed into the kernel hook's scope_filter_enabled. So
  read-only logging hooks auto-scope; interventions are unaffected.
- hyper/shell.py: replace the ad-hoc '/igloo/' path filter with a principled
  plugins.scope.in_scope(pid) gate (lineage-correct, not path-based).
- analysis/{ficd,interfaces}, apis/execs, loggers/rw_logger: opt into
  scope_filter=True (they don't pass read_only).
- penguin_config/structure.py: add core.analysis_scope (default true); set
  false to capture every process for debugging.
- defaults.py: enable the scope plugin by default.

env.py is intentionally left unscoped: its getenv/strstr hypercalls come from
the libnvram LD_PRELOAD shim, which lib_inject injects only into firmware
binaries, so it is already firmware-scoped by construction.

Depends on the igloo_driver scope change (scope_filter_enabled hook field +
set_scope_enabled portal op + igloo_in_scope gating).
Generalize core.analysis_scope from a bool to a string so its meaning can
evolve without a schema change. Recognized values: 'firmware' (default;
scope to the firmware subtree), 'none' (capture everything), and 'infra'
(reserved for the inverted 'only Penguin's tools' interpretation).
Booleans still validate for backward compatibility (true=='firmware',
false=='none'); scope.py normalizes them at load.

Bump IGLOO_DRIVER_VERSION to 0.0.85, which ships the scope-gating driver
support (igloo_driver #84) this branch depends on.
@lacraig2
lacraig2 force-pushed the scope-analysis-loggers branch from e3b9569 to 7e9e36d Compare June 26, 2026 12:56
Previously scope_filter defaulted to a hook's read_only value, so only
logging hooks auto-scoped while interventions ran for every process. Flip
the default: any hook added in a default context is meant to analyze or
affect the firmware-under-analysis, not Penguin's own plumbing, so all
hooks now scope to the firmware subtree by default.

The portal transport (sendto PORTAL_MAGIC) must keep running for infra --
it carries init.sh's readiness signal and scope.py's own enable -- so it
opts out with scope_filter=False. The explicit scope_filter=True markers on
execs/rw_logger/ficd/interfaces are now the default and dropped.

Tests exercise Penguin infrastructure, so the unit-test fixtures set
core.analysis_scope: none to observe every process.
@lacraig2
lacraig2 merged commit 800bead into main Jun 26, 2026
15 checks passed
@lacraig2
lacraig2 deleted the scope-analysis-loggers branch June 26, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant