Skip to content

Commit 255b591

Browse files
committed
Progress on page allocator verification
Signed-off-by: Lennard Gäher <[email protected]>
1 parent b831232 commit 255b591

File tree

65 files changed

+3008
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3008
-483
lines changed

confidential-vms/linux_vm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LINUX_VM_ROOTFS_SOURCE_DIR ?= $(CONFIDENTIAL_VMS_LINUX_SOURCE_DIR)/hypervisor_
1414
LINUX_VM_BUILDROOT_SOURCE_DIR ?= $(CONFIDENTIAL_VMS_LINUX_SOURCE_DIR)/../../hypervisor/buildroot
1515
LINUX_VM_BUILDROOT_WORK_DIR ?= $(CONFIDENTIAL_VMS_LINUX_WORK_DIR)/buildroot
1616
LINUX_VM_BUILDROOT_ROOTFS ?= $(LINUX_VM_BUILDROOT_WORK_DIR)/images/rootfs.ext2
17-
LINUX_VM_BUILDROOT_ROOTFS_SIZE ?= "256M"
17+
LINUX_VM_BUILDROOT_ROOTFS_SIZE ?= "128M"
1818
LINUX_VM_OVERLAY_SOURCE_DIR ?= $(CONFIDENTIAL_VMS_LINUX_SOURCE_DIR)/overlay
1919
LINUX_VM_OVERLAY_WORK_DIR ?= $(CONFIDENTIAL_VMS_LINUX_WORK_DIR)/overlay
2020
LINUX_VM_OVERLAY_WORK_ROOT_DIR ?= $(LINUX_VM_OVERLAY_WORK_DIR)/root

confidential-vms/linux_vm/configurations/qemu_riscv64_virt_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BR2_TARGET_ROOTFS_EXT2=y
3434
BR2_TARGET_ROOTFS_EXT2_2=n
3535
BR2_TARGET_ROOTFS_EXT2_3=n
3636
BR2_TARGET_ROOTFS_EXT2_4=y
37-
BR2_TARGET_ROOTFS_EXT2_SIZE="5G"
37+
BR2_TARGET_ROOTFS_EXT2_SIZE="1G"
3838

3939
# Kernel
4040
BR2_LINUX_KERNEL=y

hypervisor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BUILDROOT_SOURCE_DIR ?= $(MAKEFILE_SOURCE_DIR)/buildroot
1414
HYPERVISOR_BUILDROOT_CONFIG_DIR ?= $(HYPERVISOR_CONFIGURATION_DIR)/qemu_riscv64_virt_defconfig
1515
HYPERVISOR_LINUX_CONFIG ?= $(HYPERVISOR_CONFIGURATION_DIR)/linux64-defconfig
1616
HYPERVISOR_BUILDROOT_OVERRIDE_DIR ?= $(HYPERVISOR_CONFIGURATION_DIR)/package_override.dev
17-
HYPERVISOR_ROOTFS_SIZE ?= "1G"
17+
HYPERVISOR_ROOTFS_SIZE ?= "512M"
1818
HYPERVISOR_OVERLAY_DIR ?= $(HYPERVISOR_WORK_DIR)/overlay
1919
HYPERVISOR_OVERLAY_ROOT_DIR ?= $(HYPERVISOR_OVERLAY_DIR)/root
2020
HYPERVISOR_PATCHES_DIR ?= $(MAKEFILE_SOURCE_DIR)/patches

