ptrace bug in -rc2+

From: Gerd Knorr
Date: Thu Oct 14 2004 - 13:40:16 EST


Hi,

The introduction of the new TASK_TRACED state in 2.6.9-rc2 changed the
behavior of the kernel in a IMHO buggy way. Sending a SIGKILL to a
process which is traced _and_ stopped doesn't work any more. user mode
linux kernels do that on shutdown, thats why I ran into this.

Below is a short test app which shows the behavior. On 2.6.9-rc2+ the
last waitpid() call blocks forever, on older kernels it doesn't ...

Gerd

==============================[ cut here ]==============================
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char *argv[])
{
int child,rc,status;

child = fork();
if (0 == child) {
fprintf(stderr,"[child] ptrace me ...\n");
ptrace(PTRACE_TRACEME);
fprintf(stderr,"[child] exec sleep 10 ...\n");
execlp("sleep", "sleep", "10", NULL);
perror("execlp");
exit(1);
}

sleep(1);
fprintf(stderr,"kill %d,STOP ...\n",child);
kill(child,SIGSTOP);
fprintf(stderr,"waitpid %d...\n",child);
rc = waitpid(child,&status,WUNTRACED);
fprintf(stderr,"%s: rc=%d status=%s%s%s termsig=%d\n",__FUNCTION__,rc,
WIFEXITED(status) ? "exit" : "",
WIFSIGNALED(status) ? "signal" : "",
WIFSTOPPED(status) ? "stopped" : "",
WTERMSIG(status));

sleep(1);
fprintf(stderr,"kill %d,KILL ...\n",child);
kill(child,SIGKILL);
fprintf(stderr,"waitpid %d...\n",child);
rc = waitpid(child,&status,WUNTRACED);
fprintf(stderr,"%s: rc=%d status=%s%s%s termsig=%d\n",__FUNCTION__,rc,
WIFEXITED(status) ? "exit" : "",
WIFSIGNALED(status) ? "signal" : "",
WIFSTOPPED(status) ? "stopped" : "",
WTERMSIG(status));

exit(0);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/