Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in_exposed_bounds security vulnerability #1114

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ impl Process<'a> {
unsafe { self.memory.as_ptr().offset(self.memory.len() as isize) }
}

fn mem_break(&self) -> *const u8 {
self.kernel_memory_break.get()
}

crate fn flash_start(&self) -> *const u8 {
self.flash.as_ptr()
}
Expand Down Expand Up @@ -790,10 +794,17 @@ impl Process<'a> {
}
}

/// Checks if the buffer represented by the passed in base pointer and size
/// are within the memory bounds currently exposed to the processes (i.e.
/// ending at `kernel_memory_break`. If this method returns true, the buffer
/// is guaranteed to be accessible to the process and to not overlap with
/// the grant region.
crate fn in_exposed_bounds(&self, buf_start_addr: *const u8, size: usize) -> bool {
let buf_end_addr = unsafe { buf_start_addr.offset(size as isize) };
let buf_end_addr = buf_start_addr.wrapping_offset(size as isize);

buf_start_addr >= self.mem_start() && buf_end_addr <= self.mem_end()
buf_end_addr >= buf_start_addr
&& buf_start_addr >= self.mem_start()
&& buf_end_addr <= self.mem_break()
}

crate unsafe fn alloc(&self, size: usize) -> Option<&mut [u8]> {
Expand Down