Skip to content

Commit a35528b

Browse files
feat(mmap): ensure the file is readable
Signed-off-by: Anhad Singh <[email protected]>
1 parent 08f1190 commit a35528b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/aero_kernel/src/fs/file_table.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ impl FileHandle {
6565

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

7274
pub fn flags(&self) -> OpenFlags {

src/aero_kernel/src/userland/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ impl Vm {
14101410
}
14111411

14121412
if !file.is_readable() {
1413-
// return None; // EACCES
1413+
return None; // EACCES
14141414
}
14151415

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

14201420
(MMapFlags::MAP_PRIVATE, Some(file)) => {
14211421
if !file.is_readable() {
1422-
// return None; // EACCES
1422+
return None; // EACCES
14231423
}
14241424

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

0 commit comments

Comments
 (0)