aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-03-01 16:53:42 +0000
committerMark Johnston <markj@FreeBSD.org>2022-03-15 15:40:47 +0000
commitc04e4ff6168a419de1d11a7b4335d9874370b60c (patch)
tree765fe976eb2a28081932dbd7548a3de64e6fc777
parent87e1a4346d908b3d4cd1fc93f97968197ab80240 (diff)
downloadsrc-c04e4ff6168a419de1d11a7b4335d9874370b60c.tar.gz
src-c04e4ff6168a419de1d11a7b4335d9874370b60c.zip
fasttrap: Avoid creating WX mappings
fasttrap instruments certain instructions by overwriting them and copying the original instruction to some per-thread scratch space which is executed after the probe fires. This trampoline jumps back to the tracepoint after executing the original instruction. The created mapping has both write and execute permissions, and so this mechanism doesn't work when allow_wx is disabled. Work around the restriction by using proc_rwmem() to write to the trampoline. Reviewed by: vangyzen Tested by: Amit <akamit91@hotmail.com> Sponsored by: The FreeBSD Foundation (cherry picked from commit 3a56cfedbc701f8026d38c0d808c614c9f0572ae)
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c5
-rw-r--r--sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c2
2 files changed, 4 insertions, 3 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
index d96d3f44182e..04ef3ecc3e8d 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
@@ -336,8 +336,9 @@ fasttrap_scraddr(struct thread *td, fasttrap_proc_t *fprc)
*/
addr = 0;
error = vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr,
- FASTTRAP_SCRBLOCK_SIZE, 0, VMFS_ANY_SPACE, VM_PROT_ALL,
- VM_PROT_ALL, 0);
+ FASTTRAP_SCRBLOCK_SIZE, 0, VMFS_ANY_SPACE,
+ VM_PROT_READ | VM_PROT_EXECUTE,
+ VM_PROT_READ | VM_PROT_EXECUTE, MAP_COPY_ON_WRITE);
if (error != KERN_SUCCESS)
goto done;
diff --git a/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c b/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c
index 502273b73157..163a8fdd13fa 100644
--- a/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c
+++ b/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c
@@ -1666,7 +1666,7 @@ fasttrap_pid_probe(struct trapframe *tf)
ASSERT(i <= sizeof (scratch));
- if (fasttrap_copyout(scratch, (char *)addr, i)) {
+ if (uwrite(curproc, scratch, i, addr) != 0) {
fasttrap_sigtrap(p, curthread, pc);
new_pc = pc;
break;