Skip to content

feat(sandboxpolicy): pending-slot bindings and EPERM for Strict tracking faults - #1160

Draft
matthyx wants to merge 21 commits into
mainfrom
omx/nri-s1-pending-slot
Draft

matthyx wants to merge 21 commits into
mainfrom
omx/nri-s1-pending-slot

Conversation

@matthyx

@matthyx matthyx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This is groundwork for the NRI start gate, and it changes no behavior on its own. A sandbox binding can now point at PendingSlot, a slot index that is never published. The file, network and privilege programs already treat an unpublished slot as a structural fault, so a pending pod mark already does what the gate needs:

  • a Strict task is denied with EPERM;
  • an Audit task runs and is counted in the node-wide section-error counter.

There is no BPF map or layout change. Nothing writes a pending binding yet; the NRI writer comes in a later PR.

Enforcement library

  • Binding.Strict and PendingSlot.
  • classOf: a pending binding takes its class from the binding, a real slot only from the slot. An in-place Strict→Audit flip therefore never leaves BINDING_STRICT behind.
  • validate refuses Strict on a real slot.
  • Rebind swaps a cgroup binding's identity in one map write.
  • HealNode, Kept, rewriteClass, the adoption reconcile and slotGate handle pending entries. Per-slot counters of a pending slot return an error, never zero.

Errno

  • Strict tracking faults in the file and privilege programs (7 sites) return EPERM instead of ENOMEM.
  • A refused credential preparation still shows up as ENOMEM. The kernel's prepare_creds() and cred_alloc_blank() turn the hook's refusal into NULL, and their callers return ENOMEM. This is documented in the docs and the tests.

Tests

  • Unit tests, including the class-flip test.
  • Kernel tests:
    • pending marks in all three sections, Strict EPERM and Audit allow-and-count;
    • the move from a pending mark to a real slot;
    • replacing an entry on a full bindings map;
    • a subtree mark;
    • the fork, exec and credential errnos;
    • exec refusal with the shared exec engine, in both attach orders.

Validation

Check Result
Local VMs, AL2023 6.18.56 privilege 49/0, privilege busybox 5/0, file 69/0, file otherprocess 1/0, network 24/0, exec refusal 3/0, no skips
Local VMs, Debian 13 6.12.117 every test touched by this change passes. TestIoUringAttrIsJudged fails there (setxattr EACCES); it also failed on that kernel before this change and is not touched here
go build, go vet (including the kernel tags), go test -race, gofmt, go mod tidy pass
golangci-lint 2.15.0 the same 28 issues as main at 756eeab, so none are new

AI Review

The changes were written and validated with Claude Code (Claude Opus 5.5), and each round was checked by a separate reviewer agent:

  • Design: five adversarial review rounds before the design was approved with corrections.
  • Code: four review rounds. Every finding was either fixed or deferred to a named follow-up slice.
  • Final verification: an independent pass matched every claim to VM log lines and confirmed that each VM payload matched the reviewed diff.
  • Two failures traced to the kernel and the test environment: the kernel's ENOMEM at credential refusals, and the Debian 13 io_uring failure, which predates this change.

The owner approved the design decisions and accepted the ENOMEM kernel limit.

🤖 Generated with Claude Code

AI-skills: none | cmds: /goal

…ing faults

Add the enforcement-library groundwork for the NRI start gate: a binding
can point at PendingSlot, a slot that is never published. The file,
network and privilege programs already treat an unpublished slot as a
structural fault, so a pending pod mark denies a Strict task (EPERM) and
lets an Audit one run, counted in the node-wide section error counter.
No BPF map or layout changes, and nothing writes a pending binding yet.

- Binding.Strict and PendingSlot. classOf takes the class of a pending
  binding from the binding and of a real slot from the slot only, so an
  in-place Strict to Audit flip never keeps BINDING_STRICT. validate
  refuses Strict on a real slot.
