From owner-freebsd-current@FreeBSD.ORG Thu Feb 9 12:29:21 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 244D4106564A for ; Thu, 9 Feb 2012 12:29:21 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 64A198FC20 for ; Thu, 9 Feb 2012 12:29:19 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q19CT9ue041337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 Feb 2012 14:29:09 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q19CT9K3068152; Thu, 9 Feb 2012 14:29:09 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q19CT8eY068151; Thu, 9 Feb 2012 14:29:08 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 9 Feb 2012 14:29:08 +0200 From: Konstantin Belousov To: Dmitry Mikulin Message-ID: <20120209122908.GD3283@deviant.kiev.zoral.com.ua> References: <20120129074843.GL2726@deviant.kiev.zoral.com.ua> <4F26E0D1.8040100@juniper.net> <20120130192727.GZ2726@deviant.kiev.zoral.com.ua> <4F2C756A.80900@juniper.net> <20120204204218.GC3283@deviant.kiev.zoral.com.ua> <4F3043E2.6090607@juniper.net> <20120207121022.GC3283@deviant.kiev.zoral.com.ua> <4F318D74.9030506@juniper.net> <4F31C89C.7010705@juniper.net> <4F3318AD.6000607@juniper.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MxTdzNviYdWQq2Ha" Content-Disposition: inline In-Reply-To: <4F3318AD.6000607@juniper.net> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-current Current , Marcel Moolenaar Subject: Re: [ptrace] please review follow fork/exec changes X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Feb 2012 12:29:21 -0000 --MxTdzNviYdWQq2Ha Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 08, 2012 at 04:51:57PM -0800, Dmitry Mikulin wrote: > The patch I sent earlier works for me. Just wanted to let you know to=20 > illustrate what I would like to see from the kernel. >=20 > I'm trying to see if there's way not to add flags with semantics similar = to=20 > TDB_EXEC. I think the problem with TDB_EXEC is that is serves a trigger f= or=20 > a stop as well as an indicator to return PL_FLAG_EXEC. And in my case I= =20 > still want to see all the stops but I only want to see the PL_FLAG_EXEC= =20 > when PT_FOLLOW_EXEC is specified. >=20 > Do you think the attached patch will do what I'd like without compromisin= g=20 > existing functionality? >=20 The semantic of PL_FLAG_EXEC up until now is very simple: it indicates that current stop occured during the first return to usermode after successful exec. The proposed patch breaks the semantic, because now some stops which satisfy the stated condition are no longer marked with the flag. That said, I am lost. You stated that you still need some stops at exec even when not PT_FOLLOW_EXEC is requested. Why usermode cannot remember whether the PT_FOLLOW_EXEC was set for the process, and ignore PL_FLAG_EXEC if not requested ? I just gave up and added PL_FLAG_EXECF, which is set when PT_FOLLOW_EXEC was set and exec is active. Would this work for your purposes ? PL_FLAG_EXECF has the same semantic as PL_FLAG_EXEC had in your follow-exec.patch. But the stop set is not changed comparing with the stock src. Are you fine with PL_FLAG_CHILD part of the changes ? If yes, I will commit it to make some progress. diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 60639c9..e447c93 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1035,7 +1035,9 @@ fork_return(struct thread *td, struct trapframe *fram= e) p->p_oppid =3D p->p_pptr->p_pid; proc_reparent(p, dbg); sx_xunlock(&proctree_lock); + td->td_dbgflags |=3D TDB_CHILD; ptracestop(td, SIGSTOP); + td->td_dbgflags &=3D ~TDB_CHILD; } else { /* * ... otherwise clear the request. diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 4510380..4f93a79 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -660,6 +660,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void= *addr, int data) case PT_TO_SCX: case PT_SYSCALL: case PT_FOLLOW_FORK: + case PT_FOLLOW_EXEC: case PT_DETACH: sx_xlock(&proctree_lock); proctree_locked =3D 1; @@ -873,6 +874,12 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi= d *addr, int data) else p->p_flag &=3D ~P_FOLLOWFORK; break; + case PT_FOLLOW_EXEC: + if (data) + p->p_flag |=3D P_FOLLOWEXEC; + else + p->p_flag &=3D ~P_FOLLOWEXEC; + break; =20 case PT_STEP: case PT_CONTINUE: @@ -936,7 +943,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void= *addr, int data) p->p_sigparent =3D SIGCHLD; } p->p_oppid =3D 0; - p->p_flag &=3D ~(P_TRACED | P_WAITED | P_FOLLOWFORK); + p->p_flag &=3D ~(P_TRACED | P_WAITED | P_FOLLOWFORK | + P_FOLLOWEXEC); =20 /* should we send SIGCHLD? */ /* childproc_continued(p); */ @@ -1139,12 +1147,17 @@ kern_ptrace(struct thread *td, int req, pid_t pid, = void *addr, int data) pl->pl_flags |=3D PL_FLAG_SCE; else if (td2->td_dbgflags & TDB_SCX) pl->pl_flags |=3D PL_FLAG_SCX; - if (td2->td_dbgflags & TDB_EXEC) + if (td2->td_dbgflags & TDB_EXEC) { pl->pl_flags |=3D PL_FLAG_EXEC; + if (p->p_flag & P_FOLLOWEXEC) + pl->pl_flags |=3D PL_FLAG_EXECF; + } if (td2->td_dbgflags & TDB_FORK) { pl->pl_flags |=3D PL_FLAG_FORKED; pl->pl_child_pid =3D td2->td_dbg_forked; } + if (td2->td_dbgflags & TDB_CHILD) + pl->pl_flags |=3D PL_FLAG_CHILD; pl->pl_sigmask =3D td2->td_sigmask; pl->pl_siglist =3D td2->td_siglist; strcpy(pl->pl_tdname, td2->td_name); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 9ebfe83..bec7223 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -384,6 +384,7 @@ do { \ process */ #define TDB_STOPATFORK 0x00000080 /* Stop at the return from fork (child only) */ +#define TDB_CHILD 0x00000100 /* New child indicator for ptrace() */ =20 /* * "Private" flags kept in td_pflags: @@ -613,6 +614,7 @@ struct proc { #define P_HWPMC 0x800000 /* Process is using HWPMCs */ =20 #define P_JAILED 0x1000000 /* Process is in jail. */ +#define P_FOLLOWEXEC 0x2000000 /* Report execs with ptrace. */ #define P_INEXEC 0x4000000 /* Process is in execve(). */ #define P_STATCHILD 0x8000000 /* Child process stopped or exited. */ #define P_INMEM 0x10000000 /* Loaded into memory. */ diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 2583d59..81cebfc 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -64,6 +64,7 @@ #define PT_SYSCALL 22 =20 #define PT_FOLLOW_FORK 23 +#define PT_FOLLOW_EXEC 24 =20 #define PT_GETREGS 33 /* get general-purpose registers */ #define PT_SETREGS 34 /* set general-purpose registers */ @@ -100,13 +101,15 @@ struct ptrace_lwpinfo { #define PL_EVENT_NONE 0 #define PL_EVENT_SIGNAL 1 int pl_flags; /* LWP flags. */ -#define PL_FLAG_SA 0x01 /* M:N thread */ -#define PL_FLAG_BOUND 0x02 /* M:N bound thread */ -#define PL_FLAG_SCE 0x04 /* syscall enter point */ -#define PL_FLAG_SCX 0x08 /* syscall leave point */ -#define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ -#define PL_FLAG_SI 0x20 /* siginfo is valid */ -#define PL_FLAG_FORKED 0x40 /* new child */ +#define PL_FLAG_SA 0x0001 /* M:N thread */ +#define PL_FLAG_BOUND 0x0002 /* M:N bound thread */ +#define PL_FLAG_SCE 0x0004 /* syscall enter point */ +#define PL_FLAG_SCX 0x0008 /* syscall leave point */ +#define PL_FLAG_EXEC 0x0010 /* exec(2) succeeded */ +#define PL_FLAG_SI 0x0020 /* siginfo is valid */ +#define PL_FLAG_FORKED 0x0040 /* child born */ +#define PL_FLAG_CHILD 0x0080 /* I am from child */ +#define PL_FLAG_EXECF 0x0100 /* exec and PT_FOLLOW_EXEC was set */ sigset_t pl_sigmask; /* LWP signal mask */ sigset_t pl_siglist; /* LWP pending signal */ struct __siginfo pl_siginfo; /* siginfo for signal */ --MxTdzNviYdWQq2Ha Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk8zvBQACgkQC3+MBN1Mb4gwrACfQFTDh7eSg379N5U1bEK5Qtfb NR8AoNADcJaE2NgEBnR3WuzSiXl9D/YX =03na -----END PGP SIGNATURE----- --MxTdzNviYdWQq2Ha--