Date: Fri, 30 Jun 2017 15:49:36 +0000 (UTC) From: Alan Cox <alc@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320498 - in head/sys: kern vm Message-ID: <201706301549.v5UFnaFA084054@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: alc Date: Fri Jun 30 15:49:36 2017 New Revision: 320498 URL: https://svnweb.freebsd.org/changeset/base/320498 Log: Clear the MAP_WIREFUTURE flag on the vm map in exec_new_vmspace() when it recycles the current vm space. Otherwise, an mlockall(MCL_FUTURE) could still be in effect on the process after an execve(2), which violates the specification for mlockall(2). It's pointless for vm_map_stack() to check the MEMLOCK limit. It will never be asked to wire the stack. Moreover, it doesn't even implement wiring of the stack. Reviewed by: kib, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11421 Modified: head/sys/kern/kern_exec.c head/sys/vm/vm_map.c Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Fri Jun 30 14:45:43 2017 (r320497) +++ head/sys/kern/kern_exec.c Fri Jun 30 15:49:36 2017 (r320498) @@ -1091,6 +1091,10 @@ exec_new_vmspace(struct image_params *imgp, struct sys shmexit(vmspace); pmap_remove_pages(vmspace_pmap(vmspace)); vm_map_remove(map, vm_map_min(map), vm_map_max(map)); + /* An exec terminates mlockall(MCL_FUTURE). */ + vm_map_lock(map); + vm_map_modflags(map, 0, MAP_WIREFUTURE); + vm_map_unlock(map); } else { error = vmspace_exec(p, sv_minuser, sv->sv_maxuser); if (error) Modified: head/sys/vm/vm_map.c ============================================================================== --- head/sys/vm/vm_map.c Fri Jun 30 14:45:43 2017 (r320497) +++ head/sys/vm/vm_map.c Fri Jun 30 15:49:36 2017 (r320498) @@ -3557,25 +3557,23 @@ vmspace_fork(struct vmspace *vm1, vm_ooffset_t *fork_c return (vm2); } +/* + * Create a process's stack for exec_new_vmspace(). This function is never + * asked to wire the newly created stack. + */ int vm_map_stack(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, vm_prot_t prot, vm_prot_t max, int cow) { vm_size_t growsize, init_ssize; - rlim_t lmemlim, vmemlim; + rlim_t vmemlim; int rv; + MPASS((map->flags & MAP_WIREFUTURE) == 0); growsize = sgrowsiz; init_ssize = (max_ssize < growsize) ? max_ssize : growsize; vm_map_lock(map); - lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK); vmemlim = lim_cur(curthread, RLIMIT_VMEM); - if (!old_mlock && map->flags & MAP_WIREFUTURE) { - if (ptoa(pmap_wired_count(map->pmap)) + init_ssize > lmemlim) { - rv = KERN_NO_SPACE; - goto out; - } - } /* If we would blow our VMEM resource limit, no go */ if (map->size + init_ssize > vmemlim) { rv = KERN_NO_SPACE;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706301549.v5UFnaFA084054>