-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for CVM's untrusted MMIO regions (#60)
Added support for CoVE COVG ABI that enables CVM to add and remove untrusted MMIO regions. --------- Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
- Loading branch information
1 parent
46fb836
commit 3a44d06
Showing
13 changed files
with
847 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
security-monitor/src/confidential_flow/apply_to_confidential_vm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::confidential_flow::handlers::mmio::MmioAccessFault; | ||
use crate::confidential_flow::handlers::sbi::SbiResponse; | ||
use crate::confidential_flow::handlers::virtual_instructions::VirtualInstruction; | ||
|
||
/// Transformation of the confidential hart state in a response to processing of a confidential hart call. | ||
pub enum ApplyToConfidentialHart { | ||
MmioAccessFault(MmioAccessFault), | ||
SbiResponse(SbiResponse), | ||
VirtualInstruction(VirtualInstruction), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
security-monitor/src/confidential_flow/handlers/mmio/mmio_access_fault.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::core::control_data::{ConfidentialHart, ConfidentialVmId, ConfidentialVmMmioRegion, ControlData}; | ||
use core::mem; | ||
|
||
pub struct MmioAccessFault { | ||
cause: usize, | ||
mtval: usize, | ||
instruction_length: usize, | ||
} | ||
|
||
impl MmioAccessFault { | ||
pub const ADDRESS_ALIGNMENT: usize = mem::size_of::<usize>(); | ||
|
||
pub fn new(cause: usize, mtval: usize, instruction_length: usize) -> Self { | ||
Self { cause, mtval, instruction_length } | ||
} | ||
|
||
pub fn apply_to_confidential_hart(&self, confidential_hart: &mut ConfidentialHart) { | ||
let mepc = confidential_hart.csrs().mepc.read_value() + self.instruction_length; | ||
confidential_hart.csrs_mut().vsepc.set(mepc); | ||
let trap_vector_address = confidential_hart.csrs().vstvec.read(); | ||
confidential_hart.csrs_mut().mepc.save_value(trap_vector_address); | ||
confidential_hart.csrs_mut().vscause.set(self.cause); | ||
confidential_hart.csrs_mut().vstval.set(self.mtval); | ||
} | ||
|
||
pub fn tried_to_access_valid_mmio_region(confidential_vm_id: ConfidentialVmId, fault_address: usize) -> bool { | ||
ControlData::try_confidential_vm(confidential_vm_id, |confidential_vm| { | ||
Ok(confidential_vm.is_mmio_region_defined(&ConfidentialVmMmioRegion::new(fault_address, Self::ADDRESS_ALIGNMENT)?)) | ||
}) | ||
.unwrap_or(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
security-monitor/src/core/control_data/confidential_vm_mmio_region.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::error::Error; | ||
|
||
#[derive(Debug)] | ||
pub struct ConfidentialVmMmioRegion { | ||
pub region_start_address: usize, | ||
pub region_length: usize, | ||
} | ||
|
||
impl ConfidentialVmMmioRegion { | ||
pub fn new(region_start_address: usize, region_length: usize) -> Result<Self, Error> { | ||
// TODO: make sure region_start_address is aligned to 4KiB | ||
// TODO: make sure the region_start_address is a valid guest address | ||
Ok(Self { region_start_address, region_length }) | ||
} | ||
|
||
pub fn overlaps(&self, other: &Self) -> bool { | ||
self.region_start_address < other.region_start_address + other.region_length | ||
&& other.region_start_address < self.region_start_address + self.region_length | ||
} | ||
|
||
pub fn contains(&self, other: &Self) -> bool { | ||
self.region_start_address <= other.region_start_address | ||
&& other.region_start_address + other.region_length < self.region_start_address + self.region_length | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.