- Rebind swaps the identity of a cgroup's binding in one map write.
- HealNode, Kept, rewriteClass, the adoption reconcile and slotGate handle
  pending entries. Per-slot counters of a pending slot return an error,
  never zero.
- Strict tracking faults in the file and privilege programs return EPERM
  instead of ENOMEM. A refused credential preparation still surfaces as
  ENOMEM: the kernel's prepare_creds() and cred_alloc_blank() turn the
  hook's refusal into NULL.

Tested with unit tests (including the class-flip test) and kernel tests
for pending marks in all three sections, the move to a real slot, a
replacement on a full bindings map, a subtree mark, and the fork, exec
and credential errnos. The privilege, file and network kernel suites
pass on AL2023 6.18.56 and Debian 13 6.12.117 in local VMs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx added ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin) ai-reviewed-local labels Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.137 0.038 -72.6%
Peak CPU (cores) 0.142 0.043 -69.4%
Peak CPU p95 (cores) 0.141 0.041 -70.8%
Avg Memory (MiB) 274.917 201.073 -26.9%
Peak Memory (MiB) 288.512 203.477 -29.5%
Dedup Effectiveness

No data available.

@AlonLiwsky

Copy link
Copy Markdown
Collaborator

I read the change against the sections I own (file, privilege, network, root barrier) and the restart code. The kernel side looks right to me. A pending slot has no slot_state, so every section sees a slot that was never published. That is the existing structural-fault path: Strict denies with EPERM, Audit allows. The root barrier also treats a Strict pending task as FAULT_STRICT, so it denies too. The per-slot counter lookups on 0xFFFFFFFF miss and do nothing, which is safe. The Go maps are keyed by slot, so no index can panic.

The EPERM change does not change what is denied, only the errno. The cred-record burst case still reaches user space as ENOMEM through prepare_creds(), so a burst at pod start behaves as before. I am fine with it.

Rebind looks correct on every error path I traced: a failed arm puts the old identity back, a failed undo keeps the new one through keepFailed, and a gone container removes the entry.

I found nothing blocking for this slice, because nothing writes a pending binding yet. My main points are for the NRI writer slice. The restart layer in igbackend does not know pending entries yet, and a pending binding has no status signal. Details below.

Findings

Blocking

None.

Should fix

  1. Restart status: an adopted pending entry shows as unknown policies for the whole section. pkg/sandboxpolicy/igbackend/restart.go:982-990 loops over AdoptedBindings(). Slot 0xFFFFFFFF is not in pins.adopted and not used, so it is marked Unreadable with "adopted slot 4294967295: the previous run's manifest does not list its policies". Then pkg/sandboxpolicy/status.go:573 adds "kept state of the previous run whose policies are not known" to every policy that uses the section. The PR body says the adoption reconcile handles pending entries; that is true in enforcement, not in igbackend. Suggest: skip PendingSlot there, or report it as its own entry, before the writer lands. Verified by reading; no pending entry exists today, so no effect yet.

  2. Restart settle: the keep rule decides a Strict pending entry by slot policies. restart.go:683-686: for a cgroup with no current binding or pod, the keep rule reads b.pins.adopted[slot].Policies, which is empty for PendingSlot. After the first snapshot the entry is dropped at the deadline. For a pod-level parent cgroup (the subtree mark shape in TestPendingSlotSubtreeKernel) currentStrict never matches, so a Strict gate mark goes away after a restart while its pod may still be starting. That is a fail-open window unless the writer marks it again. Suggest: the writer slice defines who owns an adopted pending entry, and a test covers restart with one. Verified by reading; the impact is assumed, because it depends on the writer design.

  3. A pending binding has no status signal. Pending faults count only in VERDICT_COUNT_SECTION_ERROR (for example enforce_file/program.bpf.c:281), which is telemetry (pkg/sandboxpolicy/integration/telemetry.go:109). It feeds no Degraded/NotReady rule, and SlotFaults/Counters return an error for the pending slot by design. So an Audit pending entry that stays is an Audit hole that no condition shows. A Strict one is a deny-all that no condition explains. For V1 (no silent fail-open), the writer slice should report a pending binding in status (for example ProtectionUnconfirmed with a pending reason) and bound how long it may stay. Verified by reading; not a bug in this slice.

  4. Kernel results are at a base 14 commits behind main. Main now has feat(sandboxpolicy): deny the dynamic loaders when an exec section denies by path #1144 (loader deny) and feat(sandboxpolicy): summary records for denies hidden by the verdict rate limit #1145 (summary records). feat(sandboxpolicy): summary records for denies hidden by the verdict rate limit #1145 changed bindings.go, verdict.h, all three section programs and privilege_native.go, the same files as this PR. git merge-tree merges both ways without conflicts (verified). The kernel table is for 756eeab7 plus this commit only. Suggest: merge main and run the file, privilege and network kernel suites again at that head, and name the head in the table.

