Skip to content

Commit

Permalink
Rename application struct in kernel to avoid confusion with the proce…
Browse files Browse the repository at this point in the history
…ss struct

Change-Id: Ib12ad20b11fc36f6055cd213dcb4ac80f1a63587
  • Loading branch information
jul-sh committed Jun 26, 2024
1 parent b07fc5b commit 28f8b82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
15 changes: 9 additions & 6 deletions oak_restricted_kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod libm;
mod logging;
mod memory;
mod mm;
mod payload;
mod processes;
#[cfg(feature = "serial_channel")]
mod serial;
pub mod shutdown;
Expand Down Expand Up @@ -94,7 +94,7 @@ use zeroize::Zeroize;
use crate::{
acpi::Acpi,
mm::Translator,
payload::Process,
processes::Process,
snp::{get_snp_page_addresses, init_snp_pages},
};

Expand Down Expand Up @@ -449,17 +449,20 @@ pub fn start_kernel(info: &BootParams) -> ! {

log::info!("Binary loaded, size: {}", application_bytes.len());

let application =
payload::Application::new(application_bytes).expect("failed to parse application");

syscall::enable_syscalls(
channel,
syscall::dice_data::DiceData::Layer0(Box::new(stage0_dice_data)),
);

// Ensure new process is not dropped.
// Safety: The application is assumed to be a valid ELF file.
let pid = unsafe { Process::from_application(&application).expect("failed to create process") };
let pid = {
let elf_executeable =
processes::ElfExecuteable::new(application_bytes).expect("failed to parse application");
unsafe {
Process::from_elf_executeable(&elf_executeable).expect("failed to create process")
}
};

PROCCESSES.execute(pid).expect("failed to execute initial process")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ self_cell!(
}
);

/// Representation of an Restricted Application that the Restricted Kernel can
/// run.
pub struct Application {
/// Parsed Elf executeable representing a Restricted Application.
pub struct ElfExecuteable {
binary: Binary,
}

impl Application {
impl ElfExecuteable {
/// Attempts to parse the provided binary blob as an ELF file representing
/// an Restricted Application.
/// a Restricted Application.
pub fn new(blob: Box<[u8]>) -> Result<Self> {
Ok(Application {
Ok(ElfExecuteable {
binary: Binary::try_new(blob, |boxed| {
goblin::elf::Elf::parse(boxed)
.map_err(|err| anyhow!("failed to parse ELF file: {}", err))
Expand Down Expand Up @@ -144,7 +143,7 @@ impl Application {
}
}

pub fn identify_pml4_frame(
fn identify_pml4_frame(
pml4: &x86_64::structures::paging::PageTable,
) -> Result<x86_64::structures::paging::PhysFrame, anyhow::Error> {
let phys_addr = {
Expand All @@ -170,9 +169,11 @@ impl Process {
///
/// # Safety
///
/// The application must be built from a valid ELF file representing an Oak
/// The process must be built from a valid ELF file representing an Oak
/// Restricted Application.
pub unsafe fn from_application(application: &Application) -> Result<usize, anyhow::Error> {
pub unsafe fn from_elf_executeable(
elf_executeable: &ElfExecuteable,
) -> Result<usize, anyhow::Error> {
let pml4 = crate::BASE_L4_PAGE_TABLE.get().context("base l4 table should be set")?.clone();
// Load the process's page table, so the application can be loaded into its
// memory. Hold onto the previous PT, so we can revert to it once the
Expand All @@ -187,7 +188,7 @@ impl Process {

// Safety: caller ensured the application is a valid ELF file representing an
// Oak Restricted Application.
let entry = unsafe { application.map_into_memory() };
let entry = unsafe { elf_executeable.map_into_memory() };

// We've mapped the memory into the process page tables. Let's revert to the
// previous page table.
Expand Down
13 changes: 8 additions & 5 deletions oak_restricted_kernel/src/syscall/create_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::{

use oak_restricted_kernel_interface::Errno;

use crate::payload::Process;
use crate::processes::Process;

pub fn syscall_unstable_create_proccess(buf: *mut c_void, count: c_size_t) -> c_ssize_t {
// Safety: we should validate that the pointer and count are valid, as these
Expand All @@ -38,12 +38,15 @@ fn unstable_create_proccess(buf: &[u8]) -> Result<usize, Errno> {
// Copy the ELF file into kernel space.
let copied_elf_binary: alloc::vec::Vec<u8> = buf.to_vec();

let application = crate::payload::Application::new(copied_elf_binary.into_boxed_slice())
.inspect_err(|err| log::error!("failed to create application: {:?}", err))
.map_err(|_| Errno::EINVAL)?;
let elf_executeable =
crate::processes::ElfExecuteable::new(copied_elf_binary.into_boxed_slice())
.inspect_err(|err| log::error!("failed to parse application elf file: {:?}", err))
.map_err(|_| Errno::EINVAL)?;

Ok(
// Safety: application is assumed to be a valid ELF file.
unsafe { Process::from_application(&application).expect("failed to create process") },
unsafe {
Process::from_elf_executeable(&elf_executeable).expect("failed to create process")
},
)
}

0 comments on commit 28f8b82

Please sign in to comment.