Skip to content

Commit 0b48c00

Browse files
committed
Disable seccomp for musl target
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 3e45ca5 commit 0b48c00

11 files changed

Lines changed: 27 additions & 26 deletions

File tree

src/hyperlight_host/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ 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")) },
104105
}
105106

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

src/hyperlight_host/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum HyperlightError {
7171

7272
/// A disallowed syscall was caught
7373
#[error("Seccomp filter trapped on disallowed syscall (check STDERR for offending syscall)")]
74-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
74+
#[cfg(seccomp)]
7575
DisallowedSyscall,
7676

7777
/// A generic error with a message
@@ -218,12 +218,12 @@ pub enum HyperlightError {
218218

219219
/// a backend error occurred with seccomp filters
220220
#[error("Backend Error with Seccomp Filter {0:?}")]
221-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
221+
#[cfg(seccomp)]
222222
SeccompFilterBackendError(#[from] seccompiler::BackendError),
223223

224224
/// an error occurred with seccomp filters
225225
#[error("Error with Seccomp Filter {0:?}")]
226-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
226+
#[cfg(seccomp)]
227227
SeccompFilterError(#[from] seccompiler::Error),
228228

229229
/// Tried to restore snapshot to a sandbox that is not the same as the one the snapshot was taken from

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait Registerable {
3535
) -> Result<()>;
3636
/// Register a primitive host function whose worker thread has
3737
/// extra permissive seccomp filters installed
38-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
38+
#[cfg(seccomp)]
3939
fn register_host_function_with_syscalls<Args: ParameterTuple, Output: SupportedReturnType>(
4040
&mut self,
4141
name: &str,
@@ -63,7 +63,7 @@ impl Registerable for UninitializedSandbox {
6363

6464
(*hfs).register_host_function(name.to_string(), entry, &mut self.mgr)
6565
}
66-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
66+
#[cfg(seccomp)]
6767
fn register_host_function_with_syscalls<Args: ParameterTuple, Output: SupportedReturnType>(
6868
&mut self,
6969
name: &str,

src/hyperlight_host/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ 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(all(feature = "seccomp", target_os = "linux"))]
79+
#[cfg(seccomp)]
8080
pub(crate) mod seccomp;
8181
/// Signal handling for Linux
8282
#[cfg(target_os = "linux")]

src/hyperlight_host/src/metrics/mod.rs

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

136-
let expected_num_metrics = if cfg!(all(feature = "seccomp", target_os = "linux")) {
136+
let expected_num_metrics = if cfg!(all(seccomp)) {
137137
3 // if seccomp enabled, the host call duration metric is emitted on a separate thread which this local recorder doesn't capture
138138
} else {
139139
4
@@ -186,7 +186,7 @@ mod tests {
186186
"Histogram metric does not match expected value"
187187
);
188188

189-
if !cfg!(all(feature = "seccomp", target_os = "linux")) {
189+
if !cfg!(all(seccomp)) {
190190
// 4. Host call duration
191191
let histogram_key = CompositeKey::new(
192192
metrics_util::MetricKind::Histogram,

src/hyperlight_host/src/sandbox/host_funcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub(super) fn default_writer_func(s: String) -> Result<i32> {
154154
}
155155
}
156156

157-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
157+
#[cfg(seccomp)]
158158
fn maybe_with_seccomp<T: Send>(
159159
name: &str,
160160
syscalls: Option<&[ExtraAllowedSyscall]>,
@@ -199,7 +199,7 @@ fn maybe_with_seccomp<T: Send>(
199199
})
200200
}
201201

202-
#[cfg(not(all(feature = "seccomp", target_os = "linux")))]
202+
#[cfg(not(seccomp))]
203203
fn maybe_with_seccomp<T: Send>(
204204
_name: &str,
205205
_syscalls: Option<&[ExtraAllowedSyscall]>,

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ mod tests {
625625

626626
let res: Result<u64> = sbox.call("ViolateSeccompFilters", ());
627627

628-
#[cfg(feature = "seccomp")]
628+
#[cfg(seccomp)]
629629
match res {
630630
Ok(_) => panic!("Expected to fail due to seccomp violation"),
631631
Err(e) => match e {
@@ -634,15 +634,15 @@ mod tests {
634634
},
635635
}
636636

637-
#[cfg(not(feature = "seccomp"))]
637+
#[cfg(not(seccomp))]
638638
match res {
639639
Ok(_) => (),
640640
Err(e) => panic!("Expected to succeed without seccomp: {}", e),
641641
}
642642
}
643643

644644
// Second, run with allowing `SYS_getpid`
645-
#[cfg(feature = "seccomp")]
645+
#[cfg(seccomp)]
646646
{
647647
let mut usbox = UninitializedSandbox::new(
648648
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
@@ -719,7 +719,7 @@ mod tests {
719719
)
720720
.expect("Expected to call host function that returns i64");
721721

722-
if cfg!(feature = "seccomp") {
722+
if cfg!(seccomp) {
723723
// If seccomp is enabled, we expect the syscall to return EACCES, as setup by our seccomp filter
724724
assert_eq!(host_func_result, -libc::EACCES as i64);
725725
} else {
@@ -728,7 +728,7 @@ mod tests {
728728
}
729729
}
730730

731-
#[cfg(feature = "seccomp")]
731+
#[cfg(seccomp)]
732732
{
733733
// Now let's make sure if we register the `openat` syscall as an extra allowed syscall, it will succeed
734734
let mut ubox = UninitializedSandbox::new(

src/hyperlight_host/src/sandbox/uninitialized.rs

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

38-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
38+
#[cfg(seccomp)]
3939
const EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC: &[super::ExtraAllowedSyscall] = &[
4040
// Fuzzing fails without `mmap` being an allowed syscall on our seccomp filter.
4141
// All fuzzing does is call `PrintOutput` (which calls `HostPrint` ). Thing is, `println!`
@@ -311,7 +311,7 @@ impl UninitializedSandbox {
311311
///
312312
/// Unlike [`register`](Self::register), this variant allows specifying extra syscalls
313313
/// that will be permitted when the function handler runs.
314-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
314+
#[cfg(seccomp)]
315315
pub fn register_with_extra_allowed_syscalls<
316316
Args: ParameterTuple,
317317
Output: SupportedReturnType,
@@ -334,10 +334,10 @@ impl UninitializedSandbox {
334334
&mut self,
335335
print_func: impl Into<HostFunction<i32, (String,)>>,
336336
) -> Result<()> {
337-
#[cfg(not(all(target_os = "linux", feature = "seccomp")))]
337+
#[cfg(not(seccomp))]
338338
self.register("HostPrint", print_func)?;
339339

340-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
340+
#[cfg(seccomp)]
341341
self.register_with_extra_allowed_syscalls(
342342
"HostPrint",
343343
print_func,
@@ -351,13 +351,13 @@ impl UninitializedSandbox {
351351
///
352352
/// Like [`register_print`](Self::register_print), but allows specifying extra syscalls
353353
/// that will be permitted during function execution.
354-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
354+
#[cfg(seccomp)]
355355
pub fn register_print_with_extra_allowed_syscalls(
356356
&mut self,
357357
print_func: impl Into<HostFunction<i32, (String,)>>,
358358
extra_allowed_syscalls: impl IntoIterator<Item = crate::sandbox::ExtraAllowedSyscall>,
359359
) -> Result<()> {
360-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
360+
#[cfg(seccomp)]
361361
self.register_with_extra_allowed_syscalls(
362362
"HostPrint",
363363
print_func,

src/hyperlight_host/src/signal_handlers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use libc::c_int;
1818

1919
use crate::sandbox::SandboxConfiguration;
2020

21-
#[cfg(feature = "seccomp")]
21+
#[cfg(seccomp)]
2222
pub mod sigsys_signal_handler;
2323

2424
pub(crate) fn setup_signal_handlers(config: &SandboxConfiguration) -> crate::Result<()> {
@@ -27,7 +27,7 @@ pub(crate) fn setup_signal_handlers(config: &SandboxConfiguration) -> crate::Res
2727
// Anything that performs memory allocations, locks, and others are non-async-signal-safe.
2828
// Hyperlight signal handlers are all designed to be async-signal-safe, so this function
2929
// should be safe to call.
30-
#[cfg(feature = "seccomp")]
30+
#[cfg(seccomp)]
3131
{
3232
use std::sync::Once;
3333

src/hyperlight_host/src/signal_handlers/sigsys_signal_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg(feature = "seccomp")]
17+
#[cfg(seccomp)]
1818
pub(super) extern "C" fn handle_sigsys(
1919
signal: i32,
2020
info: *mut libc::siginfo_t,

0 commit comments

Comments
 (0)