Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Feb 2012 02:17:25 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Dmitry Mikulin <dmitrym@juniper.net>
Cc:        freebsd-current Current <freebsd-current@freebsd.org>, Marcel Moolenaar <marcelm@juniper.net>
Subject:   Re: [ptrace] please review follow fork/exec changes
Message-ID:  <20120210001725.GJ3283@deviant.kiev.zoral.com.ua>
In-Reply-To: <4F34311A.9050702@juniper.net>
References:  <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> <20120209122908.GD3283@deviant.kiev.zoral.com.ua> <4F34311A.9050702@juniper.net>

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

--nKzfxXxTXZ/rSi7L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Feb 09, 2012 at 12:48:26PM -0800, Dmitry Mikulin wrote:
>=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 ?
>=20
> I was trying to avoid making ugly changes in gdb if it was possible not t=
o=20
> make ugly changes in the kernel. I changed gdb to work without=20
> PT_FOLLOW_EXEC.
So, does the patch below helps you, or did I missed something again ?

>=20
> >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.
>=20
> yes, the PL_FLAG_CHILD part works for me.
> Please commit it and we can move on to the next part of the review.

Committed as r231320. Below is what left for PT_FOLLOWEXEC.

diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 2060efe..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,8 +1147,11 @@ kern_ptrace(struct thread *td, int req, pid_t pid, v=
oid *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;
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 0245e88..bec7223 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -614,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 8a02495..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,14 +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_CHILD	0x80	/* I am from 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 */

--nKzfxXxTXZ/rSi7L
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk80YhUACgkQC3+MBN1Mb4iXogCgueoz4NqyA8JcUVVKKwL57hfK
o44AoOn3muFIXYa6kAU4soUxv373KBAq
=YwH6
-----END PGP SIGNATURE-----

--nKzfxXxTXZ/rSi7L--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120210001725.GJ3283>