Skip to content

Commit 7104fea

Browse files
committed
fix get_max_prot
1 parent cf69c60 commit 7104fea

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/safeposix/vmmap.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,26 @@ impl VmmapEntry {
6363
};
6464
}
6565

66-
// Placeholder method to get maximum protection (currrently incomplete)
67-
fn get_max_prot(&self, cage_id: u64, FileDescriptor(u64)) -> i32 {
68-
let flags = PROT_NONE;
69-
70-
flags
71-
}
66+
// get maximum protection for file based mappings
67+
// this is effectively whatever mode the file was opened with
68+
// we need this because we shouldnt be able to change filed backed mappings
69+
// to have protections exceeding that of the file
70+
fn get_max_prot(&self, cage_id: u64, virtual_fd: u64 -> i32 {
71+
72+
let wrappedvfd = fdtables::translate_virtual_fd(cage_id, virtual_fd as u64);
73+
if wrappedvfd.is_err() {
74+
return syscall_error(Errno::EBADF, "fstat", "Bad File Descriptor");
75+
}
76+
let vfd = wrappedvfd.unwrap();
7277

78+
// Declare statbuf by ourselves
79+
let mut libc_statbuf: stat = unsafe { std::mem::zeroed() };
80+
let libcret = unsafe {
81+
libc::fstat(vfd.underfd as i32, &mut libc_statbuf)
82+
};
7383

74-
// Placeholder method to check file descriptor protection (currently does nothing)
75-
fn check_fd_protection(&self, cage_id: i32) {
76-
let _ = cage_id;
77-
} // will call the microvisor, need to pass fd
78-
// number if only its files backed and returns flags of fd
84+
libc_statbuf.mode as i32
85+
}
7986
}
8087

8188
// VmmapOps trait provides an interface that can be shared by different virtual memory management implementations,

0 commit comments

Comments
 (0)