Skip to content

Commit 10a849b

Browse files
georgepisaltuberciuliviu
authored andcommitted
add seccomp tests for rust panic
Signed-off-by: George Pisaltu <[email protected]>
1 parent 552cf7d commit 10a849b

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,19 @@ def bin_seccomp_paths(test_session_root_path):
327327
'demo_malicious'
328328
)
329329
)
330+
demo_panic = os.path.normpath(
331+
os.path.join(
332+
release_binaries_path,
333+
'demo_panic'
334+
)
335+
)
330336

331337
yield {
332338
'demo_basic_jailer': demo_basic_jailer,
333339
'demo_advanced_jailer': demo_advanced_jailer,
334340
'demo_harmless': demo_harmless,
335-
'demo_malicious': demo_malicious
341+
'demo_malicious': demo_malicious,
342+
'demo_panic': demo_panic
336343
}
337344

338345

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
fn main() {
4+
unsafe {
5+
// Simulate a Firecracker panic by aborting.
6+
// The Firecracker build is configured with panic = "abort".
7+
unsafe { libc::abort() };
8+
}
9+
}

tests/integration_tests/security/demo_seccomp/src/bin/seccomp_rules/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
use seccomp::{allow_syscall, SyscallRuleSet};
3+
use seccomp::{allow_syscall, allow_syscall_if, SyscallRuleSet};
44

55
/// Returns a list of rules that allow syscalls required for running a rust program.
66
pub fn rust_required_rules() -> Vec<SyscallRuleSet> {
77
vec![
8-
allow_syscall(libc::SYS_sigaltstack),
9-
allow_syscall(libc::SYS_munmap),
108
allow_syscall(libc::SYS_exit_group),
9+
allow_syscall(libc::SYS_futex),
10+
allow_syscall(libc::SYS_munmap),
11+
allow_syscall(libc::SYS_rt_sigaction),
12+
allow_syscall(libc::SYS_rt_sigprocmask),
13+
allow_syscall(libc::SYS_sigaltstack),
14+
allow_syscall(libc::SYS_tkill),
1115
]
1216
}
1317

1418
/// Returns a list of rules that allow syscalls required for executing another program.
1519
pub fn jailer_required_rules() -> Vec<SyscallRuleSet> {
1620
vec![
17-
allow_syscall(libc::SYS_rt_sigprocmask),
18-
allow_syscall(libc::SYS_rt_sigaction),
1921
allow_syscall(libc::SYS_execve),
2022
allow_syscall(libc::SYS_mmap),
2123
allow_syscall(libc::SYS_mprotect),

tests/integration_tests/security/test_seccomp.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ def test_advanced_seccomp_malicious(bin_seccomp_paths):
7878
assert outcome.returncode == -31
7979

8080

81+
def test_advanced_seccomp_panic(bin_seccomp_paths):
82+
"""
83+
Test `demo_panic`.
84+
85+
Test that the advanced demo jailer allows the panic demo binary.
86+
"""
87+
# pylint: disable=redefined-outer-name
88+
# pylint: disable=subprocess-run-check
89+
# The fixture pattern causes a pylint false positive for that rule.
90+
91+
demo_advanced_jailer = bin_seccomp_paths['demo_advanced_jailer']
92+
demo_panic = bin_seccomp_paths['demo_panic']
93+
94+
assert os.path.exists(demo_advanced_jailer)
95+
assert os.path.exists(demo_panic)
96+
97+
outcome = utils.run_cmd([demo_advanced_jailer, demo_panic],
98+
no_shell=True,
99+
ignore_return_code=True)
100+
101+
# The demo harmless binary should have terminated gracefully.
102+
assert outcome.returncode == -6
103+
104+
81105
def test_seccomp_applies_to_all_threads(test_microvm_with_api):
82106
"""Test all Firecracker threads get default seccomp level 2."""
83107
test_microvm = test_microvm_with_api

0 commit comments

Comments
 (0)