Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5df5571
feat(ghidra): admit verified recordless MIPS I o32 executables
Bobtoshi Oct 13, 2026
d8630ea
test(ghidra): verify MIPS branch decoding and retain diagnostics
Bobtoshi Oct 13, 2026
5ec1a57
fix(mips)!: reject uninspected GNU ABI attributes
Bobtoshi Oct 13, 2026
102f813
test(mips): isolate native boundary controls from ambient settings
Bobtoshi Oct 13, 2026
05e2366
test(mips): verify cleanup and pin readelf locale
Bobtoshi Oct 13, 2026
0a8f70f
Merge latest upstream and verify MIPS declaration coverage
Bobtoshi Oct 14, 2026
e389016
chore: preserve untouched upstream tests after merge
Bobtoshi Oct 14, 2026
2d2f2f8
test(ghidra): refresh MIPS controls and verify orphan cleanup
Bobtoshi Nov 6, 2026
11edd85
fix(verification): sweep the captured Ghidra provider run identities
Bobtoshi Nov 6, 2026
3569da2
chore: merge upstream into MIPS verifier branch
Bobtoshi Nov 8, 2026
7ab92a4
test(ghidra): verify imported MIPS languages and merge upstream
Bobtoshi Nov 10, 2026
6886262
test(ghidra): remove an empty processor context suite
Bobtoshi Nov 10, 2026
a830a4a
fix(ghidra): track verifier runs before lazy analysis
Bobtoshi Nov 11, 2026
624b879
fix(ghidra): verify MIPS evidence and preserve cleanup failures
Bobtoshi Nov 11, 2026
779a635
test(ghidra): verify committed MIPS dossier attribution
Bobtoshi Nov 13, 2026
19a9f98
fix(ghidra): bound MIPS readelf verification
Bobtoshi Nov 13, 2026
0a5b082
test(ghidra): bind MIPS dossiers to their ELF fixtures
Bobtoshi Nov 13, 2026
2d1ee37
test(ghidra): retain MIPS readelf verification evidence
Bobtoshi Nov 13, 2026
7494b2b
test(ghidra): retain MIPS source paths and refusal diagnostics
Bobtoshi Nov 13, 2026
99b9126
fix(ghidra): own MIPS verifier CLI refusal commands
Bobtoshi Nov 13, 2026
7d92575
fix(ghidra): recover verified MIPS verifier provider survivors
Bobtoshi Nov 13, 2026
dbd04ab
test(ghidra): verify recordless MIPS caveats and cold cleanup
Bobtoshi Nov 13, 2026
ffcd4d6
fix(ghidra): own the MIPS verifier MCP transport
Bobtoshi Nov 13, 2026
3596755
fix(ghidra): keep MIPS MCP ownership separate from CLI commands
Bobtoshi Nov 13, 2026
1051072
Qualify MIPS32 boundaries and retain failed verifier ownership
Bobtoshi Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(verification): sweep the captured Ghidra provider run identities
  • Loading branch information
Bobtoshi committed Nov 6, 2026
commit 11edd85fb0a4b81c03e46c89af575455d2518f83
4 changes: 3 additions & 1 deletion docs/ghidra-mips.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Ghidra dossiers and exact loaded bytes. These observations do not establish
MIPS I instruction-subset or load-delay correctness. Supply existing Ghidra/Java
and GNU readelf (`REA_READELF`). Source hashes are checked after inspection,
and no target is executed. Cleanup checks both process lineage and an independent
run-token sweep, so reparenting cannot hide an owned survivor.
run-token sweep using each provider run ID retained from `binary_session` before
closing the target. Ghidra overrides the outer verifier token with that session
ID; checking the outer token alone cannot detect a reparented engine.

