public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* ptrace problem in 2.6.9
@ 2004-10-22 17:05 Stephane Eranian
  2004-10-23  4:53 ` Roland McGrath
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stephane Eranian @ 2004-10-22 17:05 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 501 bytes --]

Hi Roland,

I have some problems with the recent modifications to the
Ptrace infrastructure in 2.6.9 release. Basically I have
the smiple test program attached to this E-mail and it
hangs in 2.6.9 but not in 2.6.9-rc4. Somehow the first
waitpid() does not return. It is not clear to me why.
Is there something Ineed to change in the call itself?
I am running all of this on a 2-way IA-64 machine with
2.6.9. I have not tried on x86. 

I would appreciate your thoughts on this.

Thanks.

-- 
-Stephane

[-- Attachment #2: test_ptrace.c --]
[-- Type: text/plain, Size: 1693 bytes --]

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/ptrace.h>

static int p[2];

int
child(void)
{
	int ret;
	char c;

	printf("child %d started\n", getpid());
	ret = read(p[0], &c, 1);
	if (ret != 1) {
		perror("read");
		return -1;
	}
	return 0;
}

int
do_test(int argc, char **argv)
{
	int ret, status;
	pid_t pid;
	char c;

	ret = pipe(p);
	if (ret) {
		perror("pipe");
		return -1;
	}

	pid = fork();
	switch(pid) {
		case 0: close(p[1]); exit(child());

		case -1: perror("fork"); return -1;

		default: close(p[0]);
			 sleep(5);
			 /*
			  * stop child
			  */
			 ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
			 if (ret) {
				 perror("ptrace_attach");
				 goto abort;
			 }
			 printf("issued ptrace attach ret=%d\n", ret);

			 /*
			  * wait for child stop
			  */
			 ret = waitpid(pid, &status, WUNTRACED);
			 if (ret != pid) {
				 perror("waitpid");
				 goto abort;
			 }
			 printf("got process stopped\n");

			 if (WIFEXITED(status)) {
				printf("child has exited\n");
				goto abort;
			 }

			 /*
			  * detach and resume execution
			  */
			 ptrace(PTRACE_DETACH, pid, NULL, NULL);

			 /*
			  * signal child can proceed
			  */
			 ret = write(p[1], &c, 1);
			 if (ret != 1) {
				 perror("write");
				 kill(pid, SIGKILL);
				 return -1;
			 }

			/* wait for child exit */
			 ret = waitpid(pid, &status, 0);
			 if (ret == -1) {
				perror("final waitpid");
			 }
	}
	return ret == -1 || WEXITSTATUS(status) != 0? -1: 0;
abort:
	 kill(pid, SIGKILL);
	 return -1;
}

int
main(int argc, char **argv)
{
	return do_test(argc, argv);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ptrace problem in 2.6.9
  2004-10-22 17:05 ptrace problem in 2.6.9 Stephane Eranian
@ 2004-10-23  4:53 ` Roland McGrath
  2004-10-23  8:25 ` David Mosberger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Roland McGrath @ 2004-10-23  4:53 UTC (permalink / raw)
  To: eranian; +Cc: Andrew Morton, Linus Torvalds

This is indeed a new bug, and it is not architecture-specific.  In my
recent changes to close some race conditions, I overlooked the case of a
process using PTRACE_ATTACH on its own children.  The new PT_ATTACHED flag
does not really mean "PTRACE_ATTACH was used", it means "PTRACE_ATTACH is
changing the ->parent link".  This patch fixes the problem that your test
program demonstrates.


Thanks,
Roland

Signed-off-by: Roland McGrath <roland@redhat.com>

--- linux-2.6/kernel/ptrace.c 19 Oct 2004 06:12:06 -0000 1.38
+++ linux-2.6/kernel/ptrace.c 23 Oct 2004 04:43:20 -0000
@@ -132,7 +132,8 @@ int ptrace_attach(struct task_struct *ta
 		goto bad;
 
 	/* Go */
-	task->ptrace |= PT_PTRACED | PT_ATTACHED;
+	task->ptrace |= PT_PTRACED | ((task->real_parent != current)
+				      ? PT_ATTACHED : 0);
 	if (capable(CAP_SYS_PTRACE))
 		task->ptrace |= PT_PTRACE_CAP;
 	task_unlock(task);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ptrace problem in 2.6.9
  2004-10-22 17:05 ptrace problem in 2.6.9 Stephane Eranian
  2004-10-23  4:53 ` Roland McGrath
