Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jun 2018 10:23:06 +0300
From:      Yanko Yankulov <yanko.yankulov@gmail.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        freebsd-emulation@freebsd.org
Subject:   Re: two proposed linuxulator fixes + ptrace
Message-ID:  <CABTd0_oR8wezbhjqx53npuhKYmT5pZtSOw7py2iHjW%2Bmp8GjKw@mail.gmail.com>
In-Reply-To: <20180614141604.GA2493@kib.kiev.ua>
References:  <CABTd0_pqdAtHMH9gSJdebstASuoomYw1XLbkbbsMCUvtE-=vDA@mail.gmail.com> <20180614101324.GW2493@kib.kiev.ua> <CABTd0_p=5cqsN5TKtEWXY_oQXtGdJOyMHEzjoUJeaYcKShLCRQ@mail.gmail.com> <20180614123659.GZ2493@kib.kiev.ua> <CABTd0_pdF9RGmJHYDoL5f2ctewfWU_e0DsF=hkuqTVtFW2uhtA@mail.gmail.com> <20180614141604.GA2493@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Thanks for the hint. It turned that we already have all the info due to the
call to  fill_kinfo_proc(p, &kp);

Proper patch attached. Verified with the ptrace patch, that correct values
are reported in PPid & TracerPid.

Regarding the ptrace patch - for some reason I am not receiving a
registration mail from reviews.freebsd.org so I am a bit stuck.

Best,

On Thu, Jun 14, 2018 at 5:16 PM, Konstantin Belousov <kostikbel@gmail.com>
wrote:

> On Thu, Jun 14, 2018 at 04:11:52PM +0300, Yanko Yankulov wrote:
> > > > > For the patch 1, TracePid, can you explain what is the meaning of
> the
> > > > > pid reported ?
> > > > >
> > > > > The TracerPid is the PID of the process currently ptrace-ing the
> > > process.
> > > > TracerPid 0 means no active tracer. So the patch is not semantically
> > > > correct as it always reports no tracer, but it got the program
> running.
> > > Ok, but what is the tracer ?  Is it ptrace(2) debugger, or something
> > > else ?
> > >
> >
> > Yes, any ptrace(2) debugger/truss/strace/whatever. The Linux code is:
> >
> > tracer = ptrace_parent(p);
> > if (tracer)
> >       tpid = task_pid_nr_ns(tracer, ns);
>
> I think this should be like
>         PROC_LOCK(p);
>         tpid = (p->p_flag & P_TRACED) != 0 ? p->p_ppid : 0;
>         PROC_UNLOCK(p);
>         sx_slock(&proctree_lock);
>         parent_pid = proc_realparent(p)->p_pid;
>         sx_sunlock(&proctree_lock);
>

[-- Attachment #2 --]
From 42fdd8b6403e8a03611ccba8a0d75aa9bfe253b8 Mon Sep 17 00:00:00 2001
From: Yanko Yankulov <yanko.yankulov@gmail.com>
Date: Thu, 14 Jun 2018 10:44:22 +0300
Subject: [PATCH] linprocfs: /proc/pid/status add TracerPid

And return real parent if traced
---
 sys/compat/linprocfs/linprocfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 586259f28315..2492abffebb9 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -803,8 +803,8 @@ linprocfs_doprocstatus(PFS_FILL_ARGS)
 	 * Credentials
 	 */
 	sbuf_printf(sb, "Pid:\t%d\n",		p->p_pid);
-	sbuf_printf(sb, "PPid:\t%d\n",		p->p_pptr ?
-						p->p_pptr->p_pid : 0);
+	sbuf_printf(sb, "PPid:\t%d\n",		kp.ki_ppid );
+	sbuf_printf(sb, "TracerPid:\t%d\n",	kp.ki_tracer );
 	sbuf_printf(sb, "Uid:\t%d %d %d %d\n",	p->p_ucred->cr_ruid,
 						p->p_ucred->cr_uid,
 						p->p_ucred->cr_svuid,
-- 
2.17.1


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CABTd0_oR8wezbhjqx53npuhKYmT5pZtSOw7py2iHjW%2Bmp8GjKw>