From fe894a370556e5b173a8893cdcde6323ff79cc57 Mon Sep 17 00:00:00 2001 From: Dmitry Chagin Date: Mon, 25 Apr 2022 10:21:51 +0300 Subject: [PATCH] linux(4): Check that the thread tid in the thread group pid in linux_tdfind(). MFC after: 2 weeks --- sys/compat/linux/linux_misc.c | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 0579ac1a03c..252c6e0737c 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2710,34 +2710,34 @@ linux_tdfind(struct thread *td, lwpid_t tid, pid_t pid) tdt = NULL; if (tid == 0 || tid == td->td_tid) { - tdt = td; - PROC_LOCK(tdt->td_proc); + if (pid != -1 && td->td_proc->p_pid != pid) + return (NULL); + PROC_LOCK(td->td_proc); + return (td); } else if (tid > PID_MAX) - tdt = tdfind(tid, pid); - else { - /* - * Initial thread where the tid equal to the pid. - */ - p = pfind(tid); - if (p != NULL) { - if (SV_PROC_ABI(p) != SV_ABI_LINUX) { - /* - * p is not a Linuxulator process. - */ - PROC_UNLOCK(p); - return (NULL); - } - FOREACH_THREAD_IN_PROC(p, tdt) { - em = em_find(tdt); - if (tid == em->em_tid) - return (tdt); - } - PROC_UNLOCK(p); - } - return (NULL); - } + return (tdfind(tid, pid)); - return (tdt); + /* + * Initial thread where the tid equal to the pid. + */ + p = pfind(tid); + if (p != NULL) { + if (SV_PROC_ABI(p) != SV_ABI_LINUX || + (pid != -1 && tid != pid)) { + /* + * p is not a Linuxulator process. + */ + PROC_UNLOCK(p); + return (NULL); + } + FOREACH_THREAD_IN_PROC(p, tdt) { + em = em_find(tdt); + if (tid == em->em_tid) + return (tdt); + } + PROC_UNLOCK(p); + } + return (NULL); } void