From nobody Tue Mar 01 17:41:57 2022 X-Original-To: dev-commits-src-main@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 63A0A19DC605; Tue, 1 Mar 2022 17:41:59 +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 4K7Ph64yx4z4ZTk; Tue, 1 Mar 2022 17:41:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646156519; 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=1VA4rdpQtRwGndiafjqUTzP1bQ2BYA4ESE/S7Oz0RTk=; b=rbHLCPqBic4/EDiQULTIDJb4ilk/Uo6DyhmpnVnjHidLe+9mdp696FqUGCQ/EgxYyQ38vn Ae9U11Vgjtfj/PubO+aRefzv6ZXJHvO5xxhgBNspaVq9R2FCvQkzneCtrdofmYF8BPIAtJ Z8sJ9p6rtQ0haL65pxqIoqo0958Vg+0+SVYkL46MORdy1TullPBsrXqjQkjFm3A4371FNH kHPUg2sPyNiXgfZtBJuUIkc8DBTLD/d4AxmtF5V49pStyoG95PrGS53qznccA/GyvAIs72 0IW7HNEPn7qaYlJHC/JTafXMefcLppwQMgu0KNBJH9WFGLOy9anK6gkBBYei2A== 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 E5B9A13E2F; Tue, 1 Mar 2022 17:41:57 +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 221Hfvwf093353; Tue, 1 Mar 2022 17:41:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 221Hfvg3093352; Tue, 1 Mar 2022 17:41:57 GMT (envelope-from git) Date: Tue, 1 Mar 2022 17:41:57 GMT Message-Id: <202203011741.221Hfvg3093352@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 3a56cfedbc70 - main - fasttrap: Avoid creating WX mappings List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 3a56cfedbc701f8026d38c0d808c614c9f0572ae Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646156519; 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=1VA4rdpQtRwGndiafjqUTzP1bQ2BYA4ESE/S7Oz0RTk=; b=as3KiMMkfpPZqXT0N/fCQNejFMh5NlX9kWtmAAY05Ll6J+tvD0n30UjHkk8APIkAFGEYMd zgjaU5VvFaBSWinKQ2OA4Vltqj0+vZjsD2l5d8oSSFRLFFYUT55VxYPqxUGAkmocLC+B/m EqdVgQHZsEdZTnwMLWNr7zFR+EjhQ62Lz4boGzZmwSQg3onIfWlIG71CmGR3xwhsu/pVze zZ5/05BfpGn7fWuN4qALP5ZSshRQPfq+qblNk0tdPUsH9FDQ3F5amQ6Mjd1yCcXKKdLbRt dKa78g3lVMH3rWuhehW9rHNIbSRf2lmtkNGw0P8K2GHunU/BA8xfSVn23vL1Yg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646156519; a=rsa-sha256; cv=none; b=EQe/9Jk3AtK7Lnlb3O+Fu3PGueL8ToiqTuNbJW4elqY8CLs9N9LR08o3ICGAcDaUU1lyOU 3Rkl30r4hn6EyR9VcgS76Io5IWrQCDI9yNMw6MzxZ2brLaq8XRilRhxicu+yirEBC7JJGj XBuZO+0cxfV5zrlGPa9NK0TUQmAbpFwZoJ6TebkTBrwXa4pvjXJywvANjEkX+BJ/hcsTOe nGWaJ7tAd+DMBfW6YTu93gN8d26x7TazQrglMx6vGQG0JCEKoe2s9wfuOVhMbfugBFBRe4 xTa2wIHkoUJNrwEC8YW2jocToFqJ4338VNQAXubIcDbThS+jL4ur8AU1e3g2zg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3a56cfedbc701f8026d38c0d808c614c9f0572ae commit 3a56cfedbc701f8026d38c0d808c614c9f0572ae Author: Mark Johnston AuthorDate: 2022-03-01 16:53:42 +0000 Commit: Mark Johnston CommitDate: 2022-03-01 17:40:35 +0000 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 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34304 --- sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c | 5 +++-- sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c | 2 +- 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 f92070d8088d..c40b4b94e38d 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;