Out of program execution parameter

This commit is contained in:
Erin 2023-08-17 03:45:57 +02:00 committed by ondra05
parent de811c172e
commit 73eed89ab3
4 changed files with 14 additions and 8 deletions

View file

@ -16,7 +16,7 @@ fuzz_target!(|data: &[u8]| {
if validate(data).is_ok() {
let mut vm = unsafe {
Vm::<_, 16384>::new(
SoftPagedMem {
SoftPagedMem::<_, true> {
pf_handler: TestTrapHandler,
program: data,
root_pt: Box::into_raw(Default::default()),

View file

@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
unsafe {
let mut vm = Vm::<_, 0>::new(
SoftPagedMem {
SoftPagedMem::<_, true> {
pf_handler: TestTrapHandler,
program: &prog,
root_pt: Box::into_raw(Default::default()),

View file

@ -10,7 +10,7 @@ use {
derive_more::Display,
};
impl<'p, A> SoftPagedMem<'p, A> {
impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> {
/// Maps host's memory into VM's memory
///
/// # Safety

View file

@ -18,8 +18,12 @@ use {
};
/// HoleyBytes software paged memory
///
/// - `OUT_PROG_EXEC`: set to `false` to disable executing program
/// not contained in initially provided program, even the pages
/// are executable
#[derive(Clone, Debug)]
pub struct SoftPagedMem<'p, PfH> {
pub struct SoftPagedMem<'p, PfH, const OUT_PROG_EXEC: bool = true> {
/// Root page table
pub root_pt: *mut PageTable,
/// Page fault handler
@ -30,7 +34,9 @@ pub struct SoftPagedMem<'p, PfH> {
pub icache: ICache,
}
impl<'p, PfH: HandlePageFault> Memory for SoftPagedMem<'p, PfH> {
impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory
for SoftPagedMem<'p, PfH, OUT_PROG_EXEC>
{
/// Load value from an address
///
/// # Safety
@ -70,7 +76,7 @@ impl<'p, PfH: HandlePageFault> Memory for SoftPagedMem<'p, PfH> {
#[inline(always)]
unsafe fn prog_read<T>(&mut self, addr: u64) -> Option<T> {
if addr as usize > self.program.len() {
if OUT_PROG_EXEC && addr as usize > self.program.len() {
return self.icache.fetch::<T>(addr, self.root_pt);
}
@ -82,7 +88,7 @@ impl<'p, PfH: HandlePageFault> Memory for SoftPagedMem<'p, PfH> {
#[inline(always)]
unsafe fn prog_read_unchecked<T>(&mut self, addr: u64) -> T {
if addr as usize > self.program.len() {
if OUT_PROG_EXEC && addr as usize > self.program.len() {
return self
.icache
.fetch::<T>(addr as _, self.root_pt)
@ -93,7 +99,7 @@ impl<'p, PfH: HandlePageFault> Memory for SoftPagedMem<'p, PfH> {
}
}
impl<'p, PfH: HandlePageFault> SoftPagedMem<'p, PfH> {
impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, PfH, OUT_PROG_EXEC> {
// Everyone behold, the holy function, the god of HBVM memory accesses!
/// Split address to pages, check their permissions and feed pointers with offset