@ 2004-10-23  8:25 ` David Mosberger
  2004-10-25  7:51 ` David Mosberger
  2004-10-25  8:04 ` Stephane Eranian
  3 siblings, 0 replies; 5+ messages in thread
From: David Mosberger @ 2004-10-23  8:25 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Fri, 22 Oct 2004 10:05:57 -0700, Stephane Eranian <eranian@hpl.hp.com> said:

  Stephane> Hi Roland, I have some problems with the recent
  Stephane> modifications to the Ptrace infrastructure in 2.6.9
  Stephane> release. Basically I have the smiple test program attached
  Stephane> to this E-mail and it hangs in 2.6.9 but not in
  Stephane> 2.6.9-rc4. Somehow the first waitpid() does not return. It
  Stephane> is not clear to me why.  Is there something Ineed to
  Stephane> change in the call itself?  I am running all of this on a
  Stephane> 2-way IA-64 machine with 2.6.9. I have not tried on x86.

Shoot, I think I ran into the same problem yesterday when running the
GCC testsuite.  In my case, the problem seemed to disappear (mostly)
after downgrading "expect" from the "unstable" to the "stable"
version, but the symptoms where exactly like in your case: waitpid()
didn't return, so I suspect it really was the kernel's fault.  I'll
try Roland's patch on Monday.

	--david

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ptrace problem in 2.6.9
  2004-10-22 17:05 ptrace problem in 2.6.9 Stephane Eranian
  2004-10-23  4:53 ` Roland McGrath
  2004-10-23  8:25 ` David Mosberger
@ 2004-10-25  7:51 ` David Mosberger
  2004-10-25  8:04 ` Stephane Eranian
  3 siblings, 0 replies; 5+ messages in thread
From: David Mosberger @ 2004-10-25  7:51 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Sat, 23 Oct 2004 01:25:42 -0700, David Mosberger <davidm@linux.hpl.hp.com> said:

>>>>> On Fri, 22 Oct 2004 10:05:57 -0700, Stephane Eranian <eranian@hpl.hp.com> said:
  Stephane> Hi Roland, I have some problems with the recent
  Stephane> modifications to the Ptrace infrastructure in 2.6.9
  Stephane> release. Basically I have the smiple test program attached
  Stephane> to this E-mail and it hangs in 2.6.9 but not in
  Stephane> 2.6.9-rc4. Somehow the first waitpid() does not return. It
  Stephane> is not clear to me why.  Is there something Ineed to
  Stephane> change in the call itself?  I am running all of this on a
  Stephane> 2-way IA-64 machine with 2.6.9. I have not tried on x86.

  David> Shoot, I think I ran into the same problem yesterday when
  David> running the GCC testsuite.  In my case, the problem seemed to
  David> disappear (mostly) after downgrading "expect" from the
  David> "unstable" to the "stable" version, but the symptoms where
  David> exactly like in your case: waitpid() didn't return, so I
  David> suspect it really was the kernel's fault.  I'll try Roland's
  David> patch on Monday.

Then again, may be not: it appears that the bug only relates to
PTRACE'd processes, which "expect" is unlikely to do.  Oh, well, would
have been too easy.

	--david

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ptrace problem in 2.6.9
  2004-10-22 17:05 ptrace problem in 2.6.9 Stephane Eranian
                   ` (2 preceding siblings ...)
  2004-10-25  7:51 ` David Mosberger
@ 2004-10-25  8:04 ` Stephane Eranian
  3 siblings, 0 replies; 5+ messages in thread
From: Stephane Eranian @ 2004-10-25  8:04 UTC (permalink / raw)
  To: linux-ia64

>   Stephane> Hi Roland, I have some problems with the recent
>   Stephane> modifications to the Ptrace infrastructure in 2.6.9
>   Stephane> release. Basically I have the smiple test program attached
>   Stephane> to this E-mail and it hangs in 2.6.9 but not in
>   Stephane> 2.6.9-rc4. Somehow the first waitpid() does not return. It
>   Stephane> is not clear to me why.  Is there something Ineed to
>   Stephane> change in the call itself?  I am running all of this on a
>   Stephane> 2-way IA-64 machine with 2.6.9. I have not tried on x86.
> 
>   David> Shoot, I think I ran into the same problem yesterday when
>   David> running the GCC testsuite.  In my case, the problem seemed to
>   David> disappear (mostly) after downgrading "expect" from the
>   David> "unstable" to the "stable" version, but the symptoms where
>   David> exactly like in your case: waitpid() didn't return, so I
>   David> suspect it really was the kernel's fault.  I'll try Roland's
>   David> patch on Monday.
> 
> Then again, may be not: it appears that the bug only relates to
> PTRACE'd processes, which "expect" is unlikely to do.  Oh, well, would
> have been too easy.
> 
In any case, that fixed the problem for me.

-- 
-Stephane

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-10-25  8:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-22 17:05 ptrace problem in 2.6.9 Stephane Eranian
2004-10-23  4:53 ` Roland McGrath
2004-10-23  8:25 ` David Mosberger
2004-10-25  7:51 ` David Mosberger
2004-10-25  8:04 ` Stephane Eranian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox