Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to detect a tainted instance #4220

Merged
merged 23 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1e5d839
Removed the unsafe code used by the selector
john-sharratt Sep 10, 2023
831fa2d
Fixed some potential race conditions on the normal polling
john-sharratt Sep 10, 2023
cdb257a
Removed a debug step that was added earlier
john-sharratt Sep 10, 2023
bd5b482
Fixed a warning
john-sharratt Sep 10, 2023
6ed75f0
Implemented some polling methods for read_ready and write_ready
john-sharratt Sep 10, 2023
7b1443f
Cleaned some leftover code
john-sharratt Sep 10, 2023
916f36f
Fixed the connectivity issues, these were as follows:
john-sharratt Sep 11, 2023
e8f8982
Updated lock file
john-sharratt Sep 12, 2023
6a14fff
Updated lock file
john-sharratt Sep 12, 2023
e517a1a
Went backwards on some dependencies which are causing issues with the…
john-sharratt Sep 12, 2023
ba9e62b
- Added more methods to the interest handler for expanded functionality
john-sharratt Sep 12, 2023
0b68b2c
Linting error and windows build fixes
john-sharratt Sep 12, 2023
578d1b3
Removed the static selector
john-sharratt Sep 12, 2023
e07baee
Updated the lock file
john-sharratt Sep 12, 2023
b998eb1
Re-enabled socket option DONTROUTE, issue was in wasix-libc
ptitSeb Sep 14, 2023
fe0f7be
Added a missing check for waiting backlog
john-sharratt Sep 16, 2023
d25c870
Added fixes for the listeners which were erroring out incorrectly
john-sharratt Sep 16, 2023
ece9ce9
Merge branch 'fixes-for-sockets' of github.com:wasmerio/wasmer into f…
john-sharratt Sep 16, 2023
dc5309d
Added some extra error handling
john-sharratt Sep 17, 2023
7f640e8
Added a tainting callback so that crippled instances can be detected
john-sharratt Sep 17, 2023
96b5308
Merge remote-tracking branch 'origin/master' into tainting
theduke Sep 18, 2023
53065d1
Merge branch 'master' into tainting
john-sharratt Mar 11, 2024
9ddbb2a
Merge branch 'master' into tainting
theduke Mar 12, 2024
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
19 changes: 15 additions & 4 deletions lib/wasix/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use std::{pin::Pin, sync::Arc};

use crate::{
os::task::{thread::WasiThreadRunGuard, TaskJoinHandle},
runtime::task_manager::{
TaskWasm, TaskWasmRecycle, TaskWasmRecycleProperties, TaskWasmRunProperties,
runtime::{
task_manager::{
TaskWasm, TaskWasmRecycle, TaskWasmRecycleProperties, TaskWasmRunProperties,
},
TaintReason,
},
syscalls::rewind_ext,
RewindState, SpawnError, WasiError, WasiRuntimeError,
Expand Down Expand Up @@ -188,6 +191,7 @@ fn call_module(
let pid = env.pid();
let tasks = env.tasks().clone();
handle.thread.set_status_running();
let runtime = env.runtime.clone();

// If we need to rewind then do so
if let Some((rewind_state, rewind_result)) = rewind_state {
Expand Down Expand Up @@ -237,7 +241,10 @@ fn call_module(
if let Err(err) = call_ret {
match err.downcast::<WasiError>() {
Ok(WasiError::Exit(code)) if code.is_success() => Ok(Errno::Success),
Ok(err @ WasiError::Exit(_)) => Err(err.into()),
Ok(WasiError::Exit(code)) => {
runtime.on_taint(TaintReason::NonZeroExitCode(code));
Err(WasiError::Exit(code).into())
}
Ok(WasiError::DeepSleep(deep)) => {
// Create the callback that will be invoked when the thread respawns after a deep sleep
let rewind = deep.rewind;
Expand All @@ -264,9 +271,13 @@ fn call_module(
}
Ok(WasiError::UnknownWasiVersion) => {
debug!("failed as wasi version is unknown",);
runtime.on_taint(TaintReason::UnknownWasiVersion);
Ok(Errno::Noexec)
}
Err(err) => Err(WasiRuntimeError::from(err)),
Err(err) => {
runtime.on_taint(TaintReason::RuntimeError(err.clone()));
Err(WasiRuntimeError::from(err))
}
}
} else {
Ok(Errno::Success)
Expand Down
14 changes: 13 additions & 1 deletion lib/wasix/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use std::{
use derivative::Derivative;
use futures::future::BoxFuture;
use virtual_net::{DynVirtualNetworking, VirtualNetworking};
use wasmer::Module;
use wasmer::{Module, RuntimeError};
use wasmer_wasix_types::wasi::ExitCode;

#[cfg(feature = "journal")]
use crate::journal::DynJournal;
Expand All @@ -33,6 +34,13 @@ use crate::{
WasiTtyState,
};

#[derive(Clone)]
pub enum TaintReason {
UnknownWasiVersion,
NonZeroExitCode(ExitCode),
RuntimeError(RuntimeError),
}

/// Runtime components used when running WebAssembly programs.
///
/// Think of this as the "System" in "WebAssembly Systems Interface".
Expand Down Expand Up @@ -109,6 +117,10 @@ where
InlineWaker::block_on(self.load_module(wasm))
}

/// Callback thats invokes whenever the instance is tainted, tainting can occur
/// for multiple reasons however the most common is a panic within the process
fn on_taint(&self, _reason: TaintReason) {}

/// The list of journals which will be used to restore the state of the
/// runtime at a particular point in time
#[cfg(feature = "journal")]
Expand Down
14 changes: 13 additions & 1 deletion lib/wasix/src/syscalls/wasix/thread_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::journal::JournalEffector;
use crate::{
capture_instance_snapshot,
os::task::thread::WasiMemoryLayout,
runtime::task_manager::{TaskWasm, TaskWasmRunProperties},
runtime::{
task_manager::{TaskWasm, TaskWasmRunProperties},
TaintReason,
},
syscalls::*,
WasiThreadHandle,
};
Expand Down Expand Up @@ -177,6 +180,9 @@ fn call_module<M: MemorySize>(
ret = if code.is_success() {
Errno::Success
} else {
env.data(&store)
.runtime
.on_taint(TaintReason::NonZeroExitCode(code));
Errno::Noexec
};
}
Expand All @@ -186,10 +192,16 @@ fn call_module<M: MemorySize>(
}
Ok(WasiError::UnknownWasiVersion) => {
debug!("failed as wasi version is unknown",);
env.data(&store)
.runtime
.on_taint(TaintReason::UnknownWasiVersion);
ret = Errno::Noexec;
}
Err(err) => {
debug!("failed with runtime error: {}", err);
env.data(&store)
.runtime
.on_taint(TaintReason::RuntimeError(err));
ret = Errno::Noexec;
}
}
Expand Down
Loading