security-monitor/src/core/architecture/riscv/mmu/page_size.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
#[repr(u8)]
99
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
1010
#[rr::refined_by("page_size")]
11+
// PEq
12+
#[rr::derive_instantiate("PEq" := "λ a b, bool_decide (a = b)")]
13+
// Eq
14+
#[rr::derive_instantiate("PEq_refl" := #proof "intros ??; solve_goal")]
15+
#[rr::derive_instantiate("PEq_sym" := #proof "intros ???; solve_goal")]
16+
#[rr::derive_instantiate("PEq_trans" := #proof "intros ????; solve_goal")]
17+
// POrd
18+
#[rr::derive_instantiate("POrd" := "λ a b, Some (page_size_cmp a b)")]
19+
#[rr::derive_instantiate("POrd_eq_cons" := #proof "intros ? [] []; simpl; done")]
20+
// Ord
21+
#[rr::derive_instantiate("Ord" := "page_size_cmp")]
22+
#[rr::derive_instantiate("Ord_POrd" := #proof "intros ???; solve_goal")]
23+
#[rr::derive_instantiate("Ord_lt_trans" := #proof "intros ????; solve_goal")]
24+
#[rr::derive_instantiate("Ord_eq_trans" := #proof "intros ????; solve_goal")]
25+
#[rr::derive_instantiate("Ord_gt_trans" := #proof "intros ????; solve_goal")]
26+
#[rr::derive_instantiate("Ord_leibniz" := #proof "intros ? [] []; simpl; done")]
27+
#[rr::derive_instantiate("Ord_antisym" := #proof "intros ???; solve_goal")]
1128
pub enum PageSize {
1229
#[rr::pattern("Size4KiB")]
1330
Size4KiB,

security-monitor/src/core/memory_layout/confidential_memory_address.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pointers_utility::{ptr_byte_add_mut, ptr_byte_offset};
66

77
/// The wrapper over a raw pointer that is guaranteed to be an address located in the confidential memory region.
88
#[repr(transparent)]
9-
#[derive(Debug, PartialEq)]
9+
#[derive(Debug, PartialEq, Clone, Copy)]
1010
/// Model: The memory address is represented by the location in memory.
1111
#[rr::refined_by("l" : "loc")]
1212
/// We require the ghost state for the global memory layout to be available.
@@ -70,12 +70,12 @@ impl ConfidentialMemoryAddress {
7070
/// Precondition: The offset address is in the given range.
7171
#[rr::requires("self.2 + offset_in_bytes < upper_bound.2")]
7272
/// Precondition: The maximum (and thus the offset address) is in the confidential memory range.
73-
#[rr::requires("upper_bound.2 < MEMORY_CONFIG.(conf_end).2")]
73+
#[rr::requires("upper_bound.2 MEMORY_CONFIG.(conf_end).2")]
7474
/// Postcondition: The offset pointer is in the confidential memory range.
7575
#[rr::ensures("ret = self +ₗ offset_in_bytes")]
7676
pub fn add(&self, offset_in_bytes: usize, upper_bound: *const usize) -> Result<ConfidentialMemoryAddress, Error> {
77-
let pointer = ptr_byte_add_mut(self.0, offset_in_bytes, upper_bound).map_err(|_| Error::AddressNotInConfidentialMemory())?;
78-
Ok(ConfidentialMemoryAddress(pointer))
77+
let pointer = ptr_byte_add_mut(self.0, offset_in_bytes, upper_bound).map_err(#[rr::verify] |_| Error::AddressNotInConfidentialMemory())?;
78+
Ok(Self::new(pointer))
7979
}
8080

8181
/// Reads usize-sized sequence of bytes from the confidential memory region.

security-monitor/src/core/memory_layout/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ impl MemoryLayout {
149149

150150
/// Offsets an address in the confidential memory by a given number of bytes. Returns an error if the resulting
151151
/// address is outside the confidential memory region or exceeds the given upper bound.
152-
#[rr::trust_me]
152+
#[rr::only_spec]
153153
#[rr::ok]
154154
/// Precondition: The offset address is in confidential memory.
155-
#[rr::requires("address.2 + offset_in_bytes < self.(conf_end).2")]
155+
#[rr::requires("address.2 + offset_in_bytes < upper_bound.2")]
156156
/// Precondition: The bounds we are checking are within confidential memory.
157157
#[rr::requires("upper_bound.2 ≤ self.(conf_end).2")]
158158
/// Postcondition: Then we can correctly offset the address and ensure it is in confidential
@@ -162,7 +162,7 @@ impl MemoryLayout {
162162
&self, address: &ConfidentialMemoryAddress, offset_in_bytes: usize, upper_bound: *const usize,
163163
) -> Result<ConfidentialMemoryAddress, Error> {
164164
ensure!(upper_bound <= self.confidential_memory_end, Error::AddressNotInConfidentialMemory())?;
165-
Ok(self.confidential_address_at_offset(address, offset_in_bytes)?)
165+
Ok(address.add(offset_in_bytes, upper_bound).map_err(|_| Error::AddressNotInConfidentialMemory())?)
166166
}
167167

168168
/// Offsets an address in the non-confidential memory by given number of bytes. Returns an error if the resulting
@@ -199,8 +199,8 @@ impl MemoryLayout {
199199
// We can safely cast the below offset to usize because the constructor guarantees that the confidential memory
200200
// range is valid, and so the memory size must be a valid usize
201201
let memory_size = ptr_byte_offset(self.confidential_memory_end, self.confidential_memory_start) as usize;
202-
let usize_alligned_offsets = (0..memory_size).step_by(core::mem::size_of::<usize>());
203-
usize_alligned_offsets.for_each(|offset_in_bytes| {
202+
let usize_aligned_offsets = (0..memory_size).step_by(core::mem::size_of::<usize>());
203+
usize_aligned_offsets.for_each(|offset_in_bytes| {
204204
let _ = ptr_byte_add_mut(self.confidential_memory_start, offset_in_bytes, self.confidential_memory_end)
205205
.and_then(|ptr| Ok(unsafe { ptr.write_volatile(0) }));
206206
});

0 commit comments

Comments
 (0)