mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 00:06:34 +00:00
Fix a mmap MAP_FIXED
issue
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
1e3403e756
commit
6e46641a09
@ -11,6 +11,7 @@ use crate::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
vm::{
|
vm::{
|
||||||
perms::VmPerms,
|
perms::VmPerms,
|
||||||
|
vmar::is_userspace_vaddr,
|
||||||
vmo::{VmoOptions, VmoRightsOp},
|
vmo::{VmoOptions, VmoRightsOp},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -42,7 +43,7 @@ fn do_sys_mmap(
|
|||||||
addr: Vaddr,
|
addr: Vaddr,
|
||||||
len: usize,
|
len: usize,
|
||||||
vm_perms: VmPerms,
|
vm_perms: VmPerms,
|
||||||
option: MMapOptions,
|
mut option: MMapOptions,
|
||||||
fd: FileDesc,
|
fd: FileDesc,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
@ -52,7 +53,11 @@ fn do_sys_mmap(
|
|||||||
addr, len, vm_perms, option, fd, offset
|
addr, len, vm_perms, option, fd, offset
|
||||||
);
|
);
|
||||||
|
|
||||||
check_option(&option)?;
|
if option.flags.contains(MMapFlags::MAP_FIXED_NOREPLACE) {
|
||||||
|
option.flags.insert(MMapFlags::MAP_FIXED);
|
||||||
|
}
|
||||||
|
|
||||||
|
check_option(addr, &option)?;
|
||||||
|
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "mmap len cannot be zero");
|
return_errno_with_message!(Errno::EINVAL, "mmap len cannot be zero");
|
||||||
@ -156,11 +161,15 @@ fn do_sys_mmap(
|
|||||||
Ok(map_addr)
|
Ok(map_addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_option(option: &MMapOptions) -> Result<()> {
|
fn check_option(addr: Vaddr, option: &MMapOptions) -> Result<()> {
|
||||||
if option.typ() == MMapType::File {
|
if option.typ() == MMapType::File {
|
||||||
return_errno_with_message!(Errno::EINVAL, "Invalid mmap type");
|
return_errno_with_message!(Errno::EINVAL, "Invalid mmap type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if option.flags().contains(MMapFlags::MAP_FIXED) && !is_userspace_vaddr(addr) {
|
||||||
|
return_errno_with_message!(Errno::EINVAL, "Invalid mmap fixed addr");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user