census note: deleted-exe acceptance covers root tasks with a selected image
Astra (fix round 1, finding 4): the overlay and the note said the deleted-exe acceptance applies only to non-root tasks. It also applies to a root task of a unit with a selected image, the guarded edge. Both now say so, and that a root task of a unit with no selected image keeps main's path walk. TestRecoverCensusDeletedExeOfARootTask witnesses the root selected-image case (signed accepted in a private mount namespace, unsigned refused, exec race refused) and the root unselected case. The retry's timing text now describes the shared 20 s deadline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+91
−8
docs/superpowers/notes/census-proposal-claims-on-gate-recover.md+9 −5internal/host/rootgeneration_census_recover_linux_test.go+79 −0internal/provision/testdata/plan14-root-reads-claims-on-gate-recover.tsv+3 −3
diff --git a/docs/superpowers/notes/census-proposal-claims-on-gate-recover.md b/docs/superpowers/notes/census-proposal-claims-on-gate-recover.md| index 5c295fb19..e1393d646 100644 |
| --- a/docs/superpowers/notes/census-proposal-claims-on-gate-recover.md |
| +++ b/docs/superpowers/notes/census-proposal-claims-on-gate-recover.md |
| @@ -56,9 +56,9 @@ and has no row. |
| | `internal/host/systemparticipation.go` `systemApplier.checkUnarmedParticipationRecovery` | re-pinned, no read of its own: with no journal open its settlement goes through `settleWithoutJournal` | root system update and recovery, uid 0 | authority, G,F, unchanged | |
| | `internal/host/rootgeneration_kernel_linux.go` `generationKernel.absent` | re-pinned: same reads; a task refusal is typed (`generationTaskRefusal`, same text) so the retry can tell task-level refusals from structural ones | root census, uid 0 | authority, E2, unchanged | |
| | `internal/host/rootgeneration_kernel_linux.go` `generationKernel.task` | re-pinned: same reads; a start time that moves mid-inspection refuses as `errGenerationTaskReplaced` (still `os.ErrPermission`); every reference check still runs on every accepted service task | root census, uid 0 | authority, E2, unchanged | |
| -| `internal/host/rootgeneration_census_linux.go` `generationCensusRetry` | re-pinned, no read of its own: whole passes; task-level refusals a later pass can clear retry with backoff from 250 ms for at most 20 s; reference, namespace, mount and structural refusals refuse at once | root census, uid 0 | authority, E2, unchanged | |
| +| `internal/host/rootgeneration_census_linux.go` `generationCensusRetry` | re-pinned, no read of its own: whole passes; every pass and its blocking reads run under one 20 s deadline, and a pass that ends past it refuses; task-level refusals a later pass can clear retry with backoff from 250 ms inside it; reference, namespace, mount and structural refusals refuse at once | root census, uid 0 | authority, E2, unchanged | |
| | `internal/host/rootgeneration_services_linux.go` `generationServiceReader` | re-pinned, now a binding with no read: the production `generationServiceEnv` | root census, uid 0 | authority, E2, unchanged | |
| -| `internal/host/rootgeneration_services_linux.go` `generationServiceEnv.reader` | new: `generationServiceReader`'s body. The exe `Readlink` moves first, for diagnostics only. Every refusal names check, unit, cgroup and exe. A non-root task whose exe reads `<path> (deleted)` goes to `deletedProgram` | root census, uid 0 | authority, E2 (its caller's) | |
| +| `internal/host/rootgeneration_services_linux.go` `generationServiceEnv.reader` | new: `generationServiceReader`'s body. The exe `Readlink` moves first, for diagnostics only. Every refusal names check, unit, cgroup and exe. A non-root task, or a root task of a unit with a selected image (the guarded edge), whose exe reads `<path> (deleted)` goes to `deletedProgram` | root census, uid 0 | authority, E2 (its caller's) | |
| | `internal/host/rootgeneration_services_linux.go` `generationServiceShow` | new: the `systemctl show` moved out unchanged | root census, uid 0 | authority, E2 (its caller's) | |
| | `internal/host/rootgeneration_services_linux.go` `generationServiceTrust` | new: the unit-file `EvalSymlinks` and `OpenTrustedFile` moved out unchanged | root census, uid 0 | authority, E2 (its caller's) | |
| | `internal/host/rootgeneration_services_linux.go` `generationServiceEnv.deletedProgram` | new root read: opens a service task's image through `/proc/<pid>/exe`, `Fstat`s it and hashes it | root census, uid 0, in carlos-system-recover, carlos-system-update, instance-control's start and the guard-exec prelude | authority, F,J4 | |
| @@ -78,9 +78,13 @@ cache the box holds. Classifying it at E2 with its caller would understate |
| what it decides: a match is what lets an unselected inode count as the |
| unit's program. |
| -It is reached only for a non-root task of a unit whose selected program is |
| -`<opt>/carlos` and whose exe link reads `<opt>/carlos (deleted)`. Anything |
| -else refuses as before. Acceptance only lets the census go on to the |
| +It is reached for a non-root task, and for a root task of a unit with a |
| +selected image (the guarded edge, whose selected program is |
| +`<opt>/carlos`), when the unit selects `<opt>/carlos` and the exe link reads |
| +`<opt>/carlos (deleted)`. A root task of a unit with no selected image keeps |
| +main's path walk, which a deleted exe fails, so the strict root scan |
| +applies to it (`TestRecoverCensusDeletedExeOfARootTask`). Anything else |
| +refuses as before. Acceptance only lets the census go on to the |
| reference checks: exe, cwd, root, descriptors, maps and mounts are still |
| compared against the retired generations |
| (`TestRecoverCensusStillChecksReferencesOfAnAcceptedDeletedExe`). |
diff --git a/internal/host/rootgeneration_census_recover_linux_test.go b/internal/host/rootgeneration_census_recover_linux_test.go| index d8a3e75cd..e460e9579 100644 |
| --- a/internal/host/rootgeneration_census_recover_linux_test.go |
| +++ b/internal/host/rootgeneration_census_recover_linux_test.go |
| @@ -634,3 +634,82 @@ func TestRecoverCensusDeadlineReachesTheInspection(t *testing.T) { |
| t.Fatalf("image hash under an ended context = %v", err) |
| } |
| } |
| + |
| +// guardedEdge makes the fixture's unit the guarded carlos-edge.service: |
| +// ExecStart is the guard, the selected program <opt>/carlos, and the task |
| +// is the edge's main process in its supervise/ group. |
| +func (f *deletedExeFixture) guardedEdge(t *testing.T) { |
| + t.Helper() |
| + f.unit = "carlos-edge.service" |
| + f.execStart = "{ path=/opt/carlos/system/guard/carlos ; argv[]=/opt/carlos/system/guard/carlos system guard-exec edge ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=41 ; code=(null) ; status=0/0 }" |
| + binary := f.env.binary |
| + f.env.binary = func(opt, path string) (rootFloorBinary, error) { |
| + if path == "/opt/carlos/system/guard/carlos" { |
| + return rootFloorBinary{Digest: "guard"}, nil |
| + } |
| + b, err := binary(opt, path) |
| + b.File.Inode = 7 |
| + return b, err |
| + } |
| + base := "/system.slice/carlos-edge.service" |
| + generationWrite(t, f.task+"/cgroup", "0::"+base+"/supervise\n") |
| + generationWrite(t, f.proc+"/41/cgroup", "0::"+base+"/supervise\n") |
| + show := f.env.show |
| + f.env.show = func(ctx context.Context, unit string) (map[string]string, error) { |
| + props, err := show(ctx, unit) |
| + if err == nil { |
| + props["ControlGroup"] = base |
| + } |
| + return props, err |
| + } |
| +} |
| + |
| +func TestRecoverCensusDeletedExeOfARootTask(t *testing.T) { |
| + // The deleted-exe acceptance also covers a root task of a unit with a |
| + // selected image (the guarded edge), and only that among root tasks. |
| + // The task runs in a private mount namespace, which the strict root |
| + // scan refuses: only a trusted classification lets it pass. |
| + root := func(t *testing.T, f *deletedExeFixture) { |
| + generationWrite(t, f.task+"/status", "Tgid:\t41\nUid:\t0\t0\t0\t0\nKthread:\t0\n") |
| + generationRelink(t, "private-service", f.task+"/ns/mnt") |
| + } |
| + t.Run("selected-image-signed", func(t *testing.T) { |
| + f := deletedExe(t) |
| + f.guardedEdge(t) |
| + root(t, f) |
| + if err := f.census(t); err != nil { |
| + t.Fatalf("census refused a root guarded-edge task on its signed deleted image: %v", err) |
| + } |
| + }) |
| + t.Run("selected-image-unsigned", func(t *testing.T) { |
| + f := deletedExe(t) |
| + f.guardedEdge(t) |
| + root(t, f) |
| + f.writeImage(t, "an image no identity signs", 0o755, true) |
| + if err := f.census(t); err == nil { |
| + t.Fatal("census accepted a root guarded-edge task on an unsigned deleted image") |
| + } |
| + }) |
| + t.Run("no-selected-image", func(t *testing.T) { |
| + // A root task of a unit with no selected image keeps main's path |
| + // walk, which a deleted exe fails, so the strict root scan applies. |
| + f := deletedExe(t) |
| + root(t, f) |
| + if err := f.census(t); err == nil { |
| + t.Fatal("census trusted a root task of an unselected unit on its deleted exe") |
| + } |
| + }) |
| + t.Run("selected-image-exec-race", func(t *testing.T) { |
| + f := deletedExe(t) |
| + f.guardedEdge(t) |
| + root(t, f) |
| + err := f.execRace(t, nil, func(_ bool, call int) { |
| + if call == 1 { |
| + generationRelink(t, f.unrelated, f.task+"/exe") |
| + } |
| + }) |
| + if err == nil || !strings.Contains(err.Error(), "exe binding check refused") { |
| + t.Fatalf("root guarded-edge task that exec'd away = %v", err) |
| + } |
| + }) |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-claims-on-gate-recover.tsv b/internal/provision/testdata/plan14-root-reads-claims-on-gate-recover.tsv| index 79222f163..ce94a522e 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-claims-on-gate-recover.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-claims-on-gate-recover.tsv |
| @@ -8,10 +8,10 @@ internal/host/systemapply.go RunSystemApply authority D,F,J4 rev3=PROPOSED-claim |
| internal/host/systemparticipation.go systemApplier.checkUnarmedParticipationRecovery authority G,F rev3=PROPOSED-claims-on-gate-recover;identity=root system update/recovery uid 0;basis=re-pinned at its class and task, no read of its own: with no journal open the settlement goes through settleWithoutJournal, so a refused census defers (transaction and update record kept, recover exits 0); with a journal open it refuses as before. Pending acquisition triggers production controller settlement even without an update journal; normal ledger admission stays refused until verified recovery clears the marker. TestRecoverDefersACensusRefusalWithoutAnArmedFloor. 775e5894f5dc32c7f5403df536d423bdb7a185006406be4688f031324050a17b |
| internal/host/rootgeneration_kernel_linux.go generationKernel.absent authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root claim/adopt/update controller uid 0;basis=re-pinned at its class and task; its reads are unchanged. A task refusal is now typed (generationTaskRefusal, same text: the /proc path and the cause) so the census retry can tell task-level refusals from structural ones; bounded task and persistent generation inspection retains boot and process start checks. file:Readlink@312 b758554c182902d80a255122404d8418ec78a9d49ed32c78b9116493ab137b5a |
| internal/host/rootgeneration_kernel_linux.go generationKernel.task authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root claim/adopt/update controller uid 0;basis=re-pinned at its class and task; its reads are unchanged. A start time that moves during inspection now refuses with errGenerationTaskReplaced (still os.ErrPermission) so a fresh pass may clear it; every accepted service, including a deleted-exe task, still has exe, cwd, root, descriptors, maps and mounts checked against retired generations and its start rechecked. TestRecoverCensusStillChecksReferencesOfAnAcceptedDeletedExe, TestPlan14GenerationServiceReferences. file:Readlink@1248 b154974e026435c6c072bdd702dd5dba72d561a99823657c625332f63adb003b |
| -internal/host/rootgeneration_census_linux.go generationCensusRetry authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root claim/adopt/update controller uid 0;basis=re-pinned at its class and task, no read of its own: runs whole independent census passes through generationCensusRetryFor. Task-level refusals a later pass can clear (exited, replaced, refused by the service lookup) retry with backoff from 250 ms for at most 20 s, then the last refusal is returned unchanged; other missing-process errors retry at most three times as before; reference, namespace, mount and structural refusals refuse immediately; no partial census is accepted. TestRecoverCensusRetriesATransientRefusalWithinTheWindow, TestRecoverCensusRetriesOnlyTaskLevelTransients, TestPlan14GenerationCensusRetriesWholeObservation. 558610eb740f2af3365c6880122abcb4a1dbbd5be687805d1fdf265db88f3f63 |
| +internal/host/rootgeneration_census_linux.go generationCensusRetry authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root claim/adopt/update controller uid 0;basis=re-pinned at its class and task, no read of its own: runs whole independent census passes through generationCensusRetryFor. Every pass and its blocking reads run under one 20 s deadline from the census's start; a pass that ends past it refuses even if it succeeded, and none starts after it. Task-level refusals a later pass can clear (exited, replaced, refused by the service lookup) retry with backoff from 250 ms inside that deadline, then the last refusal is returned unchanged; other missing-process errors retry at most three times as before; reference, namespace, mount and structural refusals refuse immediately; no partial census is accepted. TestRecoverCensusRetriesATransientRefusalWithinTheWindow, TestRecoverCensusRetriesOnlyTaskLevelTransients, TestPlan14GenerationCensusRetriesWholeObservation. 558610eb740f2af3365c6880122abcb4a1dbbd5be687805d1fdf265db88f3f63 |
| internal/host/rootgeneration_services_linux.go generationServiceReader authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0;basis=re-pinned at its class and task, no read of its own now: binds the production generationServiceEnv (/proc, /opt/carlos, owner uid 0, systemctl show, trusted unit files, readRootFloorBinary) and returns its reader; the reads moved into generationServiceEnv.reader, generationServiceShow and generationServiceTrust unchanged. e008d36af58a61e8eddf18d54a8c70243e9f9c62185c93f66e4bd5557048d9e4 |
| -internal/host/rootgeneration_services_linux.go generationServiceEnv.reader authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0;basis=new unit, generationServiceReader's body at its class: classifies independently verified platform and system services by trusted unit files, systemd main PID, cgroup and protected executable; only edge main threads may use its delegated supervise subgroup; exact guard-exec edge verifies guard and selected current against signed protected identities. The exe Readlink moves before the cgroup checks for diagnostics only (a failure still refuses at its old place); every refusal names check, unit, cgroup and exe and wraps its cause. A non-root task whose exe reads <path> (deleted) goes to deletedProgram instead of the path walk; root tasks of unselected units keep the walk. TestRecoverCensusRefusalsNameCheckUnitCgroupAndExe, TestRecoverCensusAcceptsTheEdgesDeletedExeInSupervise. file:Readlink@1017 4faa70c023ebe85bca7862dc5de60382536154aefc27ef21a66af2739f81fb97 |
| +internal/host/rootgeneration_services_linux.go generationServiceEnv.reader authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0;basis=new unit, generationServiceReader's body at its class: classifies independently verified platform and system services by trusted unit files, systemd main PID, cgroup and protected executable; only edge main threads may use its delegated supervise subgroup; exact guard-exec edge verifies guard and selected current against signed protected identities. The exe Readlink moves before the cgroup checks for diagnostics only (a failure still refuses at its old place); every refusal names check, unit, cgroup and exe and wraps its cause. A non-root task, or a root task of a unit with a selected image (the guarded edge), whose exe reads <path> (deleted) goes to deletedProgram instead of the path walk; root tasks of units with no selected image keep the walk. TestRecoverCensusRefusalsNameCheckUnitCgroupAndExe, TestRecoverCensusAcceptsTheEdgesDeletedExeInSupervise. file:Readlink@1017 4faa70c023ebe85bca7862dc5de60382536154aefc27ef21a66af2739f81fb97 |
| internal/host/rootgeneration_services_linux.go generationServiceShow authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0;basis=new unit, the systemctl show of ControlGroup, MainPID, ExecStart, FragmentPath and DropInPaths moved out of generationServiceReader unchanged, at its class. file:CommandContext@103 26d82849d8e6d22eb35b0d9befd0b5c02d81cec9dc3bfaf4b684504c16c4d0cd |
| internal/host/rootgeneration_services_linux.go generationServiceTrust authority E2 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0;basis=new unit, the unit-file EvalSymlinks and rootstate.OpenTrustedFile check moved out of generationServiceReader unchanged, at its class. file:EvalSymlinks@63 07fe0cf4c6a8b17eaa223ec37b44818152ac1e70c8fe3832bedcb99c61cf24a1 |
| -internal/host/rootgeneration_services_linux.go generationServiceEnv.deletedProgram authority F,J4 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0 (carlos-system-recover, carlos-system-update, instance-control start, guard-exec prelude);basis=NEW root read, classified as guard-exec's equivalent (hostfloor OpenProtected, Disk.VerifyFile and ExecutingHash, F,J4 root-input) because it is the same proof on the same kind of input: it opens a service task's running image through /proc/<pid>/exe, requires a regular file owned by root with no links left and no group or other write, hashes its bytes (at most 512 MiB) and accepts only a digest equal to the signed router build of <opt>/carlos or <opt>/carlos.prev as readRootFloorBinary proves it from the local identity cache. Only for a non-root task of a unit whose selected program is <opt>/carlos and whose exe link reads <opt>/carlos (deleted); anything else refuses as before. Acceptance only lets the census reach the reference checks. TestRecoverCensusAcceptsADeletedExeOfTheCurrentOrPreviousBuild, TestRecoverCensusRefusesOtherDeletedExes, TestRecoverCensusRefusesADeletedExeNotOwnedByRoot. file:Fstat@389,file:Open@285 bfc0a7c3935b2f414ef9354390744b9a82d9f08d7ff93943fd685a6c98906cbf |
| +internal/host/rootgeneration_services_linux.go generationServiceEnv.deletedProgram authority F,J4 rev3=PROPOSED-claims-on-gate-recover;identity=root generation kernel reader uid 0 (carlos-system-recover, carlos-system-update, instance-control start, guard-exec prelude);basis=NEW root read, classified as guard-exec's equivalent (hostfloor OpenProtected, Disk.VerifyFile and ExecutingHash, F,J4 root-input) because it is the same proof on the same kind of input: it opens a service task's running image through /proc/<pid>/exe, requires a regular file owned by root with no links left and no group or other write, hashes its bytes (at most 512 MiB) and accepts only a digest equal to the signed router build of <opt>/carlos or <opt>/carlos.prev as readRootFloorBinary proves it from the local identity cache. It applies to a non-root task, and to a root task of a unit with a selected image (the guarded edge, whose selected program is <opt>/carlos), when the unit selects <opt>/carlos and the exe link reads <opt>/carlos (deleted); a root task of a unit with no selected image keeps main's path walk, and anything else refuses as before. The hashed descriptor stays open and binds the task to that image for its whole inspection (generationServiceEnv.recheck). Acceptance only lets the census reach the reference checks. TestRecoverCensusAcceptsADeletedExeOfTheCurrentOrPreviousBuild, TestRecoverCensusRefusesOtherDeletedExes, TestRecoverCensusRefusesADeletedExeNotOwnedByRoot. file:Fstat@389,file:Open@285 bfc0a7c3935b2f414ef9354390744b9a82d9f08d7ff93943fd685a6c98906cbf |
| @coverage internal/host 9acd729653931aa89061368f8d05f3f0c4ceac7b4c4c46192a40002debbc63b4 |