Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Fixed** On Linux, cached tasks no longer fail to spawn child processes in restricted sandboxes, for example rootless bubblewrap that denies the `seccomp` syscall. When the `seccomp` filter for file-access tracking cannot be installed, the process runs untracked instead and the run is reported as not cached. The not-cached message now reads "automatic file tracking couldn't record everything this task did", which fits both this case and a full tracking channel ([#700](https://github.com/voidzero-dev/vite-task/issues/700), [#701](https://github.com/voidzero-dev/vite-task/pull/701)).
- **Fixed** `vp run <task>` in a package that doesn't define the task now reports `Task "<task>" not found` when another package's `vite.config.*` fails to load, instead of failing with that package's error. Showing the tasks to choose from loads every package's config, so the task selector or task list is skipped then ([#987](https://github.com/voidzero-dev/vite-task/pull/987)).
- **Fixed** A task specifier like `vp run nope#build`, where no workspace package is named `nope`, now fails with `Package 'nope' not found in the workspace` and exits 1, including from a task's command, instead of running nothing and exiting 0. A short name that auto-completes to several scoped packages, like `app` for `@a/app` and `@b/app`, now fails as ambiguous. `--filter nope` still only warns and exits 0, unless `--fail-if-no-match` is set ([#984](https://github.com/voidzero-dev/vite-task/pull/984)).
- **Added** `vp run -vv` also lists what each cached run depends on, changed or not, and the output files a hit restores: in the detailed summary, under `Unchanged:` and `Outputs:`, and with `--dry-run --json`, as each step's `baseline.fingerprint` and `baseline.outputs`. It shows, for an unexpected hit, whether an edited file is an input at all. `-v` is now a counted flag, so `-vv` is the same as `--verbose --verbose` ([#969](https://github.com/voidzero-dev/vite-task/pull/969)).
Expand Down
5 changes: 4 additions & 1 deletion crates/fspy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ pub enum SpawnError {
/// so the accesses collected for the run are a subset of what it really
/// touched.
///
/// The tracking channel can be full, or a process can continue untracked
/// because the seccomp filter could not be installed.
///
/// The run itself is unaffected: recording must never stop the program
/// doing the work. What cannot be done is anything that needs every
/// access, caching above all, which has to treat the run as untracked
/// rather than as having touched only the paths that fit.
#[derive(thiserror::Error, Clone, Copy, PartialEq, Eq, Debug)]
#[error("the file-access records did not fit in the tracking channel")]
#[error("automatic file tracking could not record every file access")]
pub struct TrackingIncomplete;
31 changes: 2 additions & 29 deletions crates/fspy/tests/static_executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,15 @@
//! the CI builds with `-crt-static` the binary becomes dynamically linked,
//! defeating the purpose of these tests.
#![cfg(all(target_os = "linux", not(target_env = "musl")))]
use std::{
fs::{self, Permissions},
os::unix::fs::PermissionsExt as _,
path::{Path, PathBuf},
sync::LazyLock,
};
use std::path::Path;

use fspy::PathAccessIterable;
use fspy_shared_unix::is_dynamically_linked_to_libc;
use test_log::test;

use crate::test_utils::assert_contains;
use crate::test_utils::{assert_contains, test_bin_path};

mod test_utils;

const TEST_BIN_CONTENT: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_FSPY_TEST_BIN"));

fn test_bin_path() -> &'static Path {
static TEST_BIN_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
assert_eq!(
is_dynamically_linked_to_libc(TEST_BIN_CONTENT),
Ok(false),
"Test binary is not a static executable"
);

let tmp_dir = env!("CARGO_TARGET_TMPDIR");
let test_bin_path = PathBuf::from(tmp_dir).join("fspy-test-bin");
fs::write(&test_bin_path, TEST_BIN_CONTENT).expect("failed to write test binary");
fs::set_permissions(&test_bin_path, Permissions::from_mode(0o755))
.expect("failed to set permissions on test binary");

test_bin_path
});
TEST_BIN_PATH.as_path()
}

async fn track_test_bin(args: &[&str], cwd: Option<&str>) -> PathAccessIterable {
let mut cmd = fspy::Command::new(test_bin_path());
if let Some(cwd) = cwd {
Expand Down
43 changes: 43 additions & 0 deletions crates/fspy/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,46 @@ pub async fn spawn_command(cmd: vt_subprocess_test::Command) -> anyhow::Result<P
assert!(termination.status.success());
Ok(termination.path_accesses.expect("the test region holds every record"))
}

/// Writes the static test binary to a file named after the current test
/// binary, so test binaries running at once don't rewrite a file another one
/// is executing, and returns its path.
///
/// # Panics
///
/// Panics if the test binary is not statically linked or cannot be written.
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
#[expect(
clippy::allow_attributes,
reason = "allow attribute required for conditionally-used helper"
)]
#[allow(dead_code, reason = "not all test files use this helper")]
pub fn test_bin_path() -> &'static Path {
use std::{
fs::{self, Permissions},
os::unix::fs::PermissionsExt as _,
path::PathBuf,
sync::LazyLock,
};

use fspy_shared_unix::is_dynamically_linked_to_libc;

const TEST_BIN_CONTENT: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_FSPY_TEST_BIN"));

static TEST_BIN_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
assert_eq!(
is_dynamically_linked_to_libc(TEST_BIN_CONTENT),
Ok(false),
"Test binary is not a static executable"
);

let test_bin_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR"))
.join(concat!("fspy-test-bin-", env!("CARGO_CRATE_NAME")));
fs::write(&test_bin_path, TEST_BIN_CONTENT).expect("failed to write test binary");
fs::set_permissions(&test_bin_path, Permissions::from_mode(0o755))
.expect("failed to set permissions on test binary");

test_bin_path
});
TEST_BIN_PATH.as_path()
}
128 changes: 128 additions & 0 deletions crates/fspy/tests/untracked_fallback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//! Tests for the untracked-exec fallback: when the preload cannot install
//! the seccomp filter, the exec must proceed untracked and the run must be
//! reported as incompletely tracked (so it is not cached), rather than
//! every spawn failing. Skipped on musl: no preload library exists there.
#![cfg(all(target_os = "linux", not(target_env = "musl")))]

