X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d9a64523371fa019c4575bb400cbbc3a50ac9903..e8c3f78193f1895ea514044358b93b1add9322f3:/bsd/kern/posix_shm.c?ds=sidebyside diff --git a/bsd/kern/posix_shm.c b/bsd/kern/posix_shm.c index 1fe787812..d220614db 100644 --- a/bsd/kern/posix_shm.c +++ b/bsd/kern/posix_shm.c @@ -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; + 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; @@ -887,8 +888,12 @@ pshm_mmap(__unused proc_t p, struct mmap_args *uap, user_addr_t *retval, struct 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 ) @@ -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, - VM_PROT_DEFAULT, + max_prot, VM_INHERIT_SHARE); if (kret != KERN_SUCCESS) goto out;