From 65cd42028c2b228f3dca038c90b6428b92ea8a4e Mon Sep 17 00:00:00 2001 From: lcy1996 <992195697@qq.com> Date: Wed, 14 Nov 2018 01:13:19 +0800 Subject: [PATCH] Add illegal vma check in page fault hangler --- kernel/src/memory.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index c9e5f7d..dc9cd40 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -122,14 +122,20 @@ pub fn page_fault_handler(addr: usize) -> bool { info!("active page table token in pg fault is {:x?}", ActivePageTable::token()); let id = memory_set_record().iter() .position(|x| unsafe{(*(x.clone() as *mut MemorySet)).get_page_table_mut().token() == ActivePageTable::token()}); - info!("id got"); let mut mmsets = memory_set_record(); - info!("mmset got"); match id { Some(targetid) => { info!("get id from memroy set recorder."); let mmset_ptr = mmsets.get(targetid); - let pt = unsafe { (*(mmset_ptr.unwrap().clone() as *mut MemorySet)).get_page_table_mut() }; + // get current mmset + + let current_mmset = unsafe{&mut *(mmset_ptr.unwrap().clone() as *mut MemorySet)}; + //check whether the vma is legal + if(current_mmset.find_area(addr).is_none()){ + return false; + } + + let pt = current_mmset.get_page_table_mut(); info!("pt got!"); if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, false, || alloc_frame().unwrap()){ return true; @@ -137,6 +143,10 @@ pub fn page_fault_handler(addr: usize) -> bool { }, None => { info!("get pt from processor()"); + if(process().get_memory_set_mut().find_area(addr).is_none()){ + return false; + } + let pt = process().get_memory_set_mut().get_page_table_mut(); info!("pt got"); if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, true, || alloc_frame().unwrap()){