Minor

  1. Kernel coverage. The full suites ran on AL2023 6.18.56. On 6.12 they ran on Debian 13 6.12.117, not on the AL2023 6.12 kernel of the target fleet. The errno mapping in prepare_creds() should not differ, but a run on AL2023 6.12 would close it. Assumed.

  2. TestIoUringAttrIsJudged fails on Debian 13 6.12.117 (setxattr EACCES). The body says it also failed before this change. It is a file-section test, so I will look at it on my side and open an issue if it is a real gap. Not caused by this PR (as stated in the body; I did not check it).

  3. Runtime helper exemption in the gate mark. TestPendingSlotSubtreeKernel uses the mark shape PendingSlot + Subtree + RuntimeHelpers. With RuntimeHelpers, runtime-helper execs stay unarmed, and an unarmed task is never judged (file_no_scope). That is correct for a gate. But the exemption is today an operator setting that defaults off and shows in status. The writer slice should keep that consent rule, or say why the gate mark is different. Assumed, because the writer is not written yet.

  4. Groundwork APIs with no production caller. Rebind (bindings.go:342), ClassOf in Bind, and Binding.Strict are used only by tests and by the slot gate. That is fine for a first slice; I note it only so the writer PR adds the callers and their tests.

  5. runtime.go:372 cast. uint64(slot) < uint64(len(p.Slots)) behaves the same as the old int(slot) on 64-bit, which is the only target (amd64). Harmless.

  6. Fault verdicts with slot 4294967295, generation 0. These reach the section exporter, and SlotPolicies finds no policy, so the verdict has no policy attribution. Faults are not summary records, so feat(sandboxpolicy): summary records for denies hidden by the verdict rate limit #1145 is not affected. The downstream mapping in the private exporter should accept such a fault verdict. Assumed; I did not check the mapping.

Interaction with my open work

@AlonLiwsky

Copy link
Copy Markdown
Collaborator

One more finding that I think belongs with this work. I hit it on plain main (node-agent 318a5d7a + IG main, AL2023 6.12.113), not from any of my branches.

What happens. A container whose first process forks before the binding is live (inside the first second) is never bound:

  1. Adoption only accepts threads of the first process (real_owner_adopt_identity, tgid == init_tgid, fullruntime/bpf/opaque_real_owner_product_publisher.h). The early child does not match, so the Strict and the Audit publish are refused as AdoptionIdentity.
  2. The first Strict run fails closed: "Cannot fork", exec gets EPERM, and the container exits.
  3. The restarted container in the same pod is not bound: "shared binding capacity exhausted", because the two refused routes still hold both slots of the 2-binding profile. It runs a program copied to /tmp, so exec is not enforced for it. That is a fail-open for that container.
  4. The node goes NotReady and the policy shows Ready False (SharedNodeNotReady), so it is visible, but the container runs unenforced.

A first process that does not fork until the binding is live binds normally.

