From nobody Fri Jan 14 13:50:17 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 74C9D19479A9; Fri, 14 Jan 2022 13:50:18 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jb2k22SGqz55B4; Fri, 14 Jan 2022 13:50:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642168218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uA4J/4Lal3fwe0LE+yIhVYOUWTkOv5v85UJnZQGdW1I=; b=oNetMLPnCYytCW6laJNcutkrb01T/xn4PTbkLV8oTBf+llGhUiOHnRiXFlMIIKc9ASBroj t7vtETLYxNtD++s1HdGiB4YCc+SYORUg8FevJd8ZYkEIRXwPUqdqu/fja8Qm3s9JnuU/mh NW+y18vH27B76Pi8TA2yXmQYkj+YUL4WOxRS3A+pM9e247QfqgrFj6qAPxdScl21sa2wSL KFF5Zry5DmutPQnw/AExUGDh6/95eMAAjwYgkRxRwB3FlTJDtmE+EkM3reULmQmETrkDBb PvBGxhWpKiemz1m9MdRjrJtVLCCmiFBeeuNuFkZIHr4pYgv30lvBuDGMEjpw2A== 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 18A3414C6F; Fri, 14 Jan 2022 13:50:18 +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 20EDoHQG043916; Fri, 14 Jan 2022 13:50:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EDoHFO043912; Fri, 14 Jan 2022 13:50:17 GMT (envelope-from git) Date: Fri, 14 Jan 2022 13:50:17 GMT Message-Id: <202201141350.20EDoHFO043912@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 1562fe492a79 - stable/13 - exec: Simplify sv_copyout_strings implementations a bit List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1562fe492a7994bacefe4d0a6f6f91fa37972e79 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642168218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uA4J/4Lal3fwe0LE+yIhVYOUWTkOv5v85UJnZQGdW1I=; b=kvjb0iXDfW2YPCh2J3YmtRKR+8IFiOOuWYmLV0tk4l84soXi6TWnfWhXcRB/joyAQDKpQ4 mXMfDjAXhvawFQ3XlUxHEQuLfqRirgf9XEpTclwm6Ip4fXyQATP8RAHf8QmArMXBKTlnSo HzbnVabYdl913vU9/dk1niS1OJHrAtmGwypYDx/IDcfHOmKH7fNO+vaAQFLnBr3paZkfjR XSnohNYw8xt6aSgkjDJvou/YoWndaIpMOG/v1U/YaMm8iwcikOSD+lMH5lrsBSdrpKitwy equv4jPWNYQbMUy9RN78CWa8bch8Vu1DCTrCqYsAuBBijzhvvnNVqkiV3qfBZg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642168218; a=rsa-sha256; cv=none; b=WpOSjlskq3Z3s+Cw+XgyzZk1/7VC8iH50qkOPubzvYNpMffdgfk17GmrKCDQRvi/NpQW1I fA6PqoSswkrfcNvUyq6kONYhpGcZKgvmC1/1FZRZhHLA4uCHVT3MhGfPHSWj8hA6T8wsYR 77FC4TKRlfDg0UMoptXy8e4DZrIP02C/fd0MChzPrk+Sco9Ugwh9EHOcf7SeQaYSH3aleS R3aUpJr73po6EAVIHC6ImPaEvIC7+7yv3aJBccx6CrEXjt8lTMf8sSPWHsYRWw053znLRH VPiiajnaFdELHBvKPg8wH3OD56PkEGrN8JxEbV1n64r28az3K9l8DSt0ppIFSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1562fe492a7994bacefe4d0a6f6f91fa37972e79 commit 1562fe492a7994bacefe4d0a6f6f91fa37972e79 Author: Mark Johnston AuthorDate: 2021-12-31 17:50:15 +0000 Commit: Mark Johnston CommitDate: 2022-01-14 13:50:06 +0000 exec: Simplify sv_copyout_strings implementations a bit Simplify control flow around handling of the execpath length and signal trampoline. Cache the sysentvec pointer in a local variable. No functional change intended. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit f04a096049382637178b54ffb45089f5f9fb3db9) --- sys/amd64/linux/linux_sysvec.c | 9 ++------ sys/amd64/linux32/linux32_sysvec.c | 9 ++------ sys/arm64/linux/linux_sysvec.c | 9 ++------ sys/compat/freebsd32/freebsd32_misc.c | 28 +++++++++--------------- sys/i386/linux/linux_sysvec.c | 8 ++----- sys/kern/kern_exec.c | 40 +++++++++++++---------------------- 6 files changed, 33 insertions(+), 70 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index e02221c324ec..03e17d851a8d 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -327,17 +327,12 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) size_t execpath_len; struct proc *p; - /* Calculate string base and vector table pointers. */ - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; - p = imgp->proc; arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; destp = (uintptr_t)arginfo; - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; destp = rounddown2(destp, sizeof(void *)); imgp->execpathp = (void *)destp; diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 9a8f86ecce10..2e65763062e3 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -740,16 +740,11 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) char canary[LINUX_AT_RANDOM_LEN]; size_t execpath_len; - /* Calculate string base and vector table pointers. */ - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; - arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS; destp = (uintptr_t)arginfo; - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; destp = rounddown2(destp, sizeof(uint32_t)); imgp->execpathp = (void *)destp; diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index 30938251acd9..50bd53d4b08c 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -231,17 +231,12 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) struct proc *p; int argc, envc, error; - /* Calculate string base and vector table pointers. */ - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; - p = imgp->proc; arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; destp = (uintptr_t)arginfo; - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; destp = rounddown2(destp, sizeof(void *)); imgp->execpathp = (void *)destp; diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index db707fdbf44d..5e70a3194c1a 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -3340,6 +3340,7 @@ syscall32_helper_unregister(struct syscall_helper_data *sd) int freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) { + struct sysentvec *sysent; int argc, envc, i; u_int32_t *vectp; char *stringp; @@ -3350,30 +3351,20 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) size_t execpath_len; int error, szsigcode; - /* - * Calculate string base and vector table pointers. - * Also deal with signal trampoline code for this exec type. - */ - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; - arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent-> - sv_psstrings; + sysent = imgp->sysent; + + arginfo = (struct freebsd32_ps_strings *)sysent->sv_psstrings; imgp->ps_strings = arginfo; - if (imgp->proc->p_sysent->sv_sigcode_base == 0) - szsigcode = *(imgp->proc->p_sysent->sv_szsigcode); - else - szsigcode = 0; destp = (uintptr_t)arginfo; /* - * install sigcode + * Install sigcode. */ - if (szsigcode != 0) { + if (sysent->sv_sigcode_base == 0) { + szsigcode = *sysent->sv_szsigcode; destp -= szsigcode; destp = rounddown2(destp, sizeof(uint32_t)); - error = copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp, + error = copyout(sysent->sv_sigcode, (void *)destp, szsigcode); if (error != 0) return (error); @@ -3382,7 +3373,8 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) /* * Copy the image path for the rtld. */ - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; imgp->execpathp = (void *)destp; error = copyout(imgp->execpath, imgp->execpathp, execpath_len); diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 045c82aaf681..20108f37584f 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -277,12 +277,7 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) size_t execpath_len; struct proc *p; - /* Calculate string base and vector table pointers. */ p = imgp->proc; - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; destp = (uintptr_t)arginfo; @@ -293,7 +288,8 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) if (error != 0) return (error); - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; destp = rounddown2(destp, sizeof(void *)); imgp->execpathp = (void *)destp; diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 612797c2e075..2031f8b46ef9 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1690,37 +1690,26 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) uintptr_t destp, ustringp; struct ps_strings *arginfo; struct proc *p; + struct sysentvec *sysent; size_t execpath_len; - int error, szsigcode, szps; + int error, szsigcode; char canary[sizeof(long) * 8]; - szps = sizeof(pagesizes[0]) * MAXPAGESIZES; - /* - * Calculate string base and vector table pointers. - * Also deal with signal trampoline code for this exec type. - */ - if (imgp->execpath != NULL && imgp->auxargs != NULL) - execpath_len = strlen(imgp->execpath) + 1; - else - execpath_len = 0; p = imgp->proc; - szsigcode = 0; - arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; - imgp->ps_strings = arginfo; - if (p->p_sysent->sv_sigcode_base == 0) { - if (p->p_sysent->sv_szsigcode != NULL) - szsigcode = *(p->p_sysent->sv_szsigcode); - } + sysent = p->p_sysent; + + arginfo = (struct ps_strings *)sysent->sv_psstrings; destp = (uintptr_t)arginfo; + imgp->ps_strings = arginfo; /* - * install sigcode + * Install sigcode. */ - if (szsigcode != 0) { + if (sysent->sv_sigcode_base == 0 && sysent->sv_szsigcode != NULL) { + szsigcode = *(sysent->sv_szsigcode); destp -= szsigcode; destp = rounddown2(destp, sizeof(void *)); - error = copyout(p->p_sysent->sv_sigcode, (void *)destp, - szsigcode); + error = copyout(sysent->sv_sigcode, (void *)destp, szsigcode); if (error != 0) return (error); } @@ -1728,7 +1717,8 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) /* * Copy the image path for the rtld. */ - if (execpath_len != 0) { + if (imgp->execpath != NULL && imgp->auxargs != NULL) { + execpath_len = strlen(imgp->execpath) + 1; destp -= execpath_len; destp = rounddown2(destp, sizeof(void *)); imgp->execpathp = (void *)destp; @@ -1751,13 +1741,13 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) /* * Prepare the pagesizes array. */ - destp -= szps; + imgp->pagesizeslen = sizeof(pagesizes[0]) * MAXPAGESIZES; + destp -= imgp->pagesizeslen; destp = rounddown2(destp, sizeof(void *)); imgp->pagesizes = (void *)destp; - error = copyout(pagesizes, imgp->pagesizes, szps); + error = copyout(pagesizes, imgp->pagesizes, imgp->pagesizeslen); if (error != 0) return (error); - imgp->pagesizeslen = szps; /* * Allocate room for the argument and environment strings.