From owner-dev-commits-src-main@freebsd.org Mon Jan 11 23:22:16 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9759B4E96AE; Mon, 11 Jan 2021 23:22:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DF8qr3wFrz3KdK; Mon, 11 Jan 2021 23:22:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6F65C22CC7; Mon, 11 Jan 2021 23:22:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10BNMGqq035532; Mon, 11 Jan 2021 23:22:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10BNMG45035531; Mon, 11 Jan 2021 23:22:16 GMT (envelope-from git) Date: Mon, 11 Jan 2021 23:22:16 GMT Message-Id: <202101112322.10BNMG45035531@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4ea65707d370 - main - exec_new_vmspace: print useful error message on ctty if stack cannot be mapped. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4ea65707d3700efe250868a7a581b87fd96f635c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 23:22:16 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4ea65707d3700efe250868a7a581b87fd96f635c commit 4ea65707d3700efe250868a7a581b87fd96f635c Author: Konstantin Belousov AuthorDate: 2021-01-11 18:51:07 +0000 Commit: Konstantin Belousov 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