Date: Mon, 11 Jan 2021 23:22:16 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 4ea65707d370 - main - exec_new_vmspace: print useful error message on ctty if stack cannot be mapped. Message-ID: <202101112322.10BNMG45035531@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4ea65707d3700efe250868a7a581b87fd96f635c commit 4ea65707d3700efe250868a7a581b87fd96f635c Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-01-11 18:51:07 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-01-11 23:15:43 +0000 exec_new_vmspace: print useful error message on ctty if stack cannot be mapped. After old vmspace is destroyed during execve(2), but before the new space is fully constructed, an error during image activation cannot be returned because there is no executing program to receive it. In the relatively common case of failure to map stack, print some hints on the control terminal. Note that user has enough knobs to cause stack mapping error, and this is the most common reason for execve(2) aborting the process. Requested by: jhb Reviewed by: emaste, jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28050 --- sys/kern/kern_exec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 13753177127f..3de6ac565db5 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1043,6 +1043,7 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv) struct rlimit rlim_stack; vm_offset_t sv_minuser, stack_addr; vm_map_t map; + vm_prot_t stack_prot; u_long ssiz; imgp->vmspace_destroyed = 1; @@ -1126,11 +1127,16 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv) if (ssiz < imgp->eff_stack_sz) imgp->eff_stack_sz = ssiz; stack_addr = sv->sv_usrstack - ssiz; - error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz, - obj != NULL && imgp->stack_prot != 0 ? imgp->stack_prot : - sv->sv_stackprot, VM_PROT_ALL, MAP_STACK_GROWS_DOWN); - if (error != KERN_SUCCESS) + stack_prot = obj != NULL && imgp->stack_prot != 0 ? + imgp->stack_prot : sv->sv_stackprot; + error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz, stack_prot, + VM_PROT_ALL, MAP_STACK_GROWS_DOWN); + if (error != KERN_SUCCESS) { + uprintf("exec_new_vmspace: mapping stack size %#jx prot %#x " + "failed mach error %d errno %d\n", (uintmax_t)ssiz, + stack_prot, error, vm_mmap_to_errno(error)); return (vm_mmap_to_errno(error)); + } /* * vm_ssize and vm_maxsaddr are somewhat antiquated concepts, but they
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101112322.10BNMG45035531>