From a6e240d265656408dbe807719dc2f0911c44198f Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 18 Apr 2024 18:32:06 -0400 Subject: kernel: vm_map: Handle oflag in shared maps Signed-off-by: Ian Moffett --- sys/vm/vm_map.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sys/vm') diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index afef6f2..8f7accc 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -191,6 +191,7 @@ vm_fd_map(void *addr, vm_prot_t prot, size_t len, off_t off, int fd) { paddr_t physmem = 0; + int oflag; struct filedesc *filedes; struct vnode *vp; @@ -204,6 +205,13 @@ vm_fd_map(void *addr, vm_prot_t prot, size_t len, off_t off, int fd) if ((vp = filedes->vnode) == NULL) return 0; + /* Check the perms of the filedes */ + oflag = filedes->oflag; + if (__TEST(prot, PROT_WRITE) && oflag == O_RDONLY) + return 0; + if (!__TEST(prot, PROT_WRITE) && oflag == O_WRONLY) + return 0; + /* Try to create the virtual memory object */ if (vm_obj_init(&vp->vmobj, vp) != 0) return 0; -- cgit v1.2.3