Skip to content

Commit cea9cf5

Browse files
committed
vmm: label allowed syscalls as per architecture
libc syscalls are dependent on the architecture. Thus, "default_syscalls" is now a module that conditionally compiles allowed syscalls depending on target architecture. Signed-off-by: Diana Popa <[email protected]>
1 parent 8c6cd50 commit cea9cf5

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

vmm/src/default_syscalls/aarch64.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use seccomp::{Error, SeccompFilterContext};
5+
6+
pub const ALLOWED_SYSCALLS: &[i64] = &[];
7+
8+
pub fn default_context() -> Result<SeccompFilterContext, Error> {
9+
Ok(seccomp::SeccompFilterContext::new(
10+
vec![].into_iter().collect(),
11+
seccomp::SeccompAction::Trap,
12+
)
13+
.unwrap())
14+
}
15+
16+
pub fn set_seccomp_level(seccomp_level: u32) -> Result<(), Error> {
17+
Ok(())
18+
}

vmm/src/default_syscalls/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#[cfg(target_arch = "x86_64")]
5+
mod x86_64;
6+
7+
#[cfg(target_arch = "aarch64")]
8+
mod aarch64;
9+
10+
#[cfg(target_arch = "aarch64")]
11+
pub use self::aarch64::{default_context, set_seccomp_level, ALLOWED_SYSCALLS};
12+
#[cfg(target_arch = "x86_64")]
13+
pub use self::x86_64::{default_context, set_seccomp_level, ALLOWED_SYSCALLS};

vmm/src/default_syscalls.rs renamed to vmm/src/default_syscalls/x86_64.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
extern crate libc;
5-
extern crate sys_util;
6-
74
use seccomp::{
85
setup_seccomp, Error, SeccompAction, SeccompCmpOp, SeccompCondition, SeccompFilterContext,
96
SeccompLevel, SeccompRule, SECCOMP_LEVEL_ADVANCED, SECCOMP_LEVEL_BASIC, SECCOMP_LEVEL_NONE,
107
};
118

12-
/// List of allowed syscalls, necessary for Firecracker to function correctly.
9+
/// List of allowed syscalls necessary for correct functioning on x86_64 architectures.
10+
/// Taken from the musl repo (i.e arch/x86_64/bits/syscall.h).
1311
pub const ALLOWED_SYSCALLS: &[i64] = &[
1412
libc::SYS_accept,
1513
libc::SYS_clock_gettime,
@@ -38,17 +36,17 @@ pub const ALLOWED_SYSCALLS: &[i64] = &[
3836
libc::SYS_writev,
3937
];
4038

41-
// See /usr/include/x86_64-linux-gnu/sys/epoll.h
39+
// See include/uapi/linux/eventpoll.h in the kernel code.
4240
const EPOLL_CTL_ADD: u64 = 1;
4341
const EPOLL_CTL_DEL: u64 = 2;
4442

45-
// See /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h
43+
// See include/uapi/asm-generic/fcntl.h in the kernel code.
4644
const O_RDONLY: u64 = 0x00000000;
4745
const O_RDWR: u64 = 0x00000002;
4846
const O_NONBLOCK: u64 = 0x00004000;
4947
const O_CLOEXEC: u64 = 0x02000000;
5048

51-
// See /usr/include/linux/futex.h
49+
// See include/uapi/linux/futex.h in the kernel code.
5250
const FUTEX_WAIT: u64 = 0;
5351
const FUTEX_WAKE: u64 = 1;
5452
const FUTEX_REQUEUE: u64 = 3;
@@ -57,14 +55,14 @@ const FUTEX_WAIT_PRIVATE: u64 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG;
5755
const FUTEX_WAKE_PRIVATE: u64 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
5856
const FUTEX_REQUEUE_PRIVATE: u64 = FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG;
5957

60-
// See /usr/include/asm-generic/ioctls.h
58+
// See include/uapi/asm-generic/ioctls.h in the kernel code.
6159
const TCGETS: u64 = 0x5401;
6260
const TCSETS: u64 = 0x5402;
6361
const TIOCGWINSZ: u64 = 0x5413;
6462
const FIOCLEX: u64 = 0x5451;
6563
const FIONBIO: u64 = 0x5421;
6664

67-
// See /usr/include/linux/kvm.h
65+
// See include/uapi/linux/if_tun.h in the kernel code.
6866
const KVM_GET_API_VERSION: u64 = 0xae00;
6967
const KVM_CREATE_VM: u64 = 0xae01;
7068
const KVM_CHECK_EXTENSION: u64 = 0xae03;
@@ -88,15 +86,17 @@ const KVM_GET_SREGS: u64 = 0x8138ae83;
8886
const KVM_GET_LAPIC: u64 = 0x8400ae8e;
8987
const KVM_GET_SUPPORTED_CPUID: u64 = 0xc008ae05;
9088

91-
// See /usr/include/linux/if_tun.h
89+
// See include/uapi/linux/if_tun.h in the kernel code.
9290
const TUNSETIFF: u64 = 0x400454ca;
9391
const TUNSETOFFLOAD: u64 = 0x400454d0;
9492
const TUNSETVNETHDRSZ: u64 = 0x400454d8;
9593

96-
// See /usr/include/asm-generic/mman-common.h and /usr/include/asm-generic/mman.h
94+
// See include/uapi/asm-generic/mman-common.h in the kernel code.
9795
const PROT_NONE: u64 = 0x0;
9896
const PROT_READ: u64 = 0x1;
9997
const PROT_WRITE: u64 = 0x2;
98+
99+
// See include/uapi/asm-generic/mman.h in the kernel code.
100100
const MAP_SHARED: u64 = 0x01;
101101
const MAP_PRIVATE: u64 = 0x02;
102102
const MAP_ANONYMOUS: u64 = 0x20;
@@ -529,7 +529,7 @@ pub fn default_context() -> Result<SeccompFilterContext, Error> {
529529
vec![SeccompCondition::new(
530530
1,
531531
SeccompCmpOp::Eq,
532-
sys_util::validate_signal_num(super::VCPU_RTSIG_OFFSET, true)
532+
sys_util::validate_signal_num(super::super::VCPU_RTSIG_OFFSET, true)
533533
.map_err(|_| Error::InvalidArgumentNumber)?
534534
as u64,
535535
)?],

vmm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ use vmm_config::net::{NetworkInterfaceConfig, NetworkInterfaceConfigs, NetworkIn
8686
use vmm_config::vsock::{VsockDeviceConfig, VsockDeviceConfigs, VsockError};
8787
use vstate::{Vcpu, Vm};
8888

89+
const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0";
8990
const MAGIC_IOPORT_SIGNAL_GUEST_BOOT_COMPLETE: u16 = 0x03f0;
9091
const MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE: u8 = 123;
91-
92-
const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0";
9392
const VCPU_RTSIG_OFFSET: i32 = 0;
9493
const WRITE_METRICS_PERIOD_SECONDS: u64 = 60;
94+
9595
static START_INSTANCE_REQUEST_TS: AtomicUsize = ATOMIC_USIZE_INIT;
9696
static START_INSTANCE_REQUEST_CPU_TS: AtomicUsize = ATOMIC_USIZE_INIT;
9797

0 commit comments

Comments
 (0)