Repro. Pods with sh -c 'sleep 20; sh cases.sh; sleep inf' under a Strict and an Audit exec policy; cases.sh forks right away and then tries to run a copied binary.

Two parts, I think: the early fork itself (which the pending-slot binding and the NRI gate should cover), and the slots that refused routes keep. Do you want to handle both here, or should I open a separate issue for the slot leak?

@matthyx

matthyx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Alon. These are useful.

  • Slot leak: a separate issue, enforce_exec: refused adoptions keep their binding slots, so later containers run unbound inspektor-gadget#44. A refused adoption keeps its slot reserved on purpose (startRecycle frees only withdrawn routes), so one early fork per binding leaves every later container unbound. The issue suggests recycling the slot when the route never went live.
  • Early fork: covered by the pending-slot binding and the start gate here. I've added your repro (cases.sh forking right away, under Strict and Audit) to the writer slice's test plan.
  • Findings 1–4: I'll take them in the writer slice: pending entries in restart status, an owner for an adopted pending entry with a restart test, a status signal with a time bound, and a merge of main with the kernel suites re-run and the head named in the table.

matthyx and others added 2 commits December 3, 2026 17:52
Brings the pending-slot slice up to main 39414b7 (IG pin c5f01340ba4c),
which includes the exec restart fence work. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
This slice returns EPERM instead of ENOMEM for a Strict tracking fault in
the privilege and file gadgets, so their manifests changed. Rebuilt with
IG v0.57.0, SOURCE_DATE_EPOCH=0 and the section Makefiles' build line;
a build of main 39414b7 with the same setup reproduces main's six pins.
Network is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.037 0.036 -3.2%
Peak CPU (cores) 0.042 0.039 -7.2%
Peak CPU p95 (cores) 0.040 0.039 -3.5%
Avg Memory (MiB) 212.296 198.454 -6.5%
Peak Memory (MiB) 219.426 200.574 -8.6%
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical enforcement gaps remain: same-value rebinds can leave tasks exempt from Strict enforcement, and Strict initial bindings can report successful activation despite failed root-barrier attestation.

2 open issues
What changed in this PR

Adds pending sandbox bindings as groundwork for the future NRI start gate, without introducing a pending-binding writer.

Changes:

  • Adds pending-binding classes, identity handover, and lifecycle handling.
  • Changes Strict tracking-fault returns to EPERM while documenting kernel-generated ENOMEM exceptions.
  • Adds unit and kernel coverage and updates gadget image pins.
File Description
pkg/​sandboxpolicy/​igbackend/​slotgate_test.go Tests binding-aware slot gating.
pkg/​sandboxpolicy/​igbackend/​section_images.go Updates file and privilege image pins.
pkg/​sandboxpolicy/​igbackend/​privilege_native.go Passes binding class to the gate.
pkg/​sandboxpolicy/​igbackend/​file_native.go Gates file bindings by class.
pkg/​ebpf/​gadgets/​enforce_privilege/​runtime/​runtime_kernel_test.go Updates errno assertions.
pkg/​ebpf/​gadgets/​enforce_privilege/​runtime/​pending_kernel_test.go Tests pending privilege bindings.
pkg/​ebpf/​gadgets/​enforce_privilege/​runtime/​exec_coexist_kernel_test.go Checks refusal counters and attach orders.
pkg/​ebpf/​gadgets/​enforce_privilege/​README.md Documents tracking-fault errnos.
pkg/​ebpf/​gadgets/​enforce_privilege/​program.bpf.c Returns EPERM for tracking faults.
pkg/​ebpf/​gadgets/​enforce_network/​runtime/​pending_kernel_test.go Tests pending bindings and full-map replacement.
pkg/​ebpf/​gadgets/​enforce_file/​runtime/​runtime.go Makes slot bounds checking unsigned-safe.
pkg/​ebpf/​gadgets/​enforce_file/​runtime/​runtime_kernel_test.go Asserts EPERM on exec-mark failure.
pkg/​ebpf/​gadgets/​enforce_file/​runtime/​pending_kernel_test.go Tests pending bindings, subtrees, and errnos.
pkg/​ebpf/​gadgets/​enforce_file/​README.md Documents EPERM for mark failures.
pkg/​ebpf/​gadgets/​enforce_file/​program.bpf.c Returns EPERM for tracking faults.
pkg/​ebpf/​gadgets/​common/​README.md Documents pending bindings and handover.
pkg/​ebpf/​gadgets/​common/​enforcement/​slots.go Handles pending entries during healing and adoption.
pkg/​ebpf/​gadgets/​common/​enforcement/​pending_test.go Tests pending classes, transitions, and handover.
pkg/​ebpf/​gadgets/​common/​enforcement/​creds_linux.go Clarifies credential-failure errno comments.
pkg/​ebpf/​gadgets/​common/​enforcement/​counters.go Rejects pending-slot counter reads.
pkg/​ebpf/​gadgets/​common/​enforcement/​bindings.go Adds PendingSlot, binding classes, and Rebind.
pkg/​ebpf/​gadgets/​common/​arming.h Updates the exec-refusal errno comment.
docs/​features/​sandbox-policy.md Explains tracking-fault errno behavior.

