Skip to content

Commit 37bdf3d

Browse files
committed
Remove seccomp feature from hyperlight-host
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
1 parent 23b1511 commit 37bdf3d

File tree

14 files changed

+9
-537
lines changed

14 files changed

+9
-537
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_host/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ windows-version = "0.1"
7575
lazy_static = "1.4.0"
7676

7777
[target.'cfg(unix)'.dependencies]
78-
seccompiler = { version = "0.5.0", optional = true }
7978
kvm-bindings = { version = "0.14", features = ["fam-wrappers"], optional = true }
8079
kvm-ioctls = { version = "0.24", optional = true }
8180
mshv-bindings2 = { package="mshv-bindings", version = "=0.2.1", optional = true }
@@ -126,8 +125,7 @@ cfg_aliases = "0.2.1"
126125
built = { version = "0.8.0", optional = true, features = ["chrono", "git2"] }
127126

128127
[features]
129-
default = ["kvm", "mshv3", "seccomp", "build-metadata", "init-paging"]
130-
seccomp = ["dep:seccompiler"]
128+
default = ["kvm", "mshv3", "build-metadata", "init-paging"]
131129
function_call_metrics = []
132130
executable_heap = []
133131
# This feature enables printing of debug information to stdout in debug builds

src/hyperlight_host/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ fn main() -> Result<()> {
101101
// the other features they want.
102102
mshv2: { all(feature = "mshv2", target_os = "linux") },
103103
mshv3: { all(feature = "mshv3", not(feature="mshv2"), target_os = "linux") },
104-
seccomp: { all(feature = "seccomp", target_os = "linux", not(target_env = "musl")) },
105104
}
106105

107106
#[cfg(feature = "build-metadata")]

