From nobody Fri Jan 20 03:23:47 2023 X-Original-To: dev-commits-src-all@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 4NylFw0HFFz30vnf; Fri, 20 Jan 2023 03:23:48 +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 4NylFv4Frfz3nqm; Fri, 20 Jan 2023 03:23:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674185027; 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=GZhfMgzpoav5zvP0OnjBHgj1bSrS/bV6OTc9R/+F8dM=; b=c6v7s058PDtKnGwA4F0lUp0ZIcbpNuMU+LT53W+CkaIP44SajN2CPP3mklFU8RZIDq7L8G 5c48Hnlf/dor2zv32qJIdTaO0uH9tEMqocMFFh7bLlw0x3agePLT9HMuZfr2C743/24LTV NBRjmWnvq+0dXsiHIHNMXWCgXKIjaGqFn/Y49tVdBKPaLyObX8mlD9xXLRR4u8BWm71CXR 5JwcxpHseK7jJlsz0+j/qiZ223lstFQBI/qChWqmME6xWShBEkji/m7fQ519AwHQLkoXul cn3p3S76lDXpbPoyajmR9svGSli840E2fg/c+2jQ5xyQlVeUDliDD+kL/X1qIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674185027; 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=GZhfMgzpoav5zvP0OnjBHgj1bSrS/bV6OTc9R/+F8dM=; b=qpXqn0chfU6/hoEZLkMR12kbiGjGIgos0h/K3kfGVVoH/WrTl3uvuQv0y8asPN7aa7qWLn ZSNGRWrUlL8pBcs3SV5HQwtJIHi01LTJSiOfcGaQtX9uSu6uwcxZYG/2XOe5S2q6TG7rid F3deWCq9C7kxmSN53cLqrBInezsJM5fJ7j42CbF1jbskgcxR4UxiPAfFMSkztchAErjXLe z+Sarz5phbHd+9LtR/A5uVOiNfZMIO7raDSfuv/t/QkpQw44DSTbCy5XkB8WPBWu7CTwxn XWX7UrM8aQ9/qDqrnm7QplQ3WQkogYOup0+bGEKtzkGCvlr/hUKB5Mi6fAMpjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674185027; a=rsa-sha256; cv=none; b=i2fWiVUOvgMy5KYwVylt02/mCgYBAvOrFNTpjI0rCxw3d6P5ltGBIAw3mV7hLiVKrW/JSz 0MeHowf+NOp6yrdjVATuhBlRFzUaTNFhjwWR1iHJagCHaKAnemxOhKYy8Ldh+AdNtSVeGo Do+DOONifLD11CZiWd3i9mmD9AwLmXrGI9U92NGhPm0kvLehevmbEBs34me4JtuRuplZT+ f1NVT/r96FAARLvUzzA0EPdyo74rExpoTcan3lhT+OdR+QXPv0sj+JqbzkR8iJjxyhr82k 5vx02InimEqCqZys1g9ojz2AzhHlkDMoaHSIBj/EdzactDQu7Q9FgC6Lxqh1+A== 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 4NylFv3BSKzGDQ; Fri, 20 Jan 2023 03:23:47 +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 30K3NlPX042644; Fri, 20 Jan 2023 03:23:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30K3NlNE042643; Fri, 20 Jan 2023 03:23:47 GMT (envelope-from git) Date: Fri, 20 Jan 2023 03:23:47 GMT Message-Id: <202301200323.30K3NlNE042643@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: efde0099aacd - stable/13 - ptrace(2): document PT_SC_REMOTE List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: efde0099aacdb14bfcb8eb77498ccf2800219b78 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=efde0099aacdb14bfcb8eb77498ccf2800219b78 commit efde0099aacdb14bfcb8eb77498ccf2800219b78 Author: Konstantin Belousov AuthorDate: 2022-12-02 03:00:08 +0000 Commit: Konstantin Belousov CommitDate: 2023-01-20 03:21:11 +0000 ptrace(2): document PT_SC_REMOTE Tested by: pho (cherry picked from commit a98613f2389227effeb9d86e47e53ea01ecddfe5) --- 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 b107dcef97ae..a5e67c745422 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