From nobody Thu Dec 22 22:10:56 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 4NdPds286tz1J1xC; Thu, 22 Dec 2022 22:10:57 +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 4NdPds1FmJz3jmP; Thu, 22 Dec 2022 22:10:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671747057; 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=a/GS7toNDtyKWzxdeL0h6Yj2brK7boLTwW+5gLXlJwc=; b=UwsLmlQZzXISBxqKRN5Ae8PINGcNfIC0rScNTVnNKZgadz/kw9v/DdulGq87hQzjRi4ZdY lY+8bTuVaRj6xNid6sNMhCdvJN/bQMj4N9l0u8UCSXK1HA1YdEcM24PnL/aPj4i67mFqZj T7ePlKfey8Yy71ZJY7o8kJLalFLIWqUq+zIGSRDRHsR1Kzs6GKxuYE8EkZhuyIxega4CTC F7uEFx4+wsNL7j2wQGmpPM2Xbz+7i1o3NiUE3ER9r3vB3DRG2msvnApvUcUVQ6ahtAJUvu ixj+IwS3xtSfMHG5ZD9f+o3Q3+uVdEhKEKLI9uOU54CcC9JvZNMTlVoI2S7Irw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671747057; 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=a/GS7toNDtyKWzxdeL0h6Yj2brK7boLTwW+5gLXlJwc=; b=NXrE+fbzmF0li1TpNo1SP6e4hehhmkwwyjFo2eYMSMfxOyaP2jKqOknqvKjS0IA0xdLo3x yLLbrD+r21/Rt8GCQRduM7MnKdfj3VCTcO0hbixG8DsT/DMz88Ji83tcNtNcVv60uBf9+P K0zWmnsZnoiWoy+DgkjC1r0AMVf9t+Pn9xa8JbjsvYb305mCG/C/PO6/K/R/9iOY8EgzPb uhlgIBM0qQhEjyJsci3tNRFneEj2elngqbw3LumC68Xz0kt0tDaT/rvZK7lAo1gpkY+x+t usbCaZYsM2m0lxcNmwrCA1LGu02GGUmJsJuQnBBe1eBCDRonssqjLMX/h0vCvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671747057; a=rsa-sha256; cv=none; b=vMB63pjOXrviDEeFyBncVRmt4NK4sghyOu1dKRxtsW4fP4nlpn9efIiAv3rhwYAYn7JiSJ rN1e6VDHa27kt1HEx0IQ+lxqNf5dYlgOt6O8EuVz3Y23iP5foZF8cLtflc94H+iLVU354S 4oie4Od1OTaSnjKg7a4Q6jHTtnxh6vKswMWF+VQdG3TKh4oMph0hirziZdLo0Z+E3Sz4fQ pJ9GcAvaISPSDc3RQ24+LZK16m2MZRX7OK733sNeSsDRBJhM61StNXRlPrNAuh1Pi7B0Sx cb/lItSUQTF31np6FUr7iOPIRIz4j12QvuYOYq/Py8IUNZRdgCGfUZvbi8pmyQ== 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 4NdPds08vdz196r; Thu, 22 Dec 2022 22:10: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 2BMMAuL2038828; Thu, 22 Dec 2022 22:10:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BMMAufN038816; Thu, 22 Dec 2022 22:10:56 GMT (envelope-from git) Date: Thu, 22 Dec 2022 22:10:56 GMT Message-Id: <202212222210.2BMMAufN038816@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: a98613f23892 - main - ptrace(2): document PT_SC_REMOTE 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a98613f2389227effeb9d86e47e53ea01ecddfe5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a98613f2389227effeb9d86e47e53ea01ecddfe5 commit a98613f2389227effeb9d86e47e53ea01ecddfe5 Author: Konstantin Belousov AuthorDate: 2022-12-02 03:00:08 +0000 Commit: Konstantin Belousov CommitDate: 2022-12-22 21:11:42 +0000 ptrace(2): document PT_SC_REMOTE Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D37590 --- lib/libc/sys/ptrace.2 | 73 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 01d83897a78b..e75d3b218f28 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -976,10 +976,44 @@ The size of .Vt "struct ptrace_coredump" must be passed in .Fa data . -.Pp -The process must be stopped before dumping core. +.It Dv PT_SC_REMOTE +Request to execute a syscall in the context of the traced process, +in the specified thread. +The +.Fa addr +argument must point to the +.Vt "struct ptrace_sc_remote" , +which describes the requested syscall and its arguments, and receives +the result. +The size of +.Vt "struct ptrace_sc_remote" +must be passed in +.Fa data. +.Bd -literal +struct ptrace_sc_remote { + struct ptrace_sc_ret pscr_ret; + u_int pscr_syscall; + u_int pscr_nargs; + u_long *pscr_args; +}; +.Ed +The +.Dv pscr_syscall +contains the syscall number to execute, the +.Dv pscr_nargs +is the number of supplied arguments, which are supplied in the +.Dv pscr_args +array. +Result of the execution is returned in the +.Dv pscr_ret +member. +Note that the request and its result do not affect the returned value from +the currently executed syscall, if any. +.El +.Sh PT_COREDUMP and PT_SC_REMOTE usage +The process must be stopped before dumping or initiating a remote system call. A single thread in the target process is temporarily unsuspended -in kernel to write the dump. +in the kernel to perform the action. If the .Nm call fails before a thread is unsuspended, there is no event to @@ -996,9 +1030,38 @@ an error occurred, it is recommended to unconditionally perform with .Dv WNOHANG flag after -.Dv PT_COREDUMP , +.Dv PT_COREDUMP +and +.Dv PT_SC_REMOTE , and silently accept zero result from it. -.El +.Pp +For +.Dv PT_SC_REMOTE , +the selected thread must be stopped in the safe place, which is +currently defined as a syscall exit, or a return from kernel to +user mode (basically, a signal handler call place). +Kernel returns +.Er EBUSY +status if attempt is made to execute remote syscall at unsafe stop. +.Pp +Note that neither +.Dv kern.trap_enotcap +sysctl setting, nor the corresponding +.Xr procctl 2 +flag +.Dv PROC_TRAPCAP_CTL_ENABLE +are obeyed during the execution of the syscall by +.Dv PT_SC_REMOTE . +In other words, +.Dv SIGTRAP +signal is not sent to a process executing in capability mode, +which violated a mode access restriction. +.Pp +Note that due to the mode of execution for the remote syscall, in +particular, the setting where only one thread is allowed to run, +the syscall might block on resources owned by suspended threads. +This might result in the target process deadlock. +In this situation, the only way out is to kill the target. .Sh ARM MACHINE-SPECIFIC REQUESTS .Bl -tag -width "Dv PT_SETVFPREGS" .It Dv PT_GETVFPREGS