From nobody Mon Jan 31 14:56:37 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 157E21995051; Mon, 31 Jan 2022 14:56:38 +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 4JnWNj71RMz4T22; Mon, 31 Jan 2022 14:56:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643640998; 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=fQpKA4xIWi//VtcSv/K5iDANa9pr68LdyghhX4odOYU=; b=n+xMuRKg6A/SUZwrDUdKY+fVynu1SsmTlIGbpLLJF3XAkC9SfJSkghEsPZh2IoKbAfFY5F KqkR5BBbcHx8J0kFyy8+iZhRCjtJoPDm+WgerbnfBIWz0WE8/O7n32t5wvNh0nkMNdYsjz dHBI/q6NVdBYWo673Gx+g0ZfyVo3wjBFXII832qgTdKVp4CGqoBMsZNTcc2AB5fQppgBpX eE6I5OHpqTtzw5UOosEkberKBYEZ9Kb/6vpvPPXYaRotlJwpeN4Xmpnso+N5llySsZUy0L cXcqN+3aJR0hxrrasqsofP0rUImqk+TGecIvmQB4U4gaODiaWPGGzaXpR4jd/w== 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 CBB761E5C7; Mon, 31 Jan 2022 14:56:37 +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 20VEubbg082239; Mon, 31 Jan 2022 14:56:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20VEubZE082238; Mon, 31 Jan 2022 14:56:37 GMT (envelope-from git) Date: Mon, 31 Jan 2022 14:56:37 GMT Message-Id: <202201311456.20VEubZE082238@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: d247611467e0 - stable/13 - exec: Introduce the PROC_PS_STRINGS() macro 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: d247611467e079f34a1a3f762e2a18c00a3f2bdd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643640998; 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=fQpKA4xIWi//VtcSv/K5iDANa9pr68LdyghhX4odOYU=; b=NIIZaJg8pMmhdiFdSE1WpZeJMTJ9ta9bB9OWNcIRkkQxpb7Wb+6WhDhRZZCqA8yqht2hYo UM0ceE5cNH/gEv3UFIO4sG7Q8N5ax9cK15pajF49VbiyMY6X5phTqHQ7IGq6tUqTEqlUpa e+piSirfe3dtmmwEsmTP1t2v+PY4QM6+h3mZumL8SrLYrJX6Poay9qadL6gym18HK0ukrh Ce/r7QLjuMfy5JeWXX2+EeI+OFlsOycQSsyMI7iZD/w3ahS0lbFhBTTIVlWEXaJQlLAo7Q fnjj8kkQDkjE+nh6Ee+9/GjwMPRp+nuLCUT0WSrRLBmd9iLEMVVUI/1PpgOC7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643640998; a=rsa-sha256; cv=none; b=O/r/Qn3dPbVJma3D3vXGH3RvPDq6r6GxRh/sqHgZ/PCbGhHqrPdkpXHVpqpFKFxA0u6Pz1 jWNxmxnEw+yM+VNiegwudTGK6x3tmJoB+V1FE9EdBczi+3N7vEU6KDtaIiz6O1s7zT2OGR svnLV4iWwO8HbY/O4afxx7zhKMuX6NBM8x62pfdHJVT5+YLQykOs23LH5UtWPpIaUDraQq 701fOEMxV7oayIC+25W9gY/94jJ7hlxvNEZ2WWtD4KI6WQ8nkEcJc4QeWTE7ef6gna7UAI dNoFsSzwJEoI9Q8SuzIw6Nw8XcePQbVpZSaipsdXjiJAK6AnZlMHNM53/lcY6A== 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=d247611467e079f34a1a3f762e2a18c00a3f2bdd commit d247611467e079f34a1a3f762e2a18c00a3f2bdd Author: Mark Johnston AuthorDate: 2022-01-17 16:42:28 +0000 Commit: Mark Johnston CommitDate: 2022-01-31 14:46:57 +0000 exec: Introduce the PROC_PS_STRINGS() macro Rather than fetching the ps_strings address directly from a process' sysentvec, use this macro. With stack address randomization the ps_strings address is no longer fixed. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit 706f4a81a81250a326ea25914e7effe1768f1a37) --- sys/amd64/ia32/ia32_signal.c | 2 +- sys/amd64/ia32/ia32_syscall.c | 2 +- sys/amd64/linux/linux_sysvec.c | 2 +- sys/arm/arm/exec_machdep.c | 8 +++++++- sys/arm64/arm64/freebsd32_machdep.c | 10 ++++++++-- sys/arm64/linux/linux_sysvec.c | 2 +- sys/compat/freebsd32/freebsd32_misc.c | 2 +- sys/i386/i386/exec_machdep.c | 4 ++-- sys/i386/linux/linux_sysvec.c | 4 ++-- sys/kern/imgact_elf.c | 4 ++-- sys/kern/kern_exec.c | 18 ++++++++---------- sys/kern/kern_proc.c | 20 ++++++++++---------- sys/riscv/riscv/exec_machdep.c | 7 ++++++- sys/sys/exec.h | 1 + 14 files changed, 51 insertions(+), 35 deletions(-) diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c index 1349954f40a7..2d807c09a187 100644 --- a/sys/amd64/ia32/ia32_signal.c +++ b/sys/amd64/ia32/ia32_signal.c @@ -422,7 +422,7 @@ ia32_osendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) } regs->tf_rsp = (uintptr_t)fp; - regs->tf_rip = p->p_sysent->sv_psstrings - + regs->tf_rip = PROC_PS_STRINGS(p) - (_binary_elf_vdso32_so_1_end - _binary_elf_vdso32_so_1_start) + VDSO_IA32_OSIGCODE_OFFSET; regs->tf_rflags &= ~(PSL_T | PSL_D); diff --git a/sys/amd64/ia32/ia32_syscall.c b/sys/amd64/ia32/ia32_syscall.c index 495d6dc84887..0104a5f91c99 100644 --- a/sys/amd64/ia32/ia32_syscall.c +++ b/sys/amd64/ia32/ia32_syscall.c @@ -266,7 +266,7 @@ setup_lcall_gate(void) bzero(&uap, sizeof(uap)); uap.start = 0; uap.num = 1; - lcall_addr = curproc->p_sysent->sv_psstrings - + lcall_addr = PROC_PS_STRINGS(curproc) - (_binary_elf_vdso32_so_1_end - _binary_elf_vdso32_so_1_start) + VDSO_LCALL_TRAMP_OFFSET; bzero(&desc, sizeof(desc)); diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index 03e17d851a8d..093360537574 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -328,7 +328,7 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) struct proc *p; p = imgp->proc; - arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; + arginfo = (struct ps_strings *)PROC_PS_STRINGS(p); destp = (uintptr_t)arginfo; if (imgp->execpath != NULL && imgp->auxargs != NULL) { diff --git a/sys/arm/arm/exec_machdep.c b/sys/arm/arm/exec_machdep.c index 3b952463b1ad..865fc4d86288 100644 --- a/sys/arm/arm/exec_machdep.c +++ b/sys/arm/arm/exec_machdep.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -63,6 +64,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include +#include + /* * Clear registers on exec */ @@ -340,7 +346,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) if (sysent->sv_sigcode_base != 0) tf->tf_usr_lr = (register_t)sysent->sv_sigcode_base; else - tf->tf_usr_lr = (register_t)(sysent->sv_psstrings - + tf->tf_usr_lr = (register_t)(PROC_PS_STRINGS(p) - *(sysent->sv_szsigcode)); /* Set the mode to enter in the signal handler */ #if __ARM_ARCH >= 7 diff --git a/sys/arm64/arm64/freebsd32_machdep.c b/sys/arm64/arm64/freebsd32_machdep.c index b1e070feb4f6..f87e4342cfbd 100644 --- a/sys/arm64/arm64/freebsd32_machdep.c +++ b/sys/arm64/arm64/freebsd32_machdep.c @@ -27,7 +27,8 @@ #include __FBSDID("$FreeBSD$"); -#include +#include +#include #include #include #include @@ -42,6 +43,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include +#include + extern void freebsd32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask); /* @@ -394,7 +400,7 @@ freebsd32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) if (sysent->sv_sigcode_base != 0) tf->tf_x[14] = (register_t)sysent->sv_sigcode_base; else - tf->tf_x[14] = (register_t)(sysent->sv_psstrings - + tf->tf_x[14] = (register_t)(PROC_PS_STRINGS(p) - *(sysent->sv_szsigcode)); /* Set the mode to enter in the signal handler */ if ((register_t)catcher & 1) diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index 50bd53d4b08c..0a56cdc4f299 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -232,7 +232,7 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) int argc, envc, error; p = imgp->proc; - arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; + arginfo = (struct ps_strings *)PROC_PS_STRINGS(p); destp = (uintptr_t)arginfo; if (imgp->execpath != NULL && imgp->auxargs != NULL) { diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index 2360d28c15d0..3b62cf582866 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -3357,7 +3357,7 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) sysent = imgp->sysent; - arginfo = (struct freebsd32_ps_strings *)sysent->sv_psstrings; + arginfo = (struct freebsd32_ps_strings *)PROC_PS_STRINGS(imgp->proc); imgp->ps_strings = arginfo; destp = (uintptr_t)arginfo; diff --git a/sys/i386/i386/exec_machdep.c b/sys/i386/i386/exec_machdep.c index 13628aba7ab1..1f0a9a47a198 100644 --- a/sys/i386/i386/exec_machdep.c +++ b/sys/i386/i386/exec_machdep.c @@ -238,7 +238,7 @@ osendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) szosigcode; } else { /* a.out sysentvec does not use shared page */ - regs->tf_eip = p->p_sysent->sv_psstrings - szosigcode; + regs->tf_eip = PROC_PS_STRINGS(p) - szosigcode; } regs->tf_eflags &= ~(PSL_T | PSL_D); regs->tf_cs = _ucodesel; @@ -523,7 +523,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) regs->tf_esp = (int)sfp; regs->tf_eip = p->p_sysent->sv_sigcode_base; if (regs->tf_eip == 0) - regs->tf_eip = p->p_sysent->sv_psstrings - szsigcode; + regs->tf_eip = PROC_PS_STRINGS(p) - szsigcode; regs->tf_eflags &= ~(PSL_T | PSL_D); regs->tf_cs = _ucodesel; regs->tf_ds = _udatasel; diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 20108f37584f..1478ff0bf163 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -198,7 +198,7 @@ linux_copyout_auxargs(struct image_params *imgp, uintptr_t base) p = imgp->proc; issetugid = imgp->proc->p_flag & P_SUGID ? 1 : 0; - arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; + arginfo = (struct ps_strings *)PROC_PS_STRINGS(p); uplatform = (Elf32_Addr *)((caddr_t)arginfo - linux_szplatform); args = (Elf32_Auxargs *)imgp->auxargs; argarray = pos = malloc(LINUX_AT_COUNT * sizeof(*pos), M_TEMP, @@ -278,7 +278,7 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) struct proc *p; p = imgp->proc; - arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; + arginfo = (struct ps_strings *)PROC_PS_STRINGS(p); destp = (uintptr_t)arginfo; /* Install LINUX_PLATFORM. */ diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 721c24af7fe6..4bba6b21153b 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2662,9 +2662,9 @@ __elfN(note_procstat_psstrings)(void *arg, struct sbuf *sb, size_t *sizep) KASSERT(*sizep == size, ("invalid size")); structsize = sizeof(ps_strings); #if defined(COMPAT_FREEBSD32) && __ELF_WORD_SIZE == 32 - ps_strings = PTROUT(p->p_sysent->sv_psstrings); + ps_strings = PTROUT(PROC_PS_STRINGS(p)); #else - ps_strings = p->p_sysent->sv_psstrings; + ps_strings = PROC_PS_STRINGS(p); #endif sbuf_bcat(sb, &structsize, sizeof(structsize)); sbuf_bcat(sb, &ps_strings, sizeof(ps_strings)); diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 97857c82f7a7..301490b9ad28 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -160,19 +160,18 @@ static int sysctl_kern_ps_strings(SYSCTL_HANDLER_ARGS) { struct proc *p; - int error; + vm_offset_t ps_strings; p = curproc; #ifdef SCTL_MASK32 if (req->flags & SCTL_MASK32) { unsigned int val; - val = (unsigned int)p->p_sysent->sv_psstrings; - error = SYSCTL_OUT(req, &val, sizeof(val)); - } else + val = (unsigned int)PROC_PS_STRINGS(p); + return (SYSCTL_OUT(req, &val, sizeof(val))); + } #endif - error = SYSCTL_OUT(req, &p->p_sysent->sv_psstrings, - sizeof(p->p_sysent->sv_psstrings)); - return error; + ps_strings = PROC_PS_STRINGS(p); + return (SYSCTL_OUT(req, &ps_strings, sizeof(ps_strings))); } static int @@ -1669,9 +1668,8 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) p = imgp->proc; sysent = p->p_sysent; - arginfo = (struct ps_strings *)sysent->sv_psstrings; - destp = (uintptr_t)arginfo; - imgp->ps_strings = arginfo; + destp = PROC_PS_STRINGS(p); + arginfo = imgp->ps_strings = (void *)destp; /* * Install sigcode. diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index dc3068c29514..063fe2eb1fe2 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1838,8 +1838,8 @@ get_proc_vector32(struct thread *td, struct proc *p, char ***proc_vectorp, int i, error; error = 0; - if (proc_readmem(td, p, (vm_offset_t)p->p_sysent->sv_psstrings, &pss, - sizeof(pss)) != sizeof(pss)) + if (proc_readmem(td, p, PROC_PS_STRINGS(p), &pss, sizeof(pss)) != + sizeof(pss)) return (ENOMEM); switch (type) { case PROC_ARG: @@ -1914,8 +1914,8 @@ get_proc_vector(struct thread *td, struct proc *p, char ***proc_vectorp, if (SV_PROC_FLAG(p, SV_ILP32) != 0) return (get_proc_vector32(td, p, proc_vectorp, vsizep, type)); #endif - if (proc_readmem(td, p, (vm_offset_t)p->p_sysent->sv_psstrings, &pss, - sizeof(pss)) != sizeof(pss)) + if (proc_readmem(td, p, PROC_PS_STRINGS(p), &pss, sizeof(pss)) != + sizeof(pss)) return (ENOMEM); switch (type) { case PROC_ARG: @@ -2981,13 +2981,13 @@ sysctl_kern_proc_ps_strings(SYSCTL_HANDLER_ARGS) * process. */ ps_strings32 = SV_PROC_FLAG(p, SV_ILP32) != 0 ? - PTROUT(p->p_sysent->sv_psstrings) : 0; + PTROUT(PROC_PS_STRINGS(p)) : 0; PROC_UNLOCK(p); error = SYSCTL_OUT(req, &ps_strings32, sizeof(ps_strings32)); return (error); } #endif - ps_strings = p->p_sysent->sv_psstrings; + ps_strings = PROC_PS_STRINGS(p); PROC_UNLOCK(p); error = SYSCTL_OUT(req, &ps_strings, sizeof(ps_strings)); return (error); @@ -3104,9 +3104,9 @@ sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS) *sv->sv_szsigcode : (uintptr_t)sv->sv_szsigcode); } else { - kst32.ksigtramp_start = sv->sv_psstrings - + kst32.ksigtramp_start = PROC_PS_STRINGS(p) - *sv->sv_szsigcode; - kst32.ksigtramp_end = sv->sv_psstrings; + kst32.ksigtramp_end = PROC_PS_STRINGS(p); } } PROC_UNLOCK(p); @@ -3121,9 +3121,9 @@ sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS) ((sv->sv_flags & SV_DSO_SIG) == 0 ? *sv->sv_szsigcode : (uintptr_t)sv->sv_szsigcode); } else { - kst.ksigtramp_start = (char *)sv->sv_psstrings - + kst.ksigtramp_start = (char *)PROC_PS_STRINGS(p) - *sv->sv_szsigcode; - kst.ksigtramp_end = (char *)sv->sv_psstrings; + kst.ksigtramp_end = (char *)PROC_PS_STRINGS(p); } PROC_UNLOCK(p); error = SYSCTL_OUT(req, &kst, sizeof(kst)); diff --git a/sys/riscv/riscv/exec_machdep.c b/sys/riscv/riscv/exec_machdep.c index e06cc97eca9a..e71279e039d2 100644 --- a/sys/riscv/riscv/exec_machdep.c +++ b/sys/riscv/riscv/exec_machdep.c @@ -65,6 +65,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include +#include + #ifdef FPE #include #endif @@ -409,7 +414,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) if (sysent->sv_sigcode_base != 0) tf->tf_ra = (register_t)sysent->sv_sigcode_base; else - tf->tf_ra = (register_t)(sysent->sv_psstrings - + tf->tf_ra = (register_t)(PROC_PS_STRINGS(p) - *(sysent->sv_szsigcode)); CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_sepc, diff --git a/sys/sys/exec.h b/sys/sys/exec.h index c7b3aa8b9550..ccd7eb0ecd7d 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -77,6 +77,7 @@ struct execsw { * Prefer the kern.ps_strings or kern.proc.ps_strings sysctls to this constant. */ #define PS_STRINGS (USRSTACK - sizeof(struct ps_strings)) +#define PROC_PS_STRINGS(p) ((p)->p_sysent->sv_psstrings) int exec_map_first_page(struct image_params *); void exec_unmap_first_page(struct image_params *);