ELF `EM_MIPS` is retained as the provider-neutral `mips` family. The target also
retains class, byte order, `e_type`, raw `e_flags`, and inspected ABI declarations.
Expand Down
18 changes: 17 additions & 1 deletion scripts/lib/verifier-token-cleanup.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ export function prepareVerifierTokenCleanup(
run: VerifierRunStart,
suppliedHost?: ProcessOwnershipHost,
): Promise<{
verify(): Promise<ProcessCleanupResult>;
/** Retain a validated provider-owned receipt before closing its session. */
retainProviderRun(
runId: string,
providerScope?: {
readonly leaderPid: number;
readonly processGroupId: number;
readonly sampledProcessGroupIds?: readonly number[];
},
): Promise<void>;
verify(): Promise<{
readonly cleaned: boolean;
readonly reason?: string;
readonly runs: readonly {
readonly run_id: string;
readonly result: ProcessCleanupResult;
}[];
}>;
close(): Promise<void>;
}>;
97 changes: 90 additions & 7 deletions scripts/lib/verifier-token-cleanup.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { verifyNoTokenOwnedProcesses } from "../../dist/process/ProcessOwnership.js";
import { ProcessOwnershipEvidenceOwner } from "../../dist/process/ProcessOwnershipEvidence.js";
import { createSystemProcessOwnershipHost } from "../../dist/process/ProcessOwnershipObservation.js";
import {
createSystemProcessOwnershipHost,
readProcessOwnershipFacts,
} from "../../dist/process/ProcessOwnershipObservation.js";
import { readRunTokenCarriers } from "../../dist/process/ProcessRunTokenObservations.js";

