Skip to content

Commit

Permalink
feat(memory): removed guard pages
Browse files Browse the repository at this point in the history
Now guest memory does not have guard pages to each side of the
memory regions.

Initially guard pages were added as a defence mechanism to
prevent guest or firecracker from accessing guest memory outside
of allocated memory. Main concern was the possibility of a bug
in the device emulation, that can lead to the security issue.
As of right now firecracker creates guest memory backed by
memfd and utilizes different forms of verification and
other defence in depth mechanisms such as jailing.
Additionally guard pages do not provide a generic defence
mechanism.

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Oct 20, 2023
1 parent 54caed2 commit 71cf036
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 339 deletions.
12 changes: 6 additions & 6 deletions src/vmm/src/arch/x86_64/mptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ mod tests {
#[test]
fn bounds_check() {
let num_cpus = 4;
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(GuestAddress(MPTABLE_START), compute_mp_size(num_cpus))],
false,
)
Expand All @@ -318,7 +318,7 @@ mod tests {
#[test]
fn bounds_check_fails() {
let num_cpus = 4;
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(GuestAddress(MPTABLE_START), compute_mp_size(num_cpus) - 1)],
false,
)
Expand All @@ -330,7 +330,7 @@ mod tests {
#[test]
fn mpf_intel_checksum() {
let num_cpus = 1;
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(GuestAddress(MPTABLE_START), compute_mp_size(num_cpus))],
false,
)
Expand All @@ -346,7 +346,7 @@ mod tests {
#[test]
fn mpc_table_checksum() {
let num_cpus = 4;
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(GuestAddress(MPTABLE_START), compute_mp_size(num_cpus))],
false,
)
Expand All @@ -371,7 +371,7 @@ mod tests {

#[test]
fn cpu_entry_count() {
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(
GuestAddress(MPTABLE_START),
compute_mp_size(MAX_SUPPORTED_CPUS),
Expand Down Expand Up @@ -409,7 +409,7 @@ mod tests {
#[test]
fn cpu_entry_count_max() {
let cpus = MAX_SUPPORTED_CPUS + 1;
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
let mem = GuestMemoryMmap::from_raw_regions(
&[(GuestAddress(MPTABLE_START), compute_mp_size(cpus))],
false,
)
Expand Down
7 changes: 1 addition & 6 deletions src/vmm/src/arch/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ mod tests {
fn create_guest_mem(mem_size: Option<u64>) -> GuestMemoryMmap {
let page_size = 0x10000usize;
let mem_size = u64_to_usize(mem_size.unwrap_or(page_size as u64));
if mem_size % page_size == 0 {
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0), mem_size)], false).unwrap()
} else {
GuestMemoryMmap::from_raw_regions_unguarded(&[(GuestAddress(0), mem_size)], false)
.unwrap()
}
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0), mem_size)], false).unwrap()
}

fn read_u64(gm: &GuestMemoryMmap, offset: u64) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ pub mod tests {
}

fn create_guest_mem_at(at: GuestAddress, size: usize) -> GuestMemoryMmap {
GuestMemoryMmap::from_raw_regions_unguarded(&[(at, size)], false).unwrap()
GuestMemoryMmap::from_raw_regions(&[(at, size)], false).unwrap()
}

pub(crate) fn create_guest_mem_with_size(size: usize) -> GuestMemoryMmap {
Expand Down
3 changes: 1 addition & 2 deletions src/vmm/src/devices/virtio/balloon/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,7 @@ pub(crate) mod tests {
assert!(balloon.update_size(1).is_err());
// Switch the state to active.
balloon.device_state = DeviceState::Activated(
GuestMemoryMmap::from_raw_regions_unguarded(&[(GuestAddress(0x0), 0x1)], false)
.unwrap(),
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0x0), 0x1)], false).unwrap(),
);

assert_eq!(balloon.num_pages(), 0);
Expand Down
8 changes: 3 additions & 5 deletions src/vmm/src/devices/virtio/net/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,9 @@ pub mod test {
pub fn get_default() -> TestHelper<'a> {
let mut event_manager = EventManager::new().unwrap();
let mut net = default_net();
let mem = GuestMemoryMmap::from_raw_regions_unguarded(
&[(GuestAddress(0), MAX_BUFFER_SIZE)],
false,
)
.unwrap();
let mem =
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0), MAX_BUFFER_SIZE)], false)
.unwrap();
// transmute mem_ref lifetime to 'a
let mem_ref = unsafe { mem::transmute::<&GuestMemoryMmap, &'a GuestMemoryMmap>(&mem) };

Expand Down
5 changes: 2 additions & 3 deletions src/vmm/src/devices/virtio/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ macro_rules! check_metric_after_block {
/// Creates a [`GuestMemoryMmap`] with a single region of the given size starting at guest physical
/// address 0
pub fn single_region_mem(region_size: usize) -> GuestMemoryMmap {
GuestMemoryMmap::from_raw_regions_unguarded(&[(GuestAddress(0), region_size)], false).unwrap()
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0), region_size)], false).unwrap()
}

/// Creates a [`GuestMemoryMmap`] with a single region of size 65536 (= 0x10000 hex) starting at
Expand Down Expand Up @@ -331,8 +331,7 @@ pub(crate) mod test {
use crate::vstate::memory::{Address, GuestAddress, GuestMemoryExtension, GuestMemoryMmap};

pub fn create_virtio_mem() -> GuestMemoryMmap {
GuestMemoryMmap::from_raw_regions_unguarded(&[(GuestAddress(0), MAX_BUFFER_SIZE)], false)
.unwrap()
GuestMemoryMmap::from_raw_regions(&[(GuestAddress(0), MAX_BUFFER_SIZE)], false).unwrap()
}

/// Provides functionality necessary for testing a VirtIO device with
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/vsock/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ mod tests {
fn test_check_bounds_for_buffer_access_edge_cases() {
let mut test_ctx = TestContext::new();

test_ctx.mem = GuestMemoryMmap::from_raw_regions_unguarded(
test_ctx.mem = GuestMemoryMmap::from_raw_regions(
&[
(GuestAddress(0), 500),
(GuestAddress(500), 100),
Expand Down
Loading

0 comments on commit 71cf036

Please sign in to comment.