Skip to content

Commit 0535fc4

Browse files
committed
Disable seccomp for musl target
Signed-off-by: James Sturtevant <[email protected]>
1 parent 5654465 commit 0535fc4

File tree

11 files changed

+27
-26
lines changed

11 files changed

+27
-26
lines changed

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, self.mgr.unwrap_mgr_mut())
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(all(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
@@ -644,7 +644,7 @@ mod tests {
644644

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

647-
#[cfg(feature = "seccomp")]
647+
#[cfg(seccomp)]
648648
match res {
649649
Ok(_) => panic!("Expected to fail due to seccomp violation"),
650650
Err(e) => match e {
@@ -653,15 +653,15 @@ mod tests {
653653
},
654654
}
655655

656-
#[cfg(not(feature = "seccomp"))]
656+
#[cfg(not(seccomp))]
657657
match res {
658658
Ok(_) => (),
659659
Err(e) => panic!("Expected to succeed without seccomp: {}", e),
660660
}
661661
}
662662

663663
// Second, run with allowing `SYS_getpid`
664-
#[cfg(feature = "seccomp")]
664+
#[cfg(seccomp)]
665665
{
666666
let mut usbox = UninitializedSandbox::new(
667667
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
@@ -738,7 +738,7 @@ mod tests {
738738
)
739739
.expect("Expected to call host function that returns i64");
740740

741-
if cfg!(feature = "seccomp") {
741+
if cfg!(seccomp) {
742742
// If seccomp is enabled, we expect the syscall to return EACCES, as setup by our seccomp filter
743743
assert_eq!(host_func_result, -libc::EACCES as i64);
744744
} else {
@@ -747,7 +747,7 @@ mod tests {
747747
}
748748
}
749749

750-
#[cfg(feature = "seccomp")]
750+
#[cfg(seccomp)]
751751
{
752752
// Now let's make sure if we register the `openat` syscall as an extra allowed syscall, it will succeed
753753
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
@@ -36,7 +36,7 @@ use crate::mem::shared_mem::ExclusiveSharedMemory;
3636
use crate::sandbox::SandboxConfiguration;
3737
use crate::{MultiUseSandbox, Result, new_error};
3838

39-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
39+
#[cfg(seccomp)]
4040
const EXTRA_ALLOWED_SYSCALLS_FOR_WRITER_FUNC: &[super::ExtraAllowedSyscall] = &[
4141
// Fuzzing fails without `mmap` being an allowed syscall on our seccomp filter.
4242
// All fuzzing does is call `PrintOutput` (which calls `HostPrint` ). Thing is, `println!`
@@ -325,7 +325,7 @@ impl UninitializedSandbox {
325325
///
326326
/// Unlike [`register`](Self::register), this variant allows specifying extra syscalls
327327
/// that will be permitted when the function handler runs.
328-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
328+
#[cfg(seccomp)]
329329
pub fn register_with_extra_allowed_syscalls<
330330
Args: ParameterTuple,
331331
Output: SupportedReturnType,
@@ -348,10 +348,10 @@ impl UninitializedSandbox {
348348
&mut self,
349349
print_func: impl Into<HostFunction<i32, (String,)>>,
350350
) -> Result<()> {
351-
#[cfg(not(all(target_os = "linux", feature = "seccomp")))]
351+
#[cfg(not(seccomp))]
352352
self.register("HostPrint", print_func)?;
353353

354-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
354+
#[cfg(seccomp)]
355355
self.register_with_extra_allowed_syscalls(
356356
"HostPrint",
357357
print_func,
@@ -365,13 +365,13 @@ impl UninitializedSandbox {
365365
///
366366
/// Like [`register_print`](Self::register_print), but allows specifying extra syscalls
367367
/// that will be permitted during function execution.
368-
#[cfg(all(feature = "seccomp", target_os = "linux"))]
368+
#[cfg(seccomp)]
369369
pub fn register_print_with_extra_allowed_syscalls(
370370
&mut self,
371371
print_func: impl Into<HostFunction<i32, (String,)>>,
372372
extra_allowed_syscalls: impl IntoIterator<Item = crate::sandbox::ExtraAllowedSyscall>,
373373
) -> Result<()> {
374-
#[cfg(all(target_os = "linux", feature = "seccomp"))]
374+
#[cfg(seccomp)]
375375
self.register_with_extra_allowed_syscalls(
376376
"HostPrint",
377377
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)