Skip to content

Commit 0d23c87

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

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

vmm/src/default_syscalls/aarch64.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+
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+
).unwrap())
13+
}

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, ALLOWED_SYSCALLS};
12+
#[cfg(target_arch = "x86_64")]
13+
pub use self::x86_64::{default_context, ALLOWED_SYSCALLS};

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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-
64
use seccomp::{
75
Error, SeccompAction, SeccompCmpOp, SeccompCondition, SeccompFilterContext, SeccompRule,
86
};
97

10-
/// List of allowed syscalls, necessary for Firecracker to function correctly.
8+
/// List of allowed syscalls necessary for correct functioning on x86_64 architectures.
9+
/// Taken from the musl repo (i.e arch/x86_64/bits/syscall.h).
1110
pub const ALLOWED_SYSCALLS: &[i64] = &[
1211
libc::SYS_read,
1312
libc::SYS_write,
@@ -52,11 +51,11 @@ pub const ALLOWED_SYSCALLS: &[i64] = &[
5251
libc::SYS_getrandom,
5352
];
5453

55-
// See /usr/include/x86_64-linux-gnu/sys/epoll.h
54+
// See include/uapi/linux/eventpoll.h in the kernel code.
5655
const EPOLL_CTL_ADD: u64 = 1;
5756
const EPOLL_CTL_DEL: u64 = 2;
5857

59-
// See /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h
58+
// See include/uapi/asm-generic/fcntl.h in the kernel code.
6059
const O_RDONLY: u64 = 0x00000000;
6160
const O_RDWR: u64 = 0x00000002;
6261
const O_NONBLOCK: u64 = 0x00004000;
@@ -66,7 +65,7 @@ const F_SETFD: u64 = 2;
6665
const F_SETFL: u64 = 4;
6766
const FD_CLOEXEC: u64 = 1;
6867

69-
// See /usr/include/linux/futex.h
68+
// See include/uapi/linux/futex.h in the kernel code.
7069
const FUTEX_WAIT: u64 = 0;
7170
const FUTEX_WAKE: u64 = 1;
7271
const FUTEX_REQUEUE: u64 = 3;
@@ -75,14 +74,14 @@ const FUTEX_WAIT_PRIVATE: u64 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG;
7574
const FUTEX_WAKE_PRIVATE: u64 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
7675
const FUTEX_REQUEUE_PRIVATE: u64 = FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG;
7776

78-
// See /usr/include/asm-generic/ioctls.h
77+
// See include/uapi/asm-generic/ioctls.h in the kernel code.
7978
const TCGETS: u64 = 0x5401;
8079
const TCSETS: u64 = 0x5402;
8180
const TIOCGWINSZ: u64 = 0x5413;
8281
const FIOCLEX: u64 = 0x5451;
8382
const FIONBIO: u64 = 0x5421;
8483

85-
// See /usr/include/linux/kvm.h
84+
// See include/uapi/linux/if_tun.h in the kernel code.
8685
const KVM_GET_API_VERSION: u64 = 0xae00;
8786
const KVM_CREATE_VM: u64 = 0xae01;
8887
const KVM_CHECK_EXTENSION: u64 = 0xae03;
@@ -105,21 +104,23 @@ const KVM_GET_SREGS: u64 = 0x8138ae83;
105104
const KVM_GET_LAPIC: u64 = 0x8400ae8e;
106105
const KVM_GET_SUPPORTED_CPUID: u64 = 0xc008ae05;
107106

108-
// See /usr/include/linux/if_tun.h
107+
// See include/uapi/linux/if_tun.h in the kernel code.
109108
const TUNSETIFF: u64 = 0x400454ca;
110109
const TUNSETOFFLOAD: u64 = 0x400454d0;
111110
const TUNSETVNETHDRSZ: u64 = 0x400454d8;
112111

113-
// See /usr/include/asm-generic/mman-common.h and /usr/include/asm-generic/mman.h
112+
// See include/uapi/asm-generic/mman-common.h in the kernel code.
114113
const PROT_NONE: u64 = 0x0;
115114
const PROT_READ: u64 = 0x1;
116115
const PROT_WRITE: u64 = 0x2;
116+
117+
// See include/uapi/asm-generic/mman.h in the kernel code.
117118
const MAP_SHARED: u64 = 0x01;
118119
const MAP_PRIVATE: u64 = 0x02;
119120
const MAP_ANONYMOUS: u64 = 0x20;
120121
const MAP_NORESERVE: u64 = 0x4000;
121122

122-
// See /usr/include/x86_64-linux-gnu/bits/socket.h
123+
// See include/linux/socket.h in the kernel code.
123124
const PF_LOCAL: u64 = 1;
124125

125126
/// The default context containing the white listed syscall rules required by `Firecracker` to

vmm/src/lib.rs

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

88+
const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0";
8889
const MAGIC_IOPORT_SIGNAL_GUEST_BOOT_COMPLETE: u16 = 0x03f0;
8990
const MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE: u8 = 123;
90-
91-
const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0";
9291
const VCPU_RTSIG_OFFSET: i32 = 0;
9392
const WRITE_METRICS_PERIOD_SECONDS: u64 = 60;
93+
9494
static START_INSTANCE_REQUEST_TS: AtomicUsize = ATOMIC_USIZE_INIT;
9595
static START_INSTANCE_REQUEST_CPU_TS: AtomicUsize = ATOMIC_USIZE_INIT;
9696

0 commit comments

Comments
 (0)