]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/posix_shm.c
xnu-4903.231.4.tar.gz
[apple/xnu.git] / bsd / kern / posix_shm.c
index 1fe7878123144c4056e1609702b8f42c17dd97f1..d220614dbe1ff7ac66c749f96ed7980ac8b73011 100644 (file)
@@ -865,6 +865,7 @@ pshm_mmap(__unused proc_t p, struct mmap_args *uap, user_addr_t *retval, struct
        vm_map_offset_t user_start_addr;
        vm_map_size_t   map_size, mapped_size;
        int prot = uap->prot;
        vm_map_offset_t user_start_addr;
        vm_map_size_t   map_size, mapped_size;
        int prot = uap->prot;
+       int max_prot = VM_PROT_DEFAULT;
        int flags = uap->flags;
        vm_object_offset_t file_pos = (vm_object_offset_t)uap->pos;
        vm_object_offset_t map_pos;
        int flags = uap->flags;
        vm_object_offset_t file_pos = (vm_object_offset_t)uap->pos;
        vm_object_offset_t map_pos;
@@ -887,8 +888,12 @@ pshm_mmap(__unused proc_t p, struct mmap_args *uap, user_addr_t *retval, struct
                return(EINVAL);
 
 
                return(EINVAL);
 
 
-       if ((prot & PROT_WRITE) && ((fp->f_flag & FWRITE) == 0)) {
-               return(EPERM);
+       /* Can't allow write permission if the shm_open() didn't */
+       if (!(fp->f_flag & FWRITE)) {
+               if (prot & VM_PROT_WRITE) {
+                       return EPERM;
+               }
+               max_prot &= ~VM_PROT_WRITE;
        }
 
        if (((pnode = (struct pshmnode *)fp->f_data)) == PSHMNODE_NULL )
        }
 
        if (((pnode = (struct pshmnode *)fp->f_data)) == PSHMNODE_NULL )
@@ -1000,7 +1005,7 @@ pshm_mmap(__unused proc_t p, struct mmap_args *uap, user_addr_t *retval, struct
                        file_pos - map_pos,
                        docow,
                        prot,
                        file_pos - map_pos,
                        docow,
                        prot,
-                       VM_PROT_DEFAULT, 
+                       max_prot,
                        VM_INHERIT_SHARE);
                if (kret != KERN_SUCCESS) 
                        goto out;
                        VM_INHERIT_SHARE);
                if (kret != KERN_SUCCESS) 
                        goto out;