diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index aea4453a..c71a664b 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -28,8 +28,8 @@ jobs: run: docker build -f docker/rust-builder.Dockerfile -t faunosteo_rust_builder:1.99.0 docker - name: fmt, clippy, tests, ts-rs export, cargo-deny (licenses, bans, sources) run: bash docker/rust-run.sh bash scripts/rust-check.sh - - name: Committed TypeScript types match the Rust contracts - run: git diff --exit-code -- packages/core-wasm/types + - name: Committed TypeScript types match the Rust contracts (no modified or new file) + run: test -z "$(git status --porcelain -- packages/core-wasm/types)" || { git status --porcelain -- packages/core-wasm/types; exit 1; } - name: Browser module builds (size printed; the budget is asserted by the vitest proofs) run: bash docker/rust-run.sh bash scripts/wasm-build.sh diff --git a/crates/worker/src/sandbox.rs b/crates/worker/src/sandbox.rs index faf979b8..015cf5c3 100644 --- a/crates/worker/src/sandbox.rs +++ b/crates/worker/src/sandbox.rs @@ -100,18 +100,22 @@ pub fn apply(limits: &Limits, seccomp: bool) -> Result<(), SandboxError> { /// `PR_SET_DUMPABLE 0` is the kernel-side stop, `RLIMIT_CORE 0` the belt. #[allow(unsafe_code)] fn disable_core_dumps() -> Result<(), SandboxError> { - // SAFETY: prctl is a variadic FFI; for PR_SET_DUMPABLE the kernel reads one integer - // (the new flag) and requires the three remaining arguments to be zero, which is what is - // passed: no pointer, no memory of this process involved, and only this process's flag - // changes. The return code is checked below. - let rc = unsafe { libc::prctl(libc::PR_SET_DUMPABLE, 0, 0, 0, 0) }; + /// prctl reads its variadic arguments as unsigned long: the flag value and the + /// arguments an option ignores are passed at that width. + const NOT_DUMPABLE: libc::c_ulong = 0; + const UNUSED: libc::c_ulong = 0; + // SAFETY: prctl is a variadic FFI reading its extra arguments as unsigned long; for + // PR_SET_DUMPABLE the kernel uses the first one (the new flag) and ignores the other + // three, passed at that width: no pointer, no memory of this process involved, and only + // this process's flag changes. The return code is checked below. + let rc = unsafe { libc::prctl(libc::PR_SET_DUMPABLE, NOT_DUMPABLE, UNUSED, UNUSED, UNUSED) }; if rc != 0 { return Err(SandboxError::Rlimit("PR_SET_DUMPABLE".to_owned())); } - // SAFETY: PR_GET_DUMPABLE reads this process's flag; the four extra arguments must be - // zero and are. The result is the flag (0 expected) or -1 on failure: any non-zero value - // is refused below. - let dumpable = unsafe { libc::prctl(libc::PR_GET_DUMPABLE, 0, 0, 0, 0) }; + // SAFETY: PR_GET_DUMPABLE reads this process's flag and ignores the extra arguments, + // passed as unsigned-long zeros. The result is the flag (0 expected) or -1 on failure: + // any non-zero value is refused below. + let dumpable = unsafe { libc::prctl(libc::PR_GET_DUMPABLE, UNUSED, UNUSED, UNUSED, UNUSED) }; if dumpable != 0 { return Err(SandboxError::Rlimit(format!( "PR_GET_DUMPABLE = {dumpable}" diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 509c0bce..ac8901cc 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -15,8 +15,18 @@ stage() { stage "rust: fmt, clippy, tests, ts-rs export, cargo-deny (native toolchain)" bash scripts/rust-check.sh -stage "rust: committed TypeScript types match the Rust contracts" -git diff --exit-code -- packages/core-wasm/types +stage "rust: committed TypeScript types match the Rust contracts (no modified or new file)" +drift="$(git status --porcelain -- packages/core-wasm/types)" +if [ -n "$drift" ]; then + echo "packages/core-wasm/types differs from the committed types:" >&2 + echo "$drift" >&2 + exit 1 +fi +stage "rust: RustSec advisories (warn-only until the CI/CD step; the release gate blocks)" +# Out of the blocking path on purpose (RUST_ARCHITECTURE_REVIEW VIII.3); printed here because +# no nightly job runs yet. Needs the network for the advisory database. +(cd . && . scripts/rust-env.sh && cargo deny check advisories) \ + || echo "== advisories: findings or no network above; review before a release" stage "wasm: browser module (the core-wasm proofs run on it in the Node pipeline)" bash scripts/wasm-build.sh stage "node: typecheck, tests, lint, build" diff --git a/scripts/rust-env.sh b/scripts/rust-env.sh index 411b9b36..f9512c08 100644 --- a/scripts/rust-env.sh +++ b/scripts/rust-env.sh @@ -1,10 +1,16 @@ # Sourced by the Rust scripts (never executed): puts the user-level rustup toolchain on # PATH when the calling shell did not. Non-interactive shells skip ~/.bashrc, so editor # tasks, git hooks and agent shells start without ~/.cargo/bin. rustup then selects the -# channel pinned by rust-toolchain.toml. Nothing here installs anything. +# channel pinned by rust-toolchain.toml. Nothing here installs anything. The directory is +# appended, never prepended (the guard only fires when no cargo is on PATH, and the system +# tools used by the scripts must keep resolving first), and only when it is absolute. cargo_bin="${CARGO_HOME:-$HOME/.cargo}/bin" -if ! command -v cargo >/dev/null 2>&1 && [ -x "$cargo_bin/cargo" ]; then - PATH="$cargo_bin:$PATH" +case "$cargo_bin" in + /*) ;; + *) cargo_bin="" ;; +esac +if ! command -v cargo >/dev/null 2>&1 && [ -n "$cargo_bin" ] && [ -x "$cargo_bin/cargo" ]; then + PATH="$PATH:$cargo_bin" export PATH fi unset cargo_bin diff --git a/scripts/wasm-build.sh b/scripts/wasm-build.sh index 1cf49d8a..98e308b9 100755 --- a/scripts/wasm-build.sh +++ b/scripts/wasm-build.sh @@ -25,7 +25,7 @@ fi cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked --features proofs out=packages/core-wasm/pkg -rm -rf "$out" +rm -rf packages/core-wasm/pkg wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \ target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm