Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/fspy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ publish = false

[dependencies]
allocator-api2 = { workspace = true, features = ["alloc"] }
wincode = { workspace = true }
bumpalo = { workspace = true, features = ["allocator-api2", "collections"] }
derive_more = { workspace = true, features = ["debug"] }
vt_materialized_artifact = { workspace = true }
Expand Down Expand Up @@ -51,6 +50,7 @@ fspy_detours_sys = { workspace = true }
fspy_preload_windows = { workspace = true }
ntapi = { workspace = true }
winapi = { workspace = true, features = ["winbase", "securitybaseapi", "handleapi"] }
wincode = { workspace = true }
winsafe = { workspace = true, features = ["kernel"] }

[target.'cfg(target_os = "macos")'.dev-dependencies]
Expand Down
18 changes: 6 additions & 12 deletions crates/fspy/src/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use allocator_api2::alloc::Global;
use fspy_shared::ipc::{
PathAccess,
channel::{FrameReader, Receiver},
};
use fspy_shared::ipc::{AccessReader, AccessReceiver, PathAccess};

use crate::error::TrackingIncomplete;

Expand Down Expand Up @@ -35,10 +32,10 @@ pub fn shm_capacity() -> usize {

/// The path accesses a run reported through the IPC channel.
pub struct ChannelAccesses {
frames: FrameReader,
reader: AccessReader,
}

impl TryFrom<Receiver<Global>> for ChannelAccesses {
impl TryFrom<AccessReceiver<Global>> for ChannelAccesses {
type Error = TrackingIncomplete;

/// Closes the channel and takes every record it collected.
Expand All @@ -53,16 +50,13 @@ impl TryFrom<Receiver<Global>> for ChannelAccesses {
/// [`TrackingIncomplete`] when a tracked process could not record
/// something it went on to do. What did arrive is then a subset of
/// what the run really touched, so none of it is handed back.
fn try_from(receiver: Receiver<Global>) -> Result<Self, TrackingIncomplete> {
Ok(Self { frames: receiver.close().map_err(|_| TrackingIncomplete)? })
fn try_from(receiver: AccessReceiver<Global>) -> Result<Self, TrackingIncomplete> {
Ok(Self { reader: receiver.close().map_err(|_| TrackingIncomplete)? })
}
}

impl ChannelAccesses {
pub fn iter_path_accesses(&self) -> impl Iterator<Item = PathAccess<'_>> {
self.frames.iter().map(|frame| {
wincode::deserialize_exact(frame)
.expect("committed frames are complete under the channel protocol")
})
self.reader.iter()
}
}
7 changes: 4 additions & 3 deletions crates/fspy/src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::sync::Arc;
use fspy_seccomp_unotify::supervisor::supervise;
#[cfg(not(target_env = "musl"))]
use fspy_shared::ipc::IpcStr;
use fspy_shared::ipc::{PathAccess, channel::channel};
use fspy_shared::ipc::{PathAccess, access_channel};
use fspy_shared_unix::{
exec::ExecResolveConfig,
payload::{Payload, encode_payload},
Expand Down Expand Up @@ -88,8 +88,9 @@ impl SpyImpl {
mut command: Command,
cancellation_token: CancellationToken,
) -> Result<TrackedChild, SpawnError> {
let ipc_receiver = channel(crate::ipc::shm_capacity(), allocator_api2::alloc::Global)
.map_err(SpawnError::ChannelCreation)?;
let ipc_receiver =
access_channel(crate::ipc::shm_capacity(), allocator_api2::alloc::Global)
.map_err(SpawnError::ChannelCreation)?;

// The supervisor records the accesses it intercepts into the same
// channel as the preload library.
Expand Down
6 changes: 3 additions & 3 deletions crates/fspy/src/unix/syscall_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use fspy_seccomp_unotify::{
impl_handler,
supervisor::handler::arg::{CStrPtr, Caller, Fd},
};
use fspy_shared::ipc::{AccessMode, PathAccess, channel::Sender};
use fspy_shared::ipc::{AccessMode, AccessSender, PathAccess};

const PATH_MAX: usize = libc::PATH_MAX as usize;

Expand All @@ -27,12 +27,12 @@ const PATH_MAX: usize = libc::PATH_MAX as usize;
/// every record is published before the access it describes, as the channel
/// requires of its senders.
pub struct SyscallHandler {
ipc_sender: Arc<Sender>,
ipc_sender: Arc<AccessSender>,
path_read_buf: [u8; PATH_MAX],
}

impl SyscallHandler {
pub const fn new(ipc_sender: Arc<Sender>) -> Self {
pub const fn new(ipc_sender: Arc<AccessSender>) -> Self {
Self { ipc_sender, path_read_buf: [0; PATH_MAX] }
}

Expand Down
4 changes: 2 additions & 2 deletions crates/fspy/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use fspy_detours_sys::{DetourCopyPayloadToProcess, DetourUpdateProcessWithDll};
use fspy_shared::{
ipc::{PathAccess, channel::channel},
ipc::{PathAccess, access_channel},
windows::{PAYLOAD_ID, Payload},
};
use futures_util::FutureExt;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl SpyImpl {
let ansi_dll_path_with_nul = &self.ansi_dll_path_with_nul;
command.env("FSPY", "1");

let receiver = channel(crate::ipc::shm_capacity(), allocator_api2::alloc::Global)
let receiver = access_channel(crate::ipc::shm_capacity(), allocator_api2::alloc::Global)
.map_err(SpawnError::ChannelCreation)?;

let payload = Payload {
Expand Down
13 changes: 5 additions & 8 deletions crates/fspy/tests/untracked_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use std::{

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

use crate::test_utils::test_bin_path;
Expand All @@ -30,8 +27,8 @@ 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();
fn preload_with_failing_seccomp(command: &mut Command) -> AccessReceiver<Global> {
let receiver = access_channel(1 << 30, Global).unwrap();
{
let preload_path: &IpcStr = Path::new(PRELOAD_CDYLIB).into();
let payload = Payload {
Expand Down Expand Up @@ -70,7 +67,7 @@ fn static_binary_runs_untracked_when_injection_fails() {
String::from_utf8_lossy(&output.stderr)
);

let Err(RecordsLost) = receiver.close() else {
let Err(AccessCloseError::Reported) = receiver.close() else {
panic!("the channel did not report the untracked exec");
};
}
Expand Down Expand Up @@ -98,7 +95,7 @@ fn execvp_fallback_keeps_path_search() {
String::from_utf8_lossy(&output.stderr)
);

let Err(RecordsLost) = receiver.close() else {
let Err(AccessCloseError::Reported) = receiver.close() else {
panic!("the channel did not report the untracked exec");
};
}
Expand Down
12 changes: 6 additions & 6 deletions crates/fspy_client_unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{ffi::OsStr, fmt::Debug, os::unix::ffi::OsStrExt as _, path::Path};

use allocator_api2::alloc::Allocator;
use convert::{ToAbsolutePath, ToAccessMode};
use fspy_shared::ipc::{AccessMode, channel::Sender};
use fspy_shared::ipc::{AccessMode, AccessSender};
use fspy_shared_unix::{
exec::ExecResolveConfig,
payload::{EncodedPayload, decode_payload_from_env},
Expand All @@ -22,7 +22,7 @@ use raw_exec::RawExec;

pub struct Client<'a> {
encoded_payload: EncodedPayload<'a>,
ipc_sender: Option<Sender>,
ipc_sender: Option<AccessSender>,
}

// Seals the view-only design: the client holds views of leaked memory and
Expand Down Expand Up @@ -62,10 +62,10 @@ impl<'a> Client<'a> {
) -> Self {
let encoded_payload = decode_payload_from_env(envs, allocator.clone()).unwrap();

// `None` when the channel is already over, which happens when this
// process starts after the root target exited. Nothing is said
// about it: a preload library writing to the traced process's
// stderr corrupts whatever that process is printing.
// `None` when the channel is already closed — because the root target
// exited, the channel overflowed, or an earlier process aborted
// tracking. Nothing is said about it: a preload library writing to the
// traced process's stderr corrupts whatever that process is printing.
let ipc_sender = encoded_payload.payload.ipc_channel_conf.sender(allocator);

Self { encoded_payload, ipc_sender }
Expand Down
12 changes: 6 additions & 6 deletions crates/fspy_preload_windows/src/windows/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ use std::{cell::SyncUnsafeCell, ffi::CStr, mem::MaybeUninit};
use allocator_api2::alloc::Allocator;
use fspy_detours_sys::DetourCopyPayloadToProcess;
use fspy_shared::{
ipc::{PathAccess, channel::Sender},
ipc::{AccessSender, PathAccess},
windows::{PAYLOAD_ID, Payload},
};
use winapi::{shared::minwindef::BOOL, um::winnt::HANDLE};

pub struct Client<'a> {
payload: Payload<'a>,
payload_bytes: &'a [u8],
ipc_sender: Option<Sender>,
ipc_sender: Option<AccessSender>,
}

impl<'a> Client<'a> {
pub fn from_payload_bytes(payload_bytes: &'a [u8], allocator: impl Allocator) -> Self {
let payload: Payload<'a> = wincode::deserialize_exact(payload_bytes).unwrap();

// `None` when the channel is already over, which happens when this
// process starts after the root target exited. Nothing is said
// about it: a detours DLL writing to the traced process's stderr
// corrupts whatever that process is printing.
// `None` when the channel is already closed — because the root target
// exited, the channel overflowed, or an earlier process aborted
// tracking. Nothing is said about it: a detours DLL writing to the
// traced process's stderr corrupts whatever that process is printing.
let ipc_sender = payload.channel_conf.sender(allocator);

Self { payload, payload_bytes, ipc_sender }
Expand Down
Loading
Loading