mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-20 21:46:31 +00:00
Fix integer overflow caused by page align
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
0a8ad6971a
commit
e184094648
@ -20,7 +20,7 @@ pub fn sys_madvise(
|
||||
if start % PAGE_SIZE != 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned");
|
||||
}
|
||||
if len == 0 {
|
||||
if len == 0 || len > usize::MAX - PAGE_SIZE + 1 {
|
||||
return Ok(SyscallReturn::Return(0));
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,9 @@ fn do_sys_mmap(
|
||||
if len == 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "mmap len cannot be zero");
|
||||
}
|
||||
if len > usize::MAX - PAGE_SIZE + 1 {
|
||||
return_errno_with_message!(Errno::ENOMEM, "mmap len align overflow");
|
||||
}
|
||||
|
||||
let len = len.align_up(PAGE_SIZE);
|
||||
|
||||
|
@ -22,6 +22,9 @@ pub fn sys_mprotect(addr: Vaddr, len: usize, perms: u64, ctx: &Context) -> Resul
|
||||
if len == 0 {
|
||||
return Ok(SyscallReturn::Return(0));
|
||||
}
|
||||
if len > usize::MAX - PAGE_SIZE + 1 {
|
||||
return_errno_with_message!(Errno::ENOMEM, "len align overflow");
|
||||
}
|
||||
|
||||
let len = len.align_up(PAGE_SIZE);
|
||||
let end = addr.checked_add(len).ok_or(Error::with_message(
|
||||
|
@ -14,6 +14,9 @@ pub fn sys_munmap(addr: Vaddr, len: usize, ctx: &Context) -> Result<SyscallRetur
|
||||
if len == 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "munmap len cannot be zero");
|
||||
}
|
||||
if len > usize::MAX - PAGE_SIZE + 1 {
|
||||
return_errno_with_message!(Errno::ENOMEM, "munmap len align overflow");
|
||||
}
|
||||
|
||||
let root_vmar = ctx.process.root_vmar();
|
||||
let len = len.align_up(PAGE_SIZE);
|
||||
|
Reference in New Issue
Block a user