summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/vm/vm_map.c8
1 files changed, 8 insertions, 0 deletions
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;