fix(strict): bind the bundled stdlib and verify strict resources

- Strict child now gets the verified stdlib tree read-only at
  /run/marqdo-stdlib with MARQDO_STDLIB_DIR set, so Compat-C 打印 works under
  strict without exposing a host path (ADR-0021 update).
- Add a strict-lane negative: resource.open(file) is refused with
  permission.denied; hello/factorial/multi-module and --json still pass.
- StrictHostCommand gains stdlib_dir; CLI discovers the bundle and sandbox
  binds it; sandbox tests constructors updated.

Evidence: G-C lane PASS on the disposable Ubuntu 26.04 VM (7/7 adversarial
matrix, positive CLI, strict language-resource refusal, forged marker), plus
fmt/clippy/423 local tests.
This commit is contained in:
cflmy committed 2026-11-20 22:57:49 +08:00
1 parent 1be4662049
commit 1d87f98539
9 files changed
+65 -4

No files matched your search

+5
View File
@@ -682,6 +682,10 @@ fn launch_strict_process(
.unwrap_or(1024 * 1024)
.min(64 * 1024 * 1024);
let timeout = Duration::from_secs(settings.timeout.unwrap_or(30));
let stdlib_dir = crate::stdlib::StdlibBundle::discover()
.ok()
.flatten()
.map(|bundle| bundle.root().to_path_buf());
let command = marqdo_sandbox::StrictHostCommand {
program: &program,
args: &args,
@@ -690,6 +694,7 @@ fn launch_strict_process(
original_document: document,
output_limit,
timeout,
stdlib_dir: stdlib_dir.as_deref(),
};
match marqdo_sandbox::launch_strict(&command) {
Ok(code) => code,
+5
View File
@@ -89,6 +89,11 @@ impl StdlibBundle {
})
}
/// Bundle root.
pub fn root(&self) -> &Path {
&self.root
}
/// Declared stdlib version.
pub fn version(&self) -> &str {
&self.version
+2
View File
@@ -232,6 +232,8 @@ pub struct StrictHostCommand<'a> {
pub output_limit: usize,
/// Wall-clock budget for the supervised process tree.
pub timeout: Duration,
/// Verified bundled stdlib directory to bind read-only when present.
pub stdlib_dir: Option<&'a Path>,
}
/// Launch a command inside the strict sandbox (Linux only).
+12
View File
@@ -317,6 +317,16 @@ fn run_with(
})?;
let mut args = common_args();
if let Some(stdlib) = command.stdlib_dir {
args.extend([
OsString::from("--ro-bind"),
stdlib.as_os_str().to_os_string(),
OsString::from("/run/marqdo-stdlib"),
OsString::from("--setenv"),
OsString::from("MARQDO_STDLIB_DIR"),
OsString::from("/run/marqdo-stdlib"),
]);
}
args.extend([
OsString::from("--ro-bind"),
project_root.as_os_str().to_os_string(),
@@ -548,6 +558,7 @@ mod tests {
original_document: None,
output_limit: 4096,
timeout: Duration::from_secs(1),
stdlib_dir: None,
};
let error = run_with(
&command,
@@ -585,6 +596,7 @@ mod tests {
original_document: None,
output_limit: 4096,
timeout: Duration::from_secs(1),
stdlib_dir: None,
};
let error = run_with(
&command,
@@ -111,6 +111,7 @@ fn run(helper: &Path, project: &Path, outside: &Path, mode: &str) -> StrictOutco
original_document: None,
output_limit: 64 * 1024,
timeout: Duration::from_secs(3),
stdlib_dir: None,
};
launch_strict_capture(&command).unwrap_or_else(|error| panic!("{mode}: {error}"))
}
@@ -267,6 +268,7 @@ fn strict_supervisor_enforces_memory_cpu_and_output_limits() {
original_document: None,
output_limit: 64 * 1024,
timeout: Duration::from_secs(2),
stdlib_dir: None,
};
let cpu = launch_strict_capture(&command).expect_err("CPU loop must be stopped");
let message = cpu.to_string();
@@ -283,6 +285,7 @@ fn strict_supervisor_enforces_memory_cpu_and_output_limits() {
original_document: None,
output_limit: 64 * 1024,
timeout: Duration::from_secs(3),
stdlib_dir: None,
})
.expect("output helper should be captured, not spawn-failed");
assert!(