Skip to content

Commit d7966a7

Browse files
authored
Allow mmaping FILE_TYPE_LOCALTIME files (#3226)
This restores the pre- 9330318 behaviour where we allow mmapping `/etc/localtime`. This fixes #3224 and prevents a lot of extra `open`, `fstat`, `mmap`, and `close` syscalls.
2 parents 83934ce + f54943c commit d7966a7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • src/main/host/syscall/handler

src/main/host/syscall/handler/mman.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,14 @@ impl SyscallHandler {
265265

266266
log::trace!("Trying to open file {fd} in the plugin");
267267

268-
// make sure we don't open special files like /dev/urandom, /etc/localtime etc. in the
269-
// plugin via mmap
270-
if unsafe { c::regularfile_getType(file) } != c::_FileType_FILE_TYPE_REGULAR {
271-
warn_once_then_debug!("Tried to mmap a non-regular-file");
268+
// Make sure we don't open special files like `/dev/urandom` in the plugin via mmap. We
269+
// allow `/etc/localtime`, which should have been swapped with `/usr/share/zoneinfo/Etc/UTC`
270+
// in `regularfile_openat`.
271+
let file_type = unsafe { c::regularfile_getType(file) };
272+
if file_type != c::_FileType_FILE_TYPE_REGULAR
273+
&& file_type != c::_FileType_FILE_TYPE_LOCALTIME
274+
{
275+
warn_once_then_debug!("Tried to mmap a non-regular non-localtime file");
272276
return Err(());
273277
}
274278

0 commit comments

Comments
 (0)