From 2829c3921d2870310f2a053fc4251a8c59193054 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sun, 10 Jul 2022 16:13:59 +0000 Subject: [PATCH] ptrace(2): Fix edge cases around lid=0. --- sys/kern/sys_process_lwpstatus.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/kern/sys_process_lwpstatus.c b/sys/kern/sys_process_lwpstatus.c index 45d0682dbdee..f7a09323e02b 100644 --- a/sys/kern/sys_process_lwpstatus.c +++ b/sys/kern/sys_process_lwpstatus.c @@ -56,8 +56,7 @@ void ptrace_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls) { - KASSERT(l->l_lid == pls->pl_lwpid); - + pls->pl_lwpid = l->l_lid; memcpy(&pls->pl_sigmask, &l->l_sigmask, sizeof(pls->pl_sigmask)); memcpy(&pls->pl_sigpend, &l->l_sigpend.sp_set, sizeof(pls->pl_sigpend)); @@ -79,21 +78,24 @@ void process_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls) { - pls->pl_lwpid = l->l_lid; - ptrace_read_lwpstatus(l, pls); } int ptrace_update_lwp(struct proc *t, struct lwp **lt, lwpid_t lid) { - if (lid == 0 || lid == (*lt)->l_lid || t->p_nlwps == 1) + + if (lid == (*lt)->l_lid) return 0; mutex_enter(t->p_lock); lwp_delref2(*lt); - *lt = lwp_find(t, lid); + if (lid == 0) { + *lt = lwp_find_first(t); + } else { + *lt = lwp_find(t, lid); + } if (*lt == NULL) { mutex_exit(t->p_lock); return ESRCH;