Review effort: Balanced

matthyx and others added 2 commits December 3, 2026 21:17
…ing start on a failed barrier

- Bindings.bind: a same-value bind that goes from SkipArming to an arming
  binding no longer takes the fast path, so its tasks are armed and checked
  for io_uring rings; a ring found on that hand-over marks the new binding
  unconfirmed (the SkipArming previous one is not checkable).
- enforce_file instance.Ready: a failed root-barrier attestation refuses
  activation for a Strict PendingSlot initial binding too.

Addresses Copilot review on #1160 (r4790452518, r4790452606).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
…ec does

IG's root barrier (inspektor-gadget 42f1d9b6, in the pinned c5f01340)
covers tasks in a cgroup with an active Strict exec route and refuses
unshare(CLONE_NEWNS) and CLONE_NEWNS clones there, counted in
root_barrier_counters. The unarmed-exec fixture cloned straight into the
bound cgroup and unshared there, so it never reached execve and no
gadget counted the refusal.

- cloneHelper "enter" unshares the mount namespace in the host cgroup,
  moves itself into the bound cgroup and execs; the unarmed-exec round
  uses it. Both attach orders still require the refusing gadget to count
  the refusal; a moved OpUnshareNS counter or a setup failure is a
  fixture error.
- A new round pins the barrier: the old start fails with EPERM, counted
  in OpUnshareNS, with no privilege or enforce_exec exec counter moving.
- TestTaskAllocWithSharedExec: under an exec Enforce route the barrier
  refuses the CLONE_NEWNS clone (EPERM, OpCloneNS, no TASK); a barrier
  denial must park one birth fewer than the plain round.

VM: privilege-exec-refusal 16/16 on al2023-k618, al2023-k612, debian13.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A direct Bind can report success while retaining stale SkipArming state, preventing subsequent heals even after the held io_uring ring closes.

1 open issue
2 resolved since last review

Review effort: Balanced

…ng class

An Audit policy with an enforce rule or default override is Strict for
the start gate (S4), but the backend derived a pod mark's pending class
only from the policy mode. GateStrict names the sections whose pending
class is Strict; it is excluded from JSON, the revision and the
combination keys, and policy slots keep the policy mode. Callers follow
in S2 (backend), S4 (PodPlansAt) and S3 (gate plans).

For Copilot review on #1165 (r4792384813).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.038 0.038 +0.4%
Peak CPU (cores) 0.043 0.043 +0.2%
Peak CPU p95 (cores) 0.042 0.041 -3.0%
Avg Memory (MiB) 210.134 198.124 -5.7%
Peak Memory (MiB) 212.703 200.879 -5.6%
Dedup Effectiveness

