fix(process): preserve partial evidence and verify detached cleanup (#1011)

* test(ci): allow transport delivery in source identity regression

* fix(process): preserve partial evidence and verify detached cleanup

* fix(process): scope Linux token sweeps by stable process identity

* fix(process): retain environment permission failure codes

* fix(process): wait for signaled processes before verifying cleanup

* fix(process): verify sampled detached groups during cleanup

* fix(electron): preserve prelaunch identities through cleanup

* fix(process): retry growing Darwin process table snapshots

* fix(process): retain compatibility with saved v3 capture evidence

* fix(process): migrate saved v3 captures during reconstruction verification

* fix(process): preserve cancellation during Darwin helper compilation

* fix(process): propagate cancellation through ownership baselines

* perf(javascript): cache canonical export comparison sort keys

* fix(process): cancel provider ownership preparation before spawn

* fix(process): isolate native compiler waiter cancellation
This commit is contained in:
morluto
2026-10-08 04:46:46 +08:00
committed by GitHub
parent 63ba7424c0
commit 63cf28fd8f
51 changed files with 5506 additions and 316 deletions
+27
View File
@@ -1,4 +1,5 @@
import { spawn } from "node:child_process";
import { writeFile } from "node:fs/promises";
const mode = process.argv[2];
@@ -63,6 +64,32 @@ if (mode === "interactive") {
process.exit(23);
} else if (mode === "hang") {
setInterval(() => undefined, 1_000);
} else if (mode === "ready-hang") {
await writeFile(process.argv[3], "ready");
process.stdout.write("ready\n");
setInterval(() => undefined, 1_000);
} else if (mode === "detached-cleanup") {
const owned = spawn(process.execPath, [process.argv[1], "detached-child"], {
detached: true,
stdio: "ignore",
});
const unowned = spawn(process.execPath, [process.argv[1], "detached-child"], {
detached: true,
env: { ...process.env, REA_PROCESS_RUN_ID: "unowned-neighbor" },
stdio: "ignore",
});
if (owned.pid === undefined || unowned.pid === undefined)
throw new Error("detached fixture children did not receive PIDs");
owned.unref();
unowned.unref();
await writeFile(
process.argv[3],
JSON.stringify({ ownedPid: owned.pid, unownedPid: unowned.pid }),
);
await new Promise((resolve) => setTimeout(resolve, 100));
process.stdout.write("detached-ready\n");
} else if (mode === "detached-child") {
setInterval(() => undefined, 1_000);
} else {
process.stderr.write("unknown fixture mode\n");
process.exit(2);
+176
View File
@@ -0,0 +1,176 @@
import Foundation
func fixture(
arguments: [String],
environment: [String],
pointerSize: Int = 8,
executablePath: String = "/fixture/executable",
appleRecords: [String] = ["pfz=synthetic"],
zeroedPfz: Bool = false
) -> [UInt8] {
var bytes = withUnsafeBytes(of: Int32(arguments.count).littleEndian, Array.init)
let pathBytes = Array(executablePath.utf8)
bytes.append(contentsOf: pathBytes + [0])
let prefixLength = Array("executable_path=".utf8).count
let padding = (pointerSize - ((prefixLength + pathBytes.count + 1) % pointerSize)) % pointerSize
bytes.append(contentsOf: repeatElement(UInt8(0), count: padding))
for argument in arguments { bytes.append(contentsOf: Array(argument.utf8) + [0]) }
for entry in environment { bytes.append(contentsOf: Array(entry.utf8) + [0]) }
if zeroedPfz {
bytes.append(contentsOf: repeatElement(UInt8(0), count: Array("pfz=synthetic".utf8).count + 1))
}
for record in appleRecords { bytes.append(contentsOf: Array(record.utf8) + [0]) }
return bytes
}
@main
struct ProcessRunTokenParserProbe {
static func main() throws {
let argvDecoy = try token(in: fixture(
arguments: ["/fixture/executable", "REA_PROCESS_RUN_ID=argv-decoy", "trailing"],
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy"]
))
let realToken = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy", "REA_PROCESS_RUN_ID=owned-token"]
))
let emptyLaterArgument = try token(in: fixture(
arguments: ["/fixture/executable", "", "after-empty"],
environment: ["REA_PROCESS_RUN_ID=empty-argument-token"],
pointerSize: 8
))
let alternatePadding = try token(in: fixture(
arguments: ["/fixture/executable", "argument"],
environment: ["REA_PROCESS_RUN_ID=alternate-padding-token"],
pointerSize: 4
), pointerSize: 4)
let emptyArgv0Read = try token(in: fixture(
arguments: ["", "", "after-empty"],
environment: ["REA_PROCESS_RUN_ID=empty-argv0-token"],
pointerSize: 8
))
let finalAssignmentArgumentRead = try token(in: fixture(
arguments: ["/fixture/executable", "FOO=bar"],
environment: ["REA_PROCESS_RUN_ID=final-assignment-token"]
))
let reservedArgumentIgnored = try token(in: fixture(
arguments: ["/fixture/executable", "REA_PROCESS_RUN_ID=argv-decoy"],
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy"]
))
let nonAsciiPathRead = try token(in: fixture(
arguments: ["/fixture/é", "FOO=bar"],
environment: ["REA_PROCESS_RUN_ID=utf8-path-token"],
pointerSize: 8,
executablePath: "/fixture/é"
))
let appleVectorTokenFailsClosed: Bool
do {
_ = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["pfz=user-value", "PATH=/usr/bin"],
appleRecords: ["pfz=synthetic", "REA_PROCESS_RUN_ID=apple-decoy"]
))
appleVectorTokenFailsClosed = false
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
appleVectorTokenFailsClosed = true
}
let clearedAppleVectorTokenFailsClosed: Bool
do {
_ = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["REA_PROCESS_RUN_ID=cleared-pfz-owned-token"],
appleRecords: ["REA_PROCESS_RUN_ID=apple-decoy"],
zeroedPfz: true
))
clearedAppleVectorTokenFailsClosed = false
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
clearedAppleVectorTokenFailsClosed = true
}
let callerPfzBeforeTokenRead = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["pfz=caller-value", "REA_PROCESS_RUN_ID=cleared-pfz-owned-token"],
zeroedPfz: true
))
let emptyEnvironmentRecordsBeforeTokenFailClosed: Bool
do {
_ = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["DECOY=value", "", "", "REA_PROCESS_RUN_ID=synthetic-decoy"],
appleRecords: [],
zeroedPfz: true
))
emptyEnvironmentRecordsBeforeTokenFailClosed = false
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
emptyEnvironmentRecordsBeforeTokenFailClosed = true
}
let zeroArgumentsRead = try token(in: fixture(
arguments: [],
environment: ["REA_PROCESS_RUN_ID=zero-argc-token"],
pointerSize: 4
), pointerSize: 4)
var truncatedArgv = withUnsafeBytes(of: Int32(2).littleEndian, Array.init)
let truncatedPath = Array("/fixture/executable".utf8)
truncatedArgv.append(contentsOf: truncatedPath + [0])
let truncatedPadding = (8 - ((Array("executable_path=".utf8).count + truncatedPath.count + 1) % 8)) % 8
truncatedArgv.append(contentsOf: repeatElement(UInt8(0), count: truncatedPadding))
truncatedArgv.append(contentsOf: Array("/fixture/executable".utf8) + [0])
truncatedArgv.append(contentsOf: Array("REA_PROCESS_RUN_ID=synthetic-decoy".utf8))
let truncatedArgvFailsClosed: Bool
do {
_ = try token(in: truncatedArgv)
truncatedArgvFailsClosed = false
} catch {
truncatedArgvFailsClosed = true
}
let duplicateTokenFailsClosed: Bool
do {
_ = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["REA_PROCESS_RUN_ID=first", "REA_PROCESS_RUN_ID=second"]
))
duplicateTokenFailsClosed = false
} catch RunTokenReadError.duplicateToken {
duplicateTokenFailsClosed = true
}
let emptyEnvironmentFailsClosed: Bool
do {
_ = try token(in: fixture(arguments: ["/fixture/executable"], environment: []))
emptyEnvironmentFailsClosed = false
} catch RunTokenReadError.environmentUnavailable {
emptyEnvironmentFailsClosed = true
}
let missingAppleBoundaryFailsClosed: Bool
do {
_ = try token(in: fixture(
arguments: ["/fixture/executable"],
environment: ["REA_PROCESS_RUN_ID=synthetic-decoy"],
appleRecords: []
))
missingAppleBoundaryFailsClosed = false
} catch RunTokenReadError.appleVectorUnavailable {
missingAppleBoundaryFailsClosed = true
}
let result: [String: Any] = [
"argvDecoyIgnored": argvDecoy == nil,
"realTokenRead": realToken == "owned-token",
"emptyLaterArgumentRead": emptyLaterArgument == "empty-argument-token",
"alternatePaddingRead": alternatePadding == "alternate-padding-token",
"truncatedArgvFailsClosed": truncatedArgvFailsClosed,
"duplicateTokenFailsClosed": duplicateTokenFailsClosed,
"emptyEnvironmentFailsClosed": emptyEnvironmentFailsClosed,
"missingAppleBoundaryFailsClosed": missingAppleBoundaryFailsClosed,
"emptyArgv0Read": emptyArgv0Read == "empty-argv0-token",
"finalAssignmentArgumentRead": finalAssignmentArgumentRead == "final-assignment-token",
"reservedArgumentIgnored": reservedArgumentIgnored == nil,
"nonAsciiPathRead": nonAsciiPathRead == "utf8-path-token",
"appleVectorTokenFailsClosed": appleVectorTokenFailsClosed,
"clearedAppleVectorTokenFailsClosed": clearedAppleVectorTokenFailsClosed,
"callerPfzBeforeTokenRead": callerPfzBeforeTokenRead == "cleared-pfz-owned-token",
"emptyEnvironmentRecordsBeforeTokenFailClosed": emptyEnvironmentRecordsBeforeTokenFailClosed,
"zeroArgumentsRead": zeroArgumentsRead == "zero-argc-token",
]
let output = try JSONSerialization.data(withJSONObject: result, options: [.sortedKeys])
FileHandle.standardOutput.write(output)
}
}
+40
View File
@@ -0,0 +1,40 @@
import Darwin
import Foundation
@main
struct ProcessRunTokenSnapshotProbe {
static func main() throws {
var sizeQueries = 0
var readAttempts = 0
let retried = readProcessSnapshot { _, output, size in
guard output != nil else {
sizeQueries += 1
size = MemoryLayout<kinfo_proc>.stride
return 0
}
readAttempts += 1
if readAttempts == 1 {
errno = ENOMEM
return -1
}
size = 0
return 0
}
let otherError = readProcessSnapshot { _, output, size in
if output == nil {
size = MemoryLayout<kinfo_proc>.stride
return 0
}
errno = EACCES
return -1
}
let output: [String: Any] = [
"retriedAfterFreshSize": retried.failure == nil && sizeQueries == 2 && readAttempts == 2,
"preservedOtherErrno": otherError.failure == "process_table_failed_\(EACCES)"
]
let data = try JSONSerialization.data(withJSONObject: output, options: [.sortedKeys])
FileHandle.standardOutput.write(data)
}
}