Skip to content

Commit

Permalink
feat(mmap): ensure the file is readable
Browse files Browse the repository at this point in the history
Signed-off-by: Anhad Singh <[email protected]>
  • Loading branch information
Andy-Python-Programmer committed Jul 3, 2024
1 parent 08f1190 commit a35528b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/aero_kernel/src/fs/file_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ impl FileHandle {

#[inline]
pub fn is_readable(&self) -> bool {
self.flags()
.intersects(OpenFlags::O_RDONLY | OpenFlags::O_RDWR)
// FIXME: switch to Linux ABI for fcntl. mlibc defines O_RDONLY as 0 so, we have to infer
// the read-only flag.
let flags = self.flags();
flags.contains(OpenFlags::O_RDWR) || !flags.contains(OpenFlags::O_WRONLY)
}

pub fn flags(&self) -> OpenFlags {
Expand Down
4 changes: 2 additions & 2 deletions src/aero_kernel/src/userland/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ impl Vm {
}

if !file.is_readable() {
// return None; // EACCES
return None; // EACCES
}

// TODO: * check if the filsystem is noexec mounted and remove the MAY_EXEC flag.
Expand All @@ -1419,7 +1419,7 @@ impl Vm {

(MMapFlags::MAP_PRIVATE, Some(file)) => {
if !file.is_readable() {
// return None; // EACCES
return None; // EACCES
}

// TODO: * check if the filsystem is noexec mounted and remove the MAY_EXEC flag.
Expand Down

0 comments on commit a35528b

Please sign in to comment.