• Oleg Nesterov's avatar
    ptrace: copy_process() should disable stepping · 6580807d
    Oleg Nesterov authored
    If the tracee calls fork() after PTRACE_SINGLESTEP, the forked child
    starts with TIF_SINGLESTEP/X86_EFLAGS_TF bits copied from ptraced parent.
    This is not right, especially when the new child is not auto-attaced: in
    this case it is killed by SIGTRAP.
    
    Change copy_process() to call user_disable_single_step(). Tested on x86.
    
    Test-case:
    
    	#include <stdio.h>
    	#include <unistd.h>
    	#include <signal.h>
    	#include <sys/ptrace.h>
    	#include <sys/wait.h>
    	#include <assert.h>
    
    	int main(void)
    	{
    		int pid, status;
    
    		if (!(pid = fork())) {
    			assert(ptrace(PTRACE_TRACEME) == 0);
    			kill(getpid(), SIGSTOP);
    
    			if (!fork()) {
    				/* kernel bug: this child will be killed by SIGTRAP */
    				printf("Hello world\n");
    				return 43;
    			}
    
    			wait(&status);
    			return WEXITSTATUS(status);
    		}
    
    		for (;;) {
    			assert(pid == wait(&status));
    			if (WIFEXITED(status))
    				break;
    			assert(ptrace(PTRACE_SINGLESTEP, pid, 0,0) == 0);
    		}
    
    		assert(WEXITSTATUS(status) == 43);
    		return 0;
    	}
    Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
    Acked-by: default avatarRoland McGrath <roland@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    6580807d
fork.c 42.7 KB