git: fdbf48835da5 - stable/14 - ptrace(2): expand ability to fetch syscall parameters
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Apr 2025 01:29:18 UTC
The branch stable/14 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=fdbf48835da5d38fa7d156bdd3e899c7664c7e08
commit fdbf48835da5d38fa7d156bdd3e899c7664c7e08
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-03-20 01:52:29 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-07 01:28:22 +0000
ptrace(2): expand ability to fetch syscall parameters
(cherry picked from commit fd5bc306ff3d8f908f36703d6ab714322f9f3c75)
---
sys/kern/kern_sig.c | 8 ++++++++
sys/kern/sys_process.c | 8 +++-----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 6661f4cd6187..8e5c9f247b57 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -345,6 +345,14 @@ ast_sig(struct thread *td, int tda)
* the postsig() loop was performed.
*/
sigfastblock_setpend(td, resched_sigs);
+
+ /*
+ * Clear td_sa.code: signal to ptrace that syscall arguments
+ * are unavailable after this point. This AST handler is the
+ * last chance for ptracestop() to signal the tracer before
+ * the tracee returns to userspace.
+ */
+ td->td_sa.code = 0;
}
static void
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index a6cc9a36643b..19fe8bcc7627 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -1174,7 +1174,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
case PT_GET_SC_ARGS:
CTR1(KTR_PTRACE, "PT_GET_SC_ARGS: pid %d", p->p_pid);
- if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) == 0
+ if (((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) == 0 &&
+ td2->td_sa.code == 0)
#ifdef COMPAT_FREEBSD32
|| (wrap32 && !safe)
#endif
@@ -1517,12 +1518,9 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
pl->pl_sigmask = td2->td_sigmask;
pl->pl_siglist = td2->td_siglist;
strcpy(pl->pl_tdname, td2->td_name);
- if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) != 0) {
+ if (td2->td_sa.code != 0) {
pl->pl_syscall_code = td2->td_sa.code;
pl->pl_syscall_narg = td2->td_sa.callp->sy_narg;
- } else {
- pl->pl_syscall_code = 0;
- pl->pl_syscall_narg = 0;
}
CTR6(KTR_PTRACE,
"PT_LWPINFO: tid %d (pid %d) event %d flags %#x child pid %d syscall %d",