No data available.

A direct Bind that turned a same-value Strict binding from SkipArming to
armed and then found a held io_uring ring returned success but kept the
old SkipArming binding in active, so every later heal returned
ErrNotHealable even after the ring closed. Record the new binding before
returning; it stays unconfirmed until a later walk finds no ring.

Addresses Copilot review on #1160 (comment 4792446677).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…nd) into omx/nri-s2-pending-owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…nd) into omx/nri-s4-classify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical adoption-path bug can report Strict bindings as attested when bindingRingChecked is missing, even though the required io_uring check has not passed.

1 open issue

Review effort: Balanced

…nconfirmed

adopt() left ringUnconfirmed empty for an adopted Strict entry without
bindingRingChecked (for example after an interrupted Audit->Strict
rewrite), so CgroupRingUnconfirmed and SlotHealth reported it attested.
In sections that walk credentials, every adopted Strict entry without the
checked flag and every adopted Strict pending entry is now unconfirmed
until a walk passes.

When a held ring refuses a Strict binding c over a different unconfirmed
Strict real-slot entry (active or adopted), keeping that entry could
enforce a weaker policy than c; bind now installs c unchecked, active and
unconfirmed instead (its slot reports it and a heal confirms it). An
adopted entry equal to c, a Strict pending entry, and an Audit entry are
restored as before (Audit->Strict needs a passed check; the bind error
keeps status honest). Start keeps such a take-over instead of failing, so
a replacement is never blocked.

Addresses Copilot review on #1160 (comment 4799126761).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…i-s2-pending-owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matthyx
matthyx requested a balanced review from Copilot December 4, 2026 11:36
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.092 0.000 -100.0%
Peak CPU (cores) 0.098 0.000 -100.0%
Peak CPU p95 (cores) 0.097 0.000 -100.0%
Avg Memory (MiB) 273.880 0.000 -100.0%
Peak Memory (MiB) 286.984 0.000 -100.0%
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Adopted-entry rewrites leave ringUnconfirmed stale, allowing Audit→Strict to report unverified protection as confirmed and Strict→Audit to leave SlotHealth incorrectly unhealthy.

2 open issues

Review effort: Balanced

…d for a ring-only SkipArming problem

- rewriteClass changed an adopted entry's flags but not its
  ringUnconfirmed marker: Audit->Strict read as attested without a check,
  and unchecked Strict->Audit kept the slot unhealthy. An adopted entry
  made Strict in a credential-walking section is now unconfirmed, and one
  made Audit is cleared.
- A Strict SkipArming binding is now ring-checked too: a fresh bind runs
  the check-only walk (records credentials, scans rings, arms nothing),
  so it is confirmed at once or bound but unconfirmed, never refused.
- Heal and HealNode return ErrNotHealable for a non-arming binding only
  when there are slot tracking faults, an unknown fault count or new node
  faults (lost marks only a new instance can re-arm); a binding whose only
  problem is the ring check is check-only walked and stays unconfirmed,
  so the owner reports ProtectionUnconfirmed without reloading.

