On Thu, Nov 26, 2009 at 11:37:03PM +0100, Oleg Nesterov wrote:
>
> Could you look at this
>
>   ptrace-copy_process-should-disable-stepping.patch
>   http://marc.info/?l=linux-mm-commits&m=125789789322573
>
> patch? It is not clear to me how we can modify the test-case to
> verify it fixes the original problem for powerpc.

I modified the test-case, it confirms that
ptrace-copy_process-should-disable-stepping.patch fixes the
problem with TIF_SINGLESTEP copied by fork() on powerpc.

Probably we need a similar fix for step-fork.c in ptrace-tests.

Modified the original testcase to call fork via syscall(__NR_fork),
to avoid the looping inside libc's fork() on powerpc.
The parent singlesteps until he sees that the child has forked, after
that the parent PTRACE_CONTs until the child exits.

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <assert.h>
#include <sys/syscall.h>

int main(void)
{
        void *addr_after_fork = &&after_fork;
        int pid, status;

        if (!(pid = fork())) {
                assert(ptrace(PTRACE_TRACEME) == 0);
                kill(getpid(), SIGSTOP);

                if (!syscall(__NR_fork)) {
                        /* kernel bug: this child will be killed by SIGTRAP */
                        printf("Hello world\n");
                        return 43;
                }

after_fork:     wait(&status);
                return WEXITSTATUS(status);
        }

        for (;;) {
                siginfo_t info;

                assert(pid == wait(&status));
                assert(ptrace(PTRACE_GETSIGINFO, pid, 0,&info) == 0);
                if (info.si_addr == addr_after_fork)
                        break;
                assert(ptrace(PTRACE_SINGLESTEP, pid, 0,0) == 0);
        }

        for (;;) {
                if (WIFEXITED(status))
                        break;
                assert(ptrace(PTRACE_CONT, pid, 0,0) == 0);
                assert(pid == wait(&status));
        }

        assert(WEXITSTATUS(status) == 43);
        return 0;
}

--
Veaceslav

Reply via email to