fix(process): return private runtime ownership at allocation

Use POSIX mkdtemp owner-only allocation directly instead of adding a fallible permission rewrite and rollback before returning the cleanup owner. Respect restrictive umasks, assert privacy and real scratch access, and align provider documentation.
This commit is contained in:
morluto
2026-10-12 16:30:53 +08:00
parent 07b36c1489
commit c22111eca2
4 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ rea function 'D:\samples\program.exe' main --json
Headless REA and the configured supervisor must share the host filesystem and native path syntax. Run REA on Windows when the supervisor runs on Windows. The attached profile can span WSL and a Windows GUI because it binds recorded input hashes instead of asking the GUI to open a WSL path.
REA copies the admitted binary into a private temporary directory, checks its digest, and requests an owned worker with `force_headless`. POSIX workspaces use mode `0700`; Windows uses the matching package's native private-DACL boundary on a local NTFS temporary directory. It injects the returned database ID into analysis requests. It verifies the active owned worker and input path rather than adopting a user database. On close or failed startup, it releases its session with `save: false`, verifies that it is absent from upstream session discovery, and removes its private input and sidecars. An unverified release retains the workspace and reports incomplete cleanup.
REA copies the admitted binary into a private temporary directory, checks its digest, and requests an owned worker with `force_headless`. POSIX workspaces are created atomically with owner-only permissions, respecting the process umask; Windows uses the matching package's native private-DACL boundary on a local NTFS temporary directory. It injects the returned database ID into analysis requests. It verifies the active owned worker and input path rather than adopting a user database. On close or failed startup, it releases its session with `save: false`, verifies that it is absent from upstream session discovery, and removes its private input and sidecars. An unverified release retains the workspace and reports incomplete cleanup.
One REA session owns one database. Stdio registrations default `IDA_MCP_MAX_WORKERS` to `1`; the explicit upstream `--max-workers 1` also bounds a supervisor. Database size and engine memory depend on the target and upstream; REA does not impose an engine memory limit. The original binary is never executed or overwritten. Optional `workspaceRoot` selects an existing absolute temporary-directory parent on the REA host. Ensure it has space for the input copy and IDA working files.
+1 -1
View File
@@ -785,7 +785,7 @@ Ghidra's default analysis settings, and loads its packaged Java
bridge via `-scriptPath`; it never opens an existing user project. Linux and
macOS use a current-user-only local bridge socket and descriptor. The
project remains under the selected temporary directory. If its Unix socket
pathname would exceed the host's byte limit, REA allocates a separate mode-0700
pathname would exceed the host's byte limit, REA allocates a separate owner-only
socket directory under `/tmp` and removes it on close, cancellation, or failure.
Diagnostics retain the actual endpoint and both owned directories.
On Linux and macOS, REA starts the inspected JVM directly using Ghidra's own LaunchSupport
+6 -10
View File
@@ -1,4 +1,4 @@
import { chmod, mkdtemp, rm } from "node:fs/promises";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -23,7 +23,7 @@ export type PrivateRuntimeRootCapability =
| {
readonly available: true;
readonly reason: null;
readonly proof: "posix-mode-0700";
readonly proof: "posix-mkdtemp-owner-only";
};
/** Report whether this process can establish a private runtime root. */
@@ -32,7 +32,7 @@ export const privateRuntimeRootCapability = (
): PrivateRuntimeRootCapability =>
platform === "win32"
? windowsNativeCapabilities(platform).private_runtime_dacl
: { available: true, reason: null, proof: "posix-mode-0700" };
: { available: true, reason: null, proof: "posix-mkdtemp-owner-only" };
/** Expected failure when a runtime root's privacy boundary is unavailable. */
export class PrivateRuntimeRootUnavailableError extends Error {
@@ -77,13 +77,9 @@ export class PrivateRuntimeRoot {
const path = await mkdtemp(
join(options.parent ?? tmpdir(), options.prefix ?? "rea-provider-"),
);
try {
await chmod(path, 0o700);
return new PrivateRuntimeRoot(path);
} catch (cause: unknown) {
await rm(path, { recursive: true, force: true });
throw cause;
}
// POSIX mkdtemp establishes owner-only access atomically. Return its owner
// without a fallible permission rewrite and rollback after allocation.
return new PrivateRuntimeRoot(path);
}
/**
@@ -1,6 +1,7 @@
import { access, stat } from "node:fs/promises";
import { access, stat, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { fileURLToPath } from "node:url";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -57,7 +58,8 @@ describe("provider process runtime and wait primitives", () => {
parent: tmpdir(),
prefix: "rea-provider-test-",
});
expect((await stat(runtime.path)).mode & 0o777).toBe(0o700);
expect((await stat(runtime.path)).mode & 0o077).toBe(0);
await writeFile(join(runtime.path, "owned-scratch"), "fixture");
const first = runtime.close();
const second = runtime.close();