mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-20 19:08:39 +00:00
kata-security-coordinator::fakeimpl: eliminate deep_copy panics
Bug: 243575548 Change-Id: Ie48e8bb4bfcf2fd2284c5822b12b3ace75018a62 GitOrigin-RevId: 92fa86dc4f528c4046dcf2bb635bf7ad0a50551c
This commit is contained in:
@@ -32,6 +32,7 @@ use kata_security_interface::*;
|
|||||||
use kata_storage_interface::KeyValueData;
|
use kata_storage_interface::KeyValueData;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
use sel4_sys::seL4_Error;
|
||||||
use sel4_sys::seL4_PageBits;
|
use sel4_sys::seL4_PageBits;
|
||||||
use sel4_sys::seL4_Page_GetAddress;
|
use sel4_sys::seL4_Page_GetAddress;
|
||||||
use sel4_sys::seL4_Word;
|
use sel4_sys::seL4_Word;
|
||||||
@@ -110,8 +111,10 @@ pub type KataSecurityCoordinatorInterface = FakeSecurityCoordinator;
|
|||||||
|
|
||||||
// Returns a deep copy (including seL4 objects) of |src|. The container
|
// Returns a deep copy (including seL4 objects) of |src|. The container
|
||||||
// CNode is in the toplevel (allocated from the slot allocator).
|
// CNode is in the toplevel (allocated from the slot allocator).
|
||||||
fn deep_copy(src: &ObjDescBundle) -> ObjDescBundle {
|
fn deep_copy(src: &ObjDescBundle) -> Result<ObjDescBundle, seL4_Error> {
|
||||||
let dest = kata_frame_alloc_in_cnode(src.size_bytes()).expect("deep_copy:alloc");
|
let dest = kata_frame_alloc_in_cnode(src.size_bytes())
|
||||||
|
.map_err(|_| seL4_Error::seL4_NotEnoughMemory)?; // TODO(sleffler) From mapping
|
||||||
|
assert_eq!(src.count(), dest.count());
|
||||||
// Src top-level slot & copy region
|
// Src top-level slot & copy region
|
||||||
let src_slot = CSpaceSlot::new();
|
let src_slot = CSpaceSlot::new();
|
||||||
let mut src_region = CopyRegion::new(unsafe { ptr::addr_of_mut!(DEEP_COPY_SRC[0]) }, PAGE_SIZE);
|
let mut src_region = CopyRegion::new(unsafe { ptr::addr_of_mut!(DEEP_COPY_SRC[0]) }, PAGE_SIZE);
|
||||||
@@ -123,12 +126,10 @@ fn deep_copy(src: &ObjDescBundle) -> ObjDescBundle {
|
|||||||
// Map src & dest frames and copy data.
|
// Map src & dest frames and copy data.
|
||||||
src_slot
|
src_slot
|
||||||
.copy_to(src.cnode, src_cptr, src.depth)
|
.copy_to(src.cnode, src_cptr, src.depth)
|
||||||
.and_then(|_| src_region.map(src_slot.slot))
|
.and_then(|_| src_region.map(src_slot.slot))?;
|
||||||
.expect("src_map");
|
|
||||||
dest_slot
|
dest_slot
|
||||||
.copy_to(dest.cnode, dest_cptr, dest.depth)
|
.copy_to(dest.cnode, dest_cptr, dest.depth)
|
||||||
.and_then(|_| dest_region.map(dest_slot.slot))
|
.and_then(|_| dest_region.map(dest_slot.slot))?;
|
||||||
.expect("dest_map");
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::copy_nonoverlapping(
|
ptr::copy_nonoverlapping(
|
||||||
@@ -139,16 +140,10 @@ fn deep_copy(src: &ObjDescBundle) -> ObjDescBundle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmap & clear top-level slot required for mapping.
|
// Unmap & clear top-level slot required for mapping.
|
||||||
src_region
|
src_region.unmap().and_then(|_| src_slot.delete())?;
|
||||||
.unmap()
|
dest_region.unmap().and_then(|_| dest_slot.delete())?;
|
||||||
.and_then(|_| src_slot.delete())
|
|
||||||
.expect("src_unmap");
|
|
||||||
dest_region
|
|
||||||
.unmap()
|
|
||||||
.and_then(|_| dest_slot.delete())
|
|
||||||
.expect("dest_unmap");
|
|
||||||
}
|
}
|
||||||
dest
|
Ok(dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SecurityCoordinatorInterface for FakeSecurityCoordinator {
|
impl SecurityCoordinatorInterface for FakeSecurityCoordinator {
|
||||||
@@ -182,7 +177,8 @@ impl SecurityCoordinatorInterface for FakeSecurityCoordinator {
|
|||||||
// Clone everything (struct + associated seL4 objects) so the
|
// Clone everything (struct + associated seL4 objects) so the
|
||||||
// return is as though it was newly instantiated from flash.
|
// return is as though it was newly instantiated from flash.
|
||||||
// XXX just return the package for now
|
// XXX just return the package for now
|
||||||
Ok(deep_copy(&bundle_data.pkg_contents))
|
deep_copy(&bundle_data.pkg_contents)
|
||||||
|
.map_err(|_| SecurityRequestError::SreLoadApplicationFailed)
|
||||||
}
|
}
|
||||||
fn load_model(
|
fn load_model(
|
||||||
&self,
|
&self,
|
||||||
@@ -194,7 +190,7 @@ impl SecurityCoordinatorInterface for FakeSecurityCoordinator {
|
|||||||
// Clone everything (struct + associated seL4 objects) so the
|
// Clone everything (struct + associated seL4 objects) so the
|
||||||
// return is as though it was newly instantiated from flash.
|
// return is as though it was newly instantiated from flash.
|
||||||
// XXX just return the package for now
|
// XXX just return the package for now
|
||||||
Ok(deep_copy(&bundle_data.pkg_contents))
|
deep_copy(&bundle_data.pkg_contents).map_err(|_| SecurityRequestError::SreLoadModelFailed)
|
||||||
}
|
}
|
||||||
fn read_key(&self, bundle_id: &str, key: &str) -> Result<&KeyValueData, SecurityRequestError> {
|
fn read_key(&self, bundle_id: &str, key: &str) -> Result<&KeyValueData, SecurityRequestError> {
|
||||||
let bundle = self.get_bundle(bundle_id)?;
|
let bundle = self.get_bundle(bundle_id)?;
|
||||||
|
Reference in New Issue
Block a user