src/hyperlight_host/src/error.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ pub enum HyperlightError {
6969
#[error("Error converting CString {0:?}")]
7070
CStringConversionError(#[from] std::ffi::NulError),
7171

72-
/// A disallowed syscall was caught
73-
#[error("Seccomp filter trapped on disallowed syscall (check STDERR for offending syscall)")]
74-
#[cfg(seccomp)]
75-
DisallowedSyscall,
76-
7772
/// A generic error with a message
7873
#[error("{0}")]
7974
Error(String),
@@ -216,16 +211,6 @@ pub enum HyperlightError {
216211
#[error("Stack overflow detected")]
217212
StackOverflow(),
218213

219-
/// a backend error occurred with seccomp filters
220-
#[error("Backend Error with Seccomp Filter {0:?}")]
221-
#[cfg(seccomp)]
222-
SeccompFilterBackendError(#[from] seccompiler::BackendError),
223-
224-
/// an error occurred with seccomp filters
225-
#[error("Error with Seccomp Filter {0:?}")]
226-
#[cfg(seccomp)]
227-
SeccompFilterError(#[from] seccompiler::Error),
228-
229214
/// Tried to restore snapshot to a sandbox that is not the same as the one the snapshot was taken from
230215
#[error("Snapshot was taken from a different sandbox")]
231216
SnapshotSandboxMismatch,

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, Ret
2020

2121
use super::utils::for_each_tuple;
2222
use super::{ParameterTuple, ResultType, SupportedReturnType};
23+
use crate::sandbox::UninitializedSandbox;
2324
use crate::sandbox::host_funcs::FunctionEntry;
24-
use crate::sandbox::{ExtraAllowedSyscall, UninitializedSandbox};
2525
use crate::{Result, new_error};
2626

2727
/// A sandbox on which (primitive) host functions can be registered
@@ -33,15 +33,6 @@ pub trait Registerable {
3333
name: &str,
3434
hf: impl Into<HostFunction<Output, Args>>,
3535
) -> Result<()>;
36-
/// Register a primitive host function whose worker thread has
37-
/// extra permissive seccomp filters installed
38-
#[cfg(seccomp)]
39-
fn register_host_function_with_syscalls<Args: ParameterTuple, Output: SupportedReturnType>(
40-
&mut self,
41-
name: &str,
42-
hf: impl Into<HostFunction<Output, Args>>,
43-
eas: Vec<ExtraAllowedSyscall>,
44-
) -> Result<()>;
4536
}
4637
impl Registerable for UninitializedSandbox {
4738
fn register_host_function<Args: ParameterTuple, Output: SupportedReturnType>(
@@ -56,28 +47,6 @@ impl Registerable for UninitializedSandbox {
5647

5748
let entry = FunctionEntry {
5849
function: hf.into().into(),
59-
extra_allowed_syscalls: None,
60-
parameter_types: Args::TYPE,
61-
return_type: Output::TYPE,
62-
};
63-
64-
(*hfs).register_host_function(name.to_string(), entry, &mut self.mgr)
65-
}
66-
#[cfg(seccomp)]
67-
fn register_host_function_with_syscalls<Args: ParameterTuple, Output: SupportedReturnType>(
68-
&mut self,
69-
name: &str,
70-
hf: impl Into<HostFunction<Output, Args>>,
71-
eas: Vec<ExtraAllowedSyscall>,
72-
) -> Result<()> {
73-
let mut hfs = self
74-
.host_funcs
75-
.try_lock()
76-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?;
77-
78-
let entry = FunctionEntry {
79-
function: hf.into().into(),
80-
extra_allowed_syscalls: Some(eas),
8150
parameter_types: Args::TYPE,
8251
return_type: Output::TYPE,
8352
};
@@ -195,13 +164,11 @@ pub(crate) fn register_host_function<Args: ParameterTuple, Output: SupportedRetu
195164
func: impl Into<HostFunction<Output, Args>>,
196165
sandbox: &mut UninitializedSandbox,
197166
name: &str,
198-
extra_allowed_syscalls: Option<Vec<ExtraAllowedSyscall>>,
199167
) -> Result<()> {
200168
let func = func.into().into();
201169

202170
let entry = FunctionEntry {
203171
function: func,
204-
extra_allowed_syscalls: extra_allowed_syscalls.clone(),
205172
parameter_types: Args::TYPE,
206173
return_type: Output::TYPE,
207174
};

src/hyperlight_host/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ pub mod metrics;
7676
/// outside this file. Types from this module needed for public consumption are
7777
/// re-exported below.
7878
pub mod sandbox;
79-
#[cfg(seccomp)]
80-
pub(crate) mod seccomp;
8179
/// Signal handling for Linux
8280
#[cfg(target_os = "linux")]
8381
pub(crate) mod signal_handlers;

src/hyperlight_host/src/metrics/mod.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ mod tests {
133133
if #[cfg(feature = "function_call_metrics")] {
134134
use metrics::Label;
135135

136-
let expected_num_metrics = if cfg!(all(seccomp)) {
137-
3 // if seccomp enabled, the host call duration metric is emitted on a separate thread which this local recorder doesn't capture
138-
} else {
139-
4
140-
};
136+
let expected_num_metrics = 4;
141137

142138
// Verify that the histogram metrics are recorded correctly
143139
assert_eq!(snapshot.len(), expected_num_metrics);
@@ -185,25 +181,6 @@ mod tests {
185181
),
186182
"Histogram metric does not match expected value"
187183
);
188-
189-
if !cfg!(all(seccomp)) {
190-
// 4. Host call duration
191-
let histogram_key = CompositeKey::new(
192-
metrics_util::MetricKind::Histogram,
193-
Key::from_parts(
194-
METRIC_HOST_FUNC_DURATION,
195-
vec![Label::new("function_name", "HostPrint")],
196-
),
197-
);
198-
let histogram_value = &snapshot.get(&histogram_key).unwrap().2;
199-
assert!(
200-
matches!(
201-
histogram_value,
202-
metrics_util::debugging::DebugValue::Histogram(histogram) if histogram.len() == 1
203-
),
204-
"Histogram metric does not match expected value"
205-
);
206-
}
207184
} else {
208185
// Verify that the counter metrics are recorded correctly
209186
assert_eq!(snapshot.len(), 1);

src/hyperlight_host/src/sandbox/host_funcs.rs

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionD
2525
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
2626
use tracing::{Span, instrument};
2727

28-
use super::ExtraAllowedSyscall;
2928
use crate::HyperlightError::HostFunctionNotFound;
3029
use crate::func::host_functions::TypeErasedHostFunction;
3130
use crate::mem::mgr::SandboxMemoryManager;
@@ -58,7 +57,6 @@ impl From<&mut FunctionRegistry> for HostFunctionDetails {
5857

5958
pub struct FunctionEntry {
6059
pub function: TypeErasedHostFunction,
61-
pub extra_allowed_syscalls: Option<Vec<ExtraAllowedSyscall>>,
6260
pub parameter_types: &'static [ParameterType],
6361
pub return_type: ReturnType,
6462
}
@@ -119,18 +117,15 @@ impl FunctionRegistry {
119117
fn call_host_func_impl(&self, name: &str, args: Vec<ParameterValue>) -> Result<ReturnValue> {
120118
let FunctionEntry {
121119
function,
122-
extra_allowed_syscalls,
123120
parameter_types: _,
124121
return_type: _,
125122
} = self
126123
.functions_map
127124
.get(name)
128125
.ok_or_else(|| HostFunctionNotFound(name.to_string()))?;
129126

130-
// Create a new thread when seccomp is enabled on Linux
131-
maybe_with_seccomp(name, extra_allowed_syscalls.as_deref(), || {
132-
crate::metrics::maybe_time_and_emit_host_call(name, || function.call(args))
133-
})
127+
// Make the host function call
128+
crate::metrics::maybe_time_and_emit_host_call(name, || function.call(args))
134129
}
135130
}
136131

@@ -153,58 +148,3 @@ pub(super) fn default_writer_func(s: String) -> Result<i32> {
153148
}
154149
}
155150
}
156-
157-
#[cfg(seccomp)]
158-
fn maybe_with_seccomp<T: Send>(
159-
name: &str,
160-
syscalls: Option<&[ExtraAllowedSyscall]>,
161-
f: impl FnOnce() -> Result<T> + Send,
162-
) -> Result<T> {
163-
use std::thread;
164-
165-
use crate::seccomp::guest::get_seccomp_filter_for_host_function_worker_thread;
166-
167-
// Use a scoped thread so that we can pass around references without having to clone them.
168-
thread::scope(|s| {
169-
thread::Builder::new()
170-
.name(format!("Host Function Worker Thread for: {name:?}"))
171-
.spawn_scoped(s, move || {
172-
let seccomp_filter = get_seccomp_filter_for_host_function_worker_thread(syscalls)?;
173-
seccomp_filter
174-
.iter()
175-
.try_for_each(|filter| seccompiler::apply_filter(filter))?;
176-
177-
// We have a `catch_unwind` here because, if a disallowed syscall is issued,
178-
// we handle it by panicking. This is to avoid returning execution to the
179-
// offending host function—for two reasons: (1) if a host function is issuing
180-
// disallowed syscalls, it could be unsafe to return to, and (2) returning
181-
// execution after trapping the disallowed syscall can lead to UB (e.g., try
182-
// running a host function that attempts to sleep without `SYS_clock_nanosleep`,
183-
// you'll block the syscall but panic in the aftermath).
184-
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
185-
Ok(val) => val,
186-
Err(err) => {
187-
if let Some(crate::HyperlightError::DisallowedSyscall) =
188-
err.downcast_ref::<crate::HyperlightError>()
189-
{
190-
return Err(crate::HyperlightError::DisallowedSyscall);
191-
}
192-
193-
crate::log_then_return!("Host function {} panicked", name);
194-
}
195-
}
196-
})?
197-
.join()
198-
.map_err(|_| new_error!("Error joining thread executing host function"))?
199-
})
200-
}
201-
202-
#[cfg(not(seccomp))]
203-
fn maybe_with_seccomp<T: Send>(
204-
_name: &str,
205-
_syscalls: Option<&[ExtraAllowedSyscall]>,
206-
f: impl FnOnce() -> Result<T> + Send,
207-
) -> Result<T> {
208-
// No seccomp, just call the function
209-
f()
210-
}

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ use crate::mem::shared_mem::ExclusiveSharedMemory;
3535
use crate::sandbox::SandboxConfiguration;
3636
use crate::{MultiUseSandbox, Result, new_error};
3737

38-
#[cfg(seccomp)]
39-
const EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC: &[super::ExtraAllowedSyscall] = &[
40-
// Fuzzing fails without `mmap` being an allowed syscall on our seccomp filter.
41-
// All fuzzing does is call `PrintOutput` (which calls `HostPrint` ). Thing is, `println!`
42-
// is designed to be thread-safe in Rust and the std lib ensures this by using
43-
// buffered I/O, which I think relies on `mmap`. This gets surfaced in fuzzing with an
44-
// OOM error, which I think is happening because `println!` is not being able to allocate
45-
// more memory for its buffers for the fuzzer's huge inputs.
46-
libc::SYS_mmap,
47-
libc::SYS_brk,
48-
libc::SYS_mprotect,
49-
#[cfg(mshv)]
50-
libc::SYS_close,
51-
];
52-
5338
#[cfg(any(crashdump, gdb))]
5439
#[derive(Clone, Debug, Default)]
5540
pub(crate) struct SandboxRuntimeConfig {
@@ -304,25 +289,7 @@ impl UninitializedSandbox {
304289
name: impl AsRef<str>,
305290
host_func: impl Into<HostFunction<Output, Args>>,
306291
) -> Result<()> {
307-
register_host_function(host_func, self, name.as_ref(), None)
308-
}
309-
310-
/// Registers a host function with additional allowed syscalls during execution.
311-
///
312-
/// Unlike [`register`](Self::register), this variant allows specifying extra syscalls
313-
/// that will be permitted when the function handler runs.
314-
#[cfg(seccomp)]
315-
pub fn register_with_extra_allowed_syscalls<
316-
Args: ParameterTuple,
317-
Output: SupportedReturnType,
318-
>(
319-
&mut self,
320-
name: impl AsRef<str>,
321-
host_func: impl Into<HostFunction<Output, Args>>,
322-
extra_allowed_syscalls: impl IntoIterator<Item = crate::sandbox::ExtraAllowedSyscall>,
323-
) -> Result<()> {
324-
let extra_allowed_syscalls: Vec<_> = extra_allowed_syscalls.into_iter().collect();
325-
register_host_function(host_func, self, name.as_ref(), Some(extra_allowed_syscalls))
292+
register_host_function(host_func, self, name.as_ref())
326293
}
327294

328295
/// Registers the special "HostPrint" function for guest printing.
@@ -334,40 +301,7 @@ impl UninitializedSandbox {
334301
&mut self,
335302
print_func: impl Into<HostFunction<i32, (String,)>>,
336303
) -> Result<()> {
337-
#[cfg(not(seccomp))]
338-
self.register("HostPrint", print_func)?;
339-
340-
#[cfg(seccomp)]
341-
self.register_with_extra_allowed_syscalls(
342-
"HostPrint",
343-
print_func,
344-
EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC.iter().copied(),
345-
)?;
346-
347-
Ok(())
348-
}
349-
350-
/// Registers the "HostPrint" function with additional allowed syscalls.
351-
///
352-
/// Like [`register_print`](Self::register_print), but allows specifying extra syscalls
353-
/// that will be permitted during function execution.
354-
#[cfg(seccomp)]
355-
pub fn register_print_with_extra_allowed_syscalls(
356-
&mut self,
357-
print_func: impl Into<HostFunction<i32, (String,)>>,
358-
extra_allowed_syscalls: impl IntoIterator<Item = crate::sandbox::ExtraAllowedSyscall>,
359-
) -> Result<()> {
360-
#[cfg(seccomp)]
361-
self.register_with_extra_allowed_syscalls(
362-
"HostPrint",
363-
print_func,
364-
EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC
365-
.iter()
366-
.copied()
367-
.chain(extra_allowed_syscalls),
368-
)?;
369-
370-
Ok(())
304+
self.register("HostPrint", print_func)
371305
}
372306
}
373307
// Check to see if the current version of Windows is supported

0 commit comments

Comments
 (0)