Index: sys/compat/cloudabi/cloudabi_mem.c =================================================================== --- sys/compat/cloudabi/cloudabi_mem.c +++ sys/compat/cloudabi/cloudabi_mem.c @@ -110,8 +110,8 @@ if (error != 0) return (error); - return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags, - uap->fd, uap->off)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, + PROT_MAX(PROT_ALL) | prot, flags, uap->fd, uap->off)); } int Index: sys/compat/freebsd32/freebsd32_misc.c =================================================================== --- sys/compat/freebsd32/freebsd32_misc.c +++ sys/compat/freebsd32/freebsd32_misc.c @@ -471,8 +471,8 @@ prot |= PROT_EXEC; #endif - return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, - uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos))); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, uap->flags, + uap->fd, PAIR32TO64(off_t, uap->pos))); } #ifdef COMPAT_FREEBSD6 @@ -488,8 +488,9 @@ prot |= PROT_EXEC; #endif - return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, - uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos))); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, + PROT_MAX(PROT_ALL) | prot, uap->flags, uap->fd, + PAIR32TO64(off_t, uap->pos))); } #endif Index: sys/compat/linux/linux_mmap.c =================================================================== --- sys/compat/linux/linux_mmap.c +++ sys/compat/linux/linux_mmap.c @@ -211,13 +211,14 @@ */ if (addr != 0 && (bsd_flags & MAP_FIXED) == 0 && (bsd_flags & MAP_EXCL) == 0) { - error = kern_mmap(td, addr, len, prot, + error = kern_mmap(td, addr, len, PROT_MAX(PROT_ALL) | prot, bsd_flags | MAP_FIXED | MAP_EXCL, fd, pos); if (error == 0) goto out; } - error = kern_mmap(td, addr, len, prot, bsd_flags, fd, pos); + error = kern_mmap(td, addr, len, PROT_MAX(PROT_ALL) | prot, bsd_flags, + fd, pos); out: LINUX_CTR2(mmap2, "return: %d (%p)", error, td->td_retval[0]); Index: sys/sys/mman.h =================================================================== --- sys/sys/mman.h +++ sys/sys/mman.h @@ -55,6 +55,16 @@ #define PROT_READ 0x01 /* pages can be read */ #define PROT_WRITE 0x02 /* pages can be written */ #define PROT_EXEC 0x04 /* pages can be executed */ +#if __BSD_VISIBLE +#define _PROT_ALL (PROT_READ|PROT_WRITE|PROT_EXEC) +#define EXTRACT_PROT(prot) (prot & _PROT_ALL) + +#define _PROT_MAX_SHIFT 16 +#define PROT_MAX(prot) ((prot) << _PROT_MAX_SHIFT) +#define EXTRACT_PROT_MAX(prot) \ + (((prot) >> _PROT_MAX_SHIFT) != 0 ? \ + ((prot) >> _PROT_MAX_SHIFT) : EXTRACT_PROT(prot)) +#endif /* * Flags contain sharing type and options. Index: sys/vm/vm_mmap.c =================================================================== --- sys/vm/vm_mmap.c +++ sys/vm/vm_mmap.c @@ -184,9 +184,12 @@ vm_offset_t addr; vm_size_t pageoff; vm_prot_t cap_maxprot; - int align, error; + int align, error, max_prot; cap_rights_t rights; + max_prot = EXTRACT_PROT_MAX(prot); + prot = EXTRACT_PROT(prot); + vms = td->td_proc->p_vmspace; fp = NULL; AUDIT_ARG_FD(fd); @@ -329,7 +332,7 @@ * This relies on VM_PROT_* matching PROT_*. */ error = vm_mmap_object(&vms->vm_map, &addr, size, prot, - VM_PROT_ALL, flags, NULL, pos, FALSE, td); + max_prot, flags, NULL, pos, FALSE, td); } else { /* * Mapping file, get fp for validation and don't let the @@ -357,7 +360,7 @@ /* This relies on VM_PROT_* matching PROT_*. */ error = fo_mmap(fp, &vms->vm_map, &addr, size, prot, - cap_maxprot, flags, pos, td); + max_prot & cap_maxprot, flags, pos, td); } if (error == 0) @@ -374,8 +377,8 @@ freebsd6_mmap(struct thread *td, struct freebsd6_mmap_args *uap) { - return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, uap->prot, - uap->flags, uap->fd, uap->pos)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, + PROT_MAX(PROT_ALL) | uap->prot, uap->flags, uap->fd, uap->pos)); } #endif @@ -429,8 +432,8 @@ flags |= MAP_PRIVATE; if (uap->flags & OMAP_FIXED) flags |= MAP_FIXED; - return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot, flags, - uap->fd, uap->pos)); + return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, + PROT_MAX(PROT_ALL) | prot, flags, uap->fd, uap->pos)); } #endif /* COMPAT_43 */