[PATCH 83] ptrace(DETACH, SIGKILL) should really kill the tracee

Jan Kratochvil jan.kratochvil at redhat.com
Sat Oct 10 17:40:25 UTC 2009


On Sat, 10 Oct 2009 18:17:12 +0200, Oleg Nesterov wrote:
> Roland, Jan, what user-space expects ptrace(DETACH, SIGKILL) should do?
> 
> My guess: this should really kill the tracee asap, hence this patch.

attached testcase works for me on both:
kernel-2.6.31.1-48.fc12.x86_64
kernel-2.6.30.5-43.fc11.x86_64

does it FAIL for you to make it worth to the testsuite?


Thanks,
Jan
-------------- next part --------------
/* Test case for (PTRACE_DETACH, SIGKILL) really does kill the tracee.

   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   arising from the use of this software.

   Permission is granted to anyone to use this software for any purpose,
   including commercial applications, and to alter it and redistribute it
   freely.  */

#define _GNU_SOURCE 1
#include <assert.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <errno.h>

static pid_t child;

static void
cleanup (void)
{
  if (child > 0)
    kill (child, SIGKILL);
  child = 0;
}

static void
handler_fail (int signo)
{
  cleanup ();
  signal (signo, SIG_DFL);
  raise (signo);
}

int
main (void)
{
  pid_t got_pid;
  int status;
  long l;

  atexit (cleanup);
  signal (SIGABRT, handler_fail);
  signal (SIGINT, handler_fail);

  child = fork ();
  switch (child)
    {
    case -1:
      assert_perror (errno);

    case 0:
      l = ptrace (PTRACE_TRACEME, 0, NULL, NULL);
      assert (l == 0);

      raise (SIGUSR1);
      _exit (42);

    default:
      break;
    }

  got_pid = waitpid (child, &status, 0);
  assert (got_pid == child);
  assert (WIFSTOPPED (status));
  assert (WSTOPSIG (status) == SIGUSR1);

  errno = 0;
  l = ptrace (PTRACE_DETACH, child, NULL, (void *) (long) SIGKILL);
  assert_perror (errno);
  assert (l == 0);

  got_pid = waitpid (child, &status, 0);
  assert (got_pid == child);
  assert (WIFSIGNALED (status));
  assert (WTERMSIG (status) == SIGKILL);

  return 0;
}


More information about the utrace-devel mailing list