fix(conversation): pi-unpin S4 fifth re-check: the own-copy rule for fit PATH entries covers /proc and /dev only; the sandbox's /tmp starts empty (pi-fit.mjs makes it fresh for each run), so a /tmp entry is judged like any directory the sandbox doesn't show, and S4h and a checkout under /tmp no longer refuse for it (R5-1); a lookup's problem line with a path or a control character in it reads "the pi lookup gave no binary"; S4h covers a /dev entry, a /tmp entry ahead of the engine's, and lookup lines (#1873, lane pi-unpin-s4)
This commit is contained in:
1 parent
83250ef36b
commit
c065034a6e
3 files changed
+44
-17
No files matched your search
@@ -331,16 +331,20 @@ can disagree with it.
|
||||
own file at its path. Up to the first `node`, every entry must read the
|
||||
same in the sandbox as on the host: absolute (env reads an empty or
|
||||
relative one against the fit check's directory), already in plain form (a
|
||||
`..` after a link goes where the link points), and not in `/proc`, `/dev`
|
||||
or `/tmp`, which the sandbox makes its own, by its spelling or by the real
|
||||
path of the nearest part of it that exists. An entry or a `node` link
|
||||
there that can't be checked refuses too. No `node` the sandbox can't show
|
||||
`..` after a link goes where the link points), and not in `/proc` or
|
||||
`/dev`, which the sandbox makes its own, by its spelling or by the real
|
||||
path of the nearest part of it that resolves. The sandbox's `/tmp` is its
|
||||
own too, but starts empty, so a `/tmp` entry is judged like any other
|
||||
directory the sandbox doesn't show. An entry or a `node` link there that
|
||||
can't be checked refuses too. No `node` the sandbox can't show
|
||||
(or reaches through a link it can't show) may come before the first one it
|
||||
can, and that first one must be this Node. No `node` anywhere on the PATH
|
||||
may lie inside the package the fit check mounts. Otherwise the start
|
||||
refuses `engine-feature-missing`. A refusal line, the fit check's
|
||||
included, names the pi by the lookup's label, which is words such as
|
||||
`MOSAIC_PI_BIN`, or "the pi" for any other label.
|
||||
`MOSAIC_PI_BIN`, or "the pi" for any other label. A lookup that found no
|
||||
pi refuses with its own line, or "the pi lookup gave no binary" when that
|
||||
line holds a path or a control character.
|
||||
The controller keeps a frozen plain copy of the lookup's answer, its own
|
||||
string data fields only, so an answer that changes later changes nothing.
|
||||
That copy must still be the lookup's at each check: the lookup run again on
|
||||
|
||||
@@ -31,7 +31,7 @@ import { LiveSessionGuard, realPath } from "./guard.mjs";
|
||||
import { ID, fragments, safeId } from "./parts.mjs";
|
||||
import { parseSnapshot } from "./pi.mjs";
|
||||
import { ENGINE_FEATURE_MISSING, ENGINE_PIN_MISMATCH, OLD_PIN_LINE, UNSEALED_ENGINE, argvDigest, buildPiArgs, checkSeal, engineEnv, oldPinRecord } from "./pi-seal.mjs";
|
||||
import { executable, locate } from "../../plugins/harness/pi/binary.mjs";
|
||||
import { PACKAGE, executable, locate } from "../../plugins/harness/pi/binary.mjs";
|
||||
import { sessionEnv } from "../../seat/src/session.mjs";
|
||||
import { levels } from "../../plugins/harness/pi/index.mjs";
|
||||
import { piFit } from "../../harness/src/pi-fit.mjs";
|
||||
@@ -171,9 +171,12 @@ const ANSWER_FIELDS = ["bin", "label", "problem", ...ANSWER_KEYS];
|
||||
// too loose.
|
||||
const SHOWN_DIRS = ["/usr", "/etc", "/bin", "/lib", "/lib64", "/sbin"];
|
||||
const shownDir = (p) => SHOWN_DIRS.some((d) => p === d || p.startsWith(d + "/"));
|
||||
// The sandbox makes its own /proc, /dev and /tmp, so a path there names
|
||||
// something else inside it than on the host.
|
||||
const OWN_COPY_DIRS = ["/proc", "/dev", "/tmp"];
|
||||
// The sandbox makes its own /proc and /dev, so a path there names something
|
||||
// else inside it than on the host. Its /tmp is another directory too, but one
|
||||
// that starts empty (pi-fit.mjs makes it fresh for each run), so an entry
|
||||
// there holds no node in the sandbox, and a node the host finds there is one
|
||||
// the sandbox can't show.
|
||||
const OWN_COPY_DIRS = ["/proc", "/dev"];
|
||||
function shownInFit(p, hops = 0) {
|
||||
if (hops > 40) return null;
|
||||
const parts = p.split("/").filter(Boolean);
|
||||
@@ -326,7 +329,11 @@ export class Controller {
|
||||
#piFile() {
|
||||
const pi = this.pi;
|
||||
if (!pi || typeof pi !== "object" || typeof pi.bin !== "string" || !pi.bin) {
|
||||
const why = typeof pi?.problem === "string" && pi.problem ? pi.problem : "the pi lookup gave no binary";
|
||||
// The lookup's problem lines are words and its package's name; a
|
||||
// hand-built one with a path or a control character in it isn't shown.
|
||||
const problem = pi?.problem;
|
||||
const plain = typeof problem === "string" && problem && !/[\x00-\x1f\x7f]/.test(problem) && !problem.replaceAll(PACKAGE, "").includes("/");
|
||||
const why = plain ? problem : "the pi lookup gave no binary";
|
||||
throw new ControlRefusal(ENGINE_FEATURE_MISSING, why);
|
||||
}
|
||||
const label = this.#label();
|
||||
@@ -384,7 +391,7 @@ export class Controller {
|
||||
// first node, every entry must read the same in both: absolute, already
|
||||
// in plain form (a ".." after a link goes where the link points, not
|
||||
// where the text does), and nowhere the sandbox gives its own copy of
|
||||
// (/proc, /dev, /tmp), in its spelling or its real path. An entry or a
|
||||
// (/proc, /dev), in its spelling or its real path. An entry or a
|
||||
// node there that can't be checked refuses. No node the sandbox can't show
|
||||
// may come first, and the first one must be this node. No node on the
|
||||
// PATH may come from the package the fit check mounts.
|
||||
|
||||
@@ -840,7 +840,7 @@ test("S4g: a lookup answer that is no longer the lookup's refuses unsealed-engin
|
||||
await make(piAt(good.bin)).close();
|
||||
});
|
||||
|
||||
test("S4h: a first line the kernel and node read differently refuses engine-feature-missing: an absolute node that isn't the engine's, a first line past 256 bytes, a CR before the newline, under env a node from the package, a node the fit check's sandbox can't see ahead of the first it can (even a link to the engine's node), an empty, relative or unplain entry before the first node, one in /proc, /dev or /tmp, one that can't be checked, or a first shown node that isn't the engine's; the engine's own directory first launches, and a label that isn't the lookup's kind reads \"the pi\", in the fit check's line too", async () => {
|
||||
test("S4h: a first line the kernel and node read differently refuses engine-feature-missing: an absolute node that isn't the engine's, a first line past 256 bytes, a CR before the newline, under env a node from the package, a node the fit check's sandbox can't see ahead of the first it can (even a link to the engine's node), an empty, relative or unplain entry before the first node, one in /proc or /dev, one that can't be checked, or a first shown node that isn't the engine's; the engine's own directory first launches, and a label that isn't the lookup's kind reads \"the pi\", in the fit check's line too; a lookup's problem line shows, a hand-built one with a path or a newline doesn't", async () => {
|
||||
const fx = fixture();
|
||||
const refused = async (pi, message, f = fx) => {
|
||||
const { ctrl, launcher } = controllerFor(f, { pi });
|
||||
@@ -930,11 +930,11 @@ test("S4h: a first line the kernel and node read differently refuses engine-feat
|
||||
// text does.
|
||||
symlinkSync("/usr/lib", join(fx.base, "sys"));
|
||||
await onPath(`${fx.base}/sys/../bin`, () => refused(envPi.found, "MOSAIC_PI_BIN's first line runs node from the fit check's PATH, which has an entry that isn't in plain form", fx2));
|
||||
// The sandbox makes its own /proc, /dev and /tmp: pid 1 there is its own,
|
||||
// and a link into /proc counts too, even past a pid the host lacks.
|
||||
// The sandbox makes its own /proc and /dev: pid 1 there is its own, and a
|
||||
// link into /proc counts too, even past a pid the host lacks.
|
||||
const ownCopy = "MOSAIC_PI_BIN's first line runs node from the fit check's PATH, which has an entry the fit check's sandbox has its own copy of";
|
||||
await onPath("/proc/1/root/usr/bin", () => refused(envPi.found, ownCopy, fx2));
|
||||
await onPath("/tmp/mosaic-no-such-dir", () => refused(envPi.found, ownCopy, fx2));
|
||||
await onPath("/dev/mosaic-no-such-dir", () => refused(envPi.found, ownCopy, fx2));
|
||||
symlinkSync("/proc", join(fx.base, "p"));
|
||||
await onPath(`${fx.base}/p/999999999/root/usr/bin`, () => refused(envPi.found, ownCopy, fx2));
|
||||
// A node link that leads nowhere on the host may lead somewhere in the
|
||||
@@ -976,8 +976,9 @@ test("S4h: a first line the kernel and node read differently refuses engine-feat
|
||||
// The engine's own directory first: the sandbox shows that file at the same
|
||||
// path, so env runs the engine's node in both.
|
||||
// Entries after it are never read, so a trailing slash on it and an empty
|
||||
// entry at the end change nothing.
|
||||
await withPath(`${dirname(process.execPath)}/:/usr/bin:/bin:`, async () => {
|
||||
// entry at the end change nothing. The sandbox's /tmp starts empty, so a
|
||||
// /tmp entry with no node on the host holds none there either.
|
||||
await withPath(`/tmp/mosaic-no-such-dir:${dirname(process.execPath)}/:/usr/bin:/bin:`, async () => {
|
||||
const h2 = await started({ fx: fx2, pi: envPi.found });
|
||||
try {
|
||||
assert.equal(h2.launcher.launches.length, 1);
|
||||
@@ -992,6 +993,21 @@ test("S4h: a first line the kernel and node read differently refuses engine-feat
|
||||
// Nor the fit check's own line.
|
||||
const lacking = standInPi(join(fx.base, "pi-lacking"), { modes: ["text", "json"] });
|
||||
await refused({ ...lacking.found, label: join(fx.base, "named") }, "pi 9.9.9 (the pi) lacks --mode rpc");
|
||||
// A lookup that found no pi refuses when the controller is built: its own
|
||||
// line, which names the step and the package, never a path; a hand-built
|
||||
// line with a path or a newline isn't shown.
|
||||
const unbuilt = (pi, message) =>
|
||||
assert.throws(() => controllerFor(fx, { pi }), (e) => {
|
||||
assert.equal(e.code, ENGINE_FEATURE_MISSING);
|
||||
assert.equal(e.message, message);
|
||||
return true;
|
||||
});
|
||||
unbuilt(piAt("relative/pi"), "MOSAIC_PI_BIN isn't an executable file at an absolute path");
|
||||
const loose = join(fx.base, "loose-pi");
|
||||
writeFileSync(loose, "#!/usr/bin/env node\n", { mode: 0o755 });
|
||||
unbuilt(piAt(loose), `MOSAIC_PI_BIN isn't part of the ${PI_PACKAGE} package`);
|
||||
unbuilt({ bin: null, problem: `${fx.base} has no pi` }, "the pi lookup gave no binary");
|
||||
unbuilt({ bin: null, problem: "no pi\nrefused: forged" }, "the pi lookup gave no binary");
|
||||
});
|
||||
|
||||
// ---- W11, W16, W17 ----------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user