/** Capture the prelaunch identities used by the canonical, PPID-independent sweep. */
export async function prepareVerifierTokenCleanup(run, suppliedHost) {
Expand All @@ -15,14 +19,93 @@ export async function prepareVerifierTokenCleanup(run, suppliedHost) {
);
if (launcher === undefined)
throw new Error("Verifier launcher is absent from the process snapshot");
const relation = {
leaderPid: run.verifier_pid,
processGroupId: launcher.processGroupId,
evidenceOwner: new ProcessOwnershipEvidenceOwner(),
const relations = new Map();
const retain = (runId, providerScope) => {
if (typeof runId !== "string" || runId.length === 0)
throw new Error("Provider run ownership receipt is unavailable");
if (!relations.has(runId))
relations.set(runId, {
leaderPid: providerScope?.leaderPid ?? run.verifier_pid,
processGroupId:
providerScope?.processGroupId ?? launcher.processGroupId,
...(providerScope?.sampledProcessGroupIds === undefined
? {}
: { sampledProcessGroupIds: providerScope.sampledProcessGroupIds }),
evidenceOwner: new ProcessOwnershipEvidenceOwner(),
});
};
retain(run.run_id);
return {
verify: () =>
verifyNoTokenOwnedProcesses(run.run_id, host, baseline, relation),
retainProviderRun: async (runId, providerScope) => {
if (typeof runId !== "string" || runId.length === 0)
throw new Error("Provider run ownership receipt is unavailable");
if (runId === run.run_id)
throw new Error(
"Provider receipt must identify its own run, not the verifier run",
);
if (providerScope === undefined) {
// Discovery proves presence only. Identity/token/identity reads then
// establish scope anchors; the final canonical sweep proves cleanup.
const carriers = await readRunTokenCarriers(host, runId);
const facts = (
await readProcessOwnershipFacts(carriers, host)
).filter(
(fact) =>
fact.state === "same-generation" &&
fact.token.state === "readable" &&
fact.token.runId === runId &&
fact.identityAfter.state === "readable" &&
fact.identityAfter.relation?.state === "observed",
);
if (facts.length === 0)
throw new Error(
`No token-verified process ownership for provider run ${runId}`,
);
providerScope = {
leaderPid: facts[0].process.pid,
processGroupId: facts[0].identityAfter.relation.processGroupId,
sampledProcessGroupIds: [
...new Set(
facts.map(
({ identityAfter }) => identityAfter.relation.processGroupId,
),
),
],
};
}
retain(runId, providerScope);
const relation = relations.get(runId);
const active = await verifyNoTokenOwnedProcesses(
runId,
host,
baseline,
relation,
);
if (relation.evidenceOwner.coverage.retainedOwned === 0)
throw new Error(
`No token-verified process ownership for provider run ${runId}: ${JSON.stringify(active)}`,
);
},
verify: async () => {
const runs = [];
for (const [runId, relation] of relations) {
runs.push({
run_id: runId,
result: await verifyNoTokenOwnedProcesses(
runId,
host,
baseline,
relation,
),
});
}
const failed = runs.find(({ result }) => !result.cleaned);
return {
cleaned: failed === undefined,
...(failed === undefined ? {} : { reason: failed.result.reason }),
runs,
};
},
close: async () => {
await host.close?.();
},
Expand Down
37 changes: 37 additions & 0 deletions scripts/verify-real-ghidra-mips-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,54 @@ try {
assert.equal(reply.ok, false);
assert.match(JSON.stringify(reply), pattern);
}
const providerRuns = [];
for (const [path, expected] of [
[legacyPath, legacy],
[recordlessMips1Path, recordlessMips1],
]) {
await call("open_binary", { path, provider_id: "ghidra" });
// Composite open/health does not launch Ghidra; analyze_function does.
const dossier = functionDossierSchema.parse(
await call("analyze_function", {
procedure: original.entry,
detail: "complete",
}),
);
assert.ok(dossier.pseudocode.length > 0);
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
const status = await call("binary_session");
assert.equal(status.analysis_provider_binding?.provider.id, "ghidra");
assert.equal(typeof status.analysis_run?.run_id, "string");
// The session owner generated this ID, and the launcher installs it on
// Ghidra in place of the surrounding verifier's process-run token.
assert.equal(status.open, true);
const providerLineage =
status.analysis_run.process_lineage.snapshots?.find(
({ provider }) => provider.id === "ghidra",
)?.observation;
const providerScope =
providerLineage?.status === "verified"
? {
leaderPid: providerLineage.launcher_pid,
processGroupId: providerLineage.process_group_id,
sampledProcessGroupIds: providerLineage.descendants.map(
({ process_group_id }) => process_group_id,
),
}
: undefined;
// Capture native token-verified identities while the provider is live;
// A public lineage snapshot is optional; native ownership is mandatory.
await cleanup.retainProviderRun(
status.analysis_run.run_id,
providerScope,
);
providerRuns.push({
control:
path === legacyPath ? "recordless_mips32" : "recordless_mips1",
run_id: status.analysis_run.run_id,
...(providerScope === undefined
? { public_lineage: "not_observed" }
: providerScope),
});
const loaded = await call("read_bytes", {
address: original.entry,
length: 24,
Expand All @@ -170,6 +206,7 @@ try {
assert.deepEqual(await readFile(recordlessMips1Path), recordlessMips1);
reports.push({
byte_order: byteOrder,
provider_runs: providerRuns,
declared_o32_mips1: "refused by CLI and MCP",
recordless_mips1:
"real Ghidra dossier and exact loaded bytes; instruction subset/load-delay semantics unverified",
Expand Down
125 changes: 121 additions & 4 deletions tests/boundary/process/verifierTokenCleanup.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { randomUUID } from "node:crypto";
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
import {
createSystemProcessOwnershipHost,
observeProcessStartIdentity,
observeProcessStartIdentityExit,
signalProcessWithStartIdentity,
} from "../../../src/process/ProcessOwnershipObservation.js";
import { expect, it, vi } from "vitest";
import { prepareVerifierTokenCleanup } from "../../../scripts/lib/verifier-token-cleanup.mjs";
import type {
ProcessOwnershipHost,
ProcessIdentityObservation,
ProcessTableEntry,
} from "../../../src/process/ProcessOwnership.js";

Expand All @@ -20,6 +29,13 @@ it("rejects a token-owned survivor after it is reparented outside the verifier t
state: "S",
command: "Ghidra control",
};
const foreign: ProcessTableEntry = {
pid: 300,
parentPid: 1,
processGroupId: 300,
state: "S",
command: "unrelated",
};
let rows = [launcher];
const close = vi.fn();
const host: ProcessOwnershipHost = {
Expand All @@ -29,14 +45,19 @@ it("rejects a token-owned survivor after it is reparented outside the verifier t
captureBaseline: async () => [{ pid: launcher.pid, identity: "start:100" }],
listProcesses: async () => rows,
environment: async (pid) =>
pid === orphan.pid ? { REA_PROCESS_RUN_ID: "owned-run" } : {},
pid === orphan.pid ? { REA_PROCESS_RUN_ID: "provider-run" } : {},
runTokens: async (selected) =>
new Map(
selected.map(({ pid }) => [
pid,
{
state: "readable",
runId: pid === orphan.pid ? "owned-run" : undefined,
runId:
pid === orphan.pid
? "provider-run"
: pid === foreign.pid
? "foreign-run"
: undefined,
} as const,
]),
),
Expand Down Expand Up @@ -67,16 +88,28 @@ it("rejects a token-owned survivor after it is reparented outside the verifier t
{ run_id: "owned-run", verifier_pid: 100, parent_pid: 50 },
host,
);
rows = [launcher, orphan];
await expect(cleanup.retainProviderRun("owned-run")).rejects.toThrow(
"its own run",
);
await expect(cleanup.retainProviderRun("")).rejects.toThrow(
"receipt is unavailable",
);
rows = [launcher, orphan, foreign];
expect(rows.filter(({ parentPid }) => parentPid === launcher.pid)).toEqual(
[],
);
// The old outer-token-only sweep misses the real provider token.
expect(await cleanup.verify()).toMatchObject({ cleaned: true });
await cleanup.retainProviderRun("provider-run");
expect(await cleanup.verify()).toMatchObject({
cleaned: false,
reason: "token-owned process remained after cleanup",
});
rows = [launcher];
rows = [launcher, foreign];
expect(await cleanup.verify()).toMatchObject({ cleaned: true });
await expect(
cleanup.retainProviderRun("unobserved-provider-run"),
).rejects.toThrow("No token-verified process ownership");
await cleanup.close();
expect(close).toHaveBeenCalledOnce();
expect(host.signalGroup).not.toHaveBeenCalled();
Expand All @@ -98,3 +131,87 @@ it("closes the inspection host when baseline ownership cannot be established", a
).rejects.toThrow("baseline is unavailable");
expect(close).toHaveBeenCalledOnce();
});

it.runIf(process.platform !== "win32")(
"retains the token installed by the production provider launcher after its parent exits",
async () => {
const run = {
run_id: randomUUID(),
verifier_pid: process.pid,
parent_pid: process.ppid,
};
const providerRun = randomUUID();
const host = createSystemProcessOwnershipHost();
const cleanup = await prepareVerifierTokenCleanup(run, host);
let orphanPid: number | undefined;
let orphanIdentity: ProcessIdentityObservation | undefined;
try {
const code = `const {spawn}=require('node:child_process');const child=spawn(process.execPath,['-e','setTimeout(()=>{},15000)'],{detached:true,stdio:'ignore',env:process.env});process.stdout.write(JSON.stringify({run_id:process.env.REA_PROCESS_RUN_ID,pid:child.pid}));child.unref();`;
const launched = await spawnOwnedProviderProcess({
command: process.execPath,
arguments: ["-e", code],
runId: providerRun,
env: { REA_PROCESS_RUN_ID: run.run_id },
expectedCommand: null,
});
let output = "";
launched.process.stdout?.on("data", (chunk) => {
output += String(chunk);
});
launched.process.stderr?.resume();
await new Promise<void>((resolve) => {
if (launched.process.exitCode !== null) resolve();
else launched.process.once("close", resolve);
});
const receipt = JSON.parse(output) as { run_id: string; pid: number };
orphanPid = receipt.pid;
orphanIdentity = await observeProcessStartIdentity(orphanPid, host);
expect(receipt.run_id).toBe(providerRun);
expect(receipt.run_id).not.toBe(run.run_id);
expect(orphanIdentity?.state).toBe("readable");
// This is the original false green: the wrapper token is absent, but
// the reparented provider process still owns its distinct native token.
expect(await cleanup.verify()).toMatchObject({ cleaned: true });
await cleanup.retainProviderRun(receipt.run_id, {
leaderPid: launched.ownership.leaderPid,
processGroupId: launched.ownership.processGroupId,
});
const result = await cleanup.verify();
expect(result).toMatchObject({ cleaned: false });
expect(
result.runs.find(({ run_id }) => run_id === providerRun)?.result,
).toMatchObject({
cleaned: false,
reason: "token-owned process remained after cleanup",
});
const row = (await host.listProcesses()).find(
({ pid }) => pid === orphanPid,
);
expect(row?.parentPid).not.toBe(process.pid);
expect(row?.parentPid).not.toBe(launched.process.pid);
} finally {
try {
if (orphanPid !== undefined && orphanIdentity?.state === "readable") {
const pid = orphanPid;
const identity = orphanIdentity.identity;
expect(
await signalProcessWithStartIdentity(pid, identity, "SIGTERM", {
host,
}),
).toBe("signaled");
await vi.waitFor(
async () => {
expect(
await observeProcessStartIdentityExit(pid, identity, host),
).toBe("exited");
},
{ timeout: 3000, interval: 20 },
);
}
} finally {
await cleanup.close();
}
}
},
20000,
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
);
Loading