Addresses Copilot review on #1160 (comments 4799346149, 4799126761).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…i-s2-pending-owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matthyx
matthyx requested a balanced review from Copilot December 4, 2026 11:57
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Peak CPU p95 (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a critical binding-publication race can let concurrent BPF hooks bypass pending restrictions even when the bind later fails.

1 open issue
1 resolved since last review

Review effort: Balanced

@matthyx

matthyx commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Re the round-14 review summary (a binding-publication race letting concurrent hooks bypass pending restrictions when the bind later fails), checked at dc21ea9:

  • bind validates the requested binding first, then makes one atomic map write of the new entry, then walks (arming, credential record, ring scan). If the walk fails, it either restores the previous entry, keeps the new one unconfirmed, or deletes a fresh entry. Hooks therefore see old → new → old, old → new, or none → new → none; no intermediate value is ever weaker than both the old and the new entry. The order is the same on main.
  • While the walk runs, the new entry is visible and may be weaker than the old one (for example a pending mark moving to its real Strict slot). That entry is the policy the owner asked for, and its validity is checked before the write; the walk can only fail for runtime reasons (held ring, unrecorded credentials, arming, a gone cgroup). io_uring requests under unrecorded credentials are not judged under the old Strict entry either, so the window adds no exposure, and a failed bind is reported as not committed, so status stays honest.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.036 0.035 -2.8%
Peak CPU (cores) 0.040 0.039 -3.8%
Peak CPU p95 (cores) 0.038 0.038 -0.2%
Avg Memory (MiB) 210.338 195.693 -7.0%
Peak Memory (MiB) 212.461 198.723 -6.5%
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The binding transition can expose real-policy permissions before the held-ring check succeeds, and failed rollback handling can leave the slot permanently ring-unconfirmed.

2 open issues
1 resolved since last review

Review effort: Balanced

… publishes

When an unchecked Strict pending entry moved to a real Strict slot, bind
wrote the real-slot entry before arming and the io_uring check, so tasks
could use the real policy's permissions during a walk that then failed.
For that transition (an active or adopted Strict pending entry to a
Strict real slot) bind now arms and checks first, while the pending entry
still denies; on failure nothing is published and the pending entry stays
unconfirmed (and becomes the heal-retried move if one was deferred), on
success the checked entry is written once. Other transitions keep their
order. keepFailed also clears any deferred move for the cgroup it keeps.

Addresses Copilot review on #1160 (comments 4800029861, 4800029921).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…i-s2-pending-owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matthyx
matthyx requested a balanced review from Copilot December 4, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical SkipArming path writes and retains a real Strict policy before validation, allowing previously denied accesses when a held io_uring ring is detected.

1 open issue
2 resolved since last review

Review effort: Balanced

// entry. A refused walk writes nothing: the pending entry stays.
prevPending := (bound && previous.Slot == PendingSlot && b.classOf(previous)) ||
(wasAdopted && adopted.Slot == PendingSlot && adopted.Flags&bindingStrict != 0)
prechecked := prevPending && c.Slot != PendingSlot && strict && b.armed != nil && !c.SkipArming

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3a8d720: the check-before-write now also covers a SkipArming binding (the pod hand-over) moving from an unchecked Strict pending entry to a Strict real slot. bind runs a side-effect-free scan first (record credentials, scan rings, arm nothing, runtime helpers included) while the pending entry stays installed; on a held ring or record failure nothing is written, the pending entry stays unconfirmed and Bind returns ErrIoUringHeld, so the owner keeps the pending mark, reports it Faulted and retries; on success the checked entry is written once. Test: TestPendingToRealSlotSkipArmingChecksBeforeWriting (map captured during the scan, nothing armed).

…hecks before it publishes

The round-15 check-before-write covered only arming bindings. A SkipArming
binding (the pod hand-over) moving from an unchecked Strict pending entry
to a Strict real slot still wrote the real-slot entry before checkOnly,
and a held io_uring ring left the real policy in place. bind now runs a
side-effect-free scan (record credentials, scan rings, no arming) first
while the pending entry stays installed; on failure nothing is written,
the pending entry stays unconfirmed and Bind returns ErrIoUringHeld (the
owner keeps the pending mark, reports it Faulted and retries); on
success the checked entry is written once.

Addresses Copilot review on #1160 (comment 4800173157).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
matthyx added a commit that referenced this pull request Dec 4, 2026
…i-s2-pending-owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matthyx
matthyx requested a balanced review from Copilot December 4, 2026 13:10
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Peak CPU p95 (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin) ai-reviewed-local

Projects

Status: WIP

Development

Successfully merging this pull request may close these issues.

3 participants