use std::{
ffi::OsStr,
fs::{self, Permissions},
os::unix::{ffi::OsStrExt as _, fs::PermissionsExt as _},
path::{Path, PathBuf},
process::Command,
};

use allocator_api2::alloc::Global;
use fspy_seccomp_unotify::payload::SeccompPayload;
use fspy_shared::ipc::{
IpcStr,
channel::{Receiver, RecordsLost, channel},
};
use fspy_shared_unix::payload::{Payload, encode_payload};

use crate::test_utils::test_bin_path;

mod test_utils;

/// The preload cdylib, built as a dependency of this crate.
const PRELOAD_CDYLIB: &str = env!("CARGO_CDYLIB_FILE_FSPY_PRELOAD_UNIX");

/// Clears `command`'s environment and preloads fspy into it with a seccomp
/// payload whose install always fails. Returns the channel the preload
/// reports to.
fn preload_with_failing_seccomp(command: &mut Command) -> Receiver<Global> {
let receiver = channel(1 << 30, Global).unwrap();
{
let preload_path: &IpcStr = Path::new(PRELOAD_CDYLIB).into();
let payload = Payload {
ipc_channel_conf: receiver.conf(),
preload_path,
seccomp_payload: SeccompPayload::unreachable(
b"/nonexistent/fspy-unreachable-supervisor".to_vec(),
),
};
let bump = bumpalo::Bump::new();
let encoded = encode_payload(payload, &bump);
command
.env_clear()
.env("LD_PRELOAD", PRELOAD_CDYLIB)
.env("FSPY_PAYLOAD", OsStr::from_bytes(encoded.encoded_string.as_ref()));
}
receiver
}

/// A static binary exec'd from a traced process needs the preload's inline
/// seccomp install. When that install fails (here: the payload's empty
/// filter, which the kernel refuses), the binary must still run — untracked
/// — and the channel must report the loss.
#[test]
fn static_binary_runs_untracked_when_injection_fails() {
let mut command = Command::new("/bin/sh");
let receiver = preload_with_failing_seccomp(&mut command);
let output = command
.arg("-c")
.arg(format!("exec {} stat /hello", test_bin_path().display()))
.output()
.expect("failed to spawn the shell");
assert!(
output.status.success(),
"the static binary did not run: {}",
String::from_utf8_lossy(&output.stderr)
);

let Err(RecordsLost) = receiver.close() else {
panic!("the channel did not report the untracked exec");
};
}

/// The untracked fallback must replay the interposed call as it was made,
/// not as `execve`. GNU `env` runs its command through `execvp`, so a bare
/// program name found only on `PATH` still runs when injection fails;
/// forwarding it to `execve` would fail with `ENOENT` instead.
#[test]
fn execvp_fallback_keeps_path_search() {
let test_bin = test_bin_path();
let mut command = Command::new("/usr/bin/env");
let receiver = preload_with_failing_seccomp(&mut command);
let output = command
.arg(test_bin.file_name().unwrap())
.arg("stat")
.arg("/hello")
.env("PATH", test_bin.parent().unwrap())
.current_dir("/")
.output()
.expect("failed to spawn env");
assert!(
output.status.success(),
"the execvp fallback lost its PATH search: {}",
String::from_utf8_lossy(&output.stderr)
);

let Err(RecordsLost) = receiver.close() else {
panic!("the channel did not report the untracked exec");
};
}

/// Only a failed seccomp install takes the untracked path. An exec that
/// fails the way the real exec would, here `ENOEXEC` for a script without a
/// `#!` line, keeps its errno and leaves the trace complete. `sh` then runs
/// the script itself, as it does without tracking.
#[test]
fn exec_errors_are_not_reported_as_lost() {
let script = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("fspy-script-without-shebang");
fs::write(&script, "exit 0\n").expect("failed to write the script");
fs::set_permissions(&script, Permissions::from_mode(0o755))
.expect("failed to set permissions on the script");

let mut command = Command::new("/bin/sh");
let receiver = preload_with_failing_seccomp(&mut command);
let output =
command.arg("-c").arg(script.as_os_str()).output().expect("failed to spawn the shell");
assert!(
output.status.success(),
"the script without a shebang did not run: {}",
String::from_utf8_lossy(&output.stderr)
);

assert!(receiver.close().is_ok(), "an authentic exec error was reported as an untracked exec");
}
11 changes: 11 additions & 0 deletions crates/fspy_client_unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ impl<'a> Client<'a> {
ipc_sender.send(&mode.with_path(path.into()));
}

/// Marks the run's trace incomplete, so the receiver treats it as
/// untracked and the runner does not cache it. Call it before the
/// process does something that tracking cannot record, such as an exec
/// that continues untracked because [`PreExec::run`] failed. It does
/// nothing when this client has no channel sender.
pub fn report_loss(&self) {
if let Some(ipc_sender) = &self.ipc_sender {
ipc_sender.report_loss();
}
}

/// Resolves and reports an exec, returning the transformed arguments to
/// forward and what to run before forwarding them.
///
Expand Down
Loading
Loading