Commit b85e9680 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

[PATCH] uml: fix TT mode by reverting "use fork instead of clone"

With Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

Revert the following patch, because of miscompilation problems in different
environments leading to UML not working *at all* in TT mode; it was merged
lately in 2.6 development cycle, a little after being written, and has
caused problems to lots of people; I know it's a bit too long, but it
shouldn't have been merged in first place, so I still apply for inclusion
in the -stable tree.  Anyone using this feature currently is either using
some older kernel (some reports even used 2.6.12-rc4-mm2) or using this
patch, as included in my -bs patchset.

For now there's not yet a fix for this patch, so for now the best thing is
to drop it (which was widely reported to give a working kernel, and as such
was even merged in -stable tree).

"Convert the boot-time host ptrace testing from clone to fork.  They were
essentially doing fork anyway.  This cleans up the code a bit, and makes
valgrind a bit happier about grinding it."

URL:
http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=98fdffccea6cc3fe9dba32c0fcc310bcb5d71529Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 2ca3310e
...@@ -131,7 +131,7 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack, ...@@ -131,7 +131,7 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
return(arg.pid); return(arg.pid);
} }
static int ptrace_child(void) static int ptrace_child(void *arg)
{ {
int ret; int ret;
int pid = os_getpid(), ppid = getppid(); int pid = os_getpid(), ppid = getppid();
...@@ -160,16 +160,20 @@ static int ptrace_child(void) ...@@ -160,16 +160,20 @@ static int ptrace_child(void)
_exit(ret); _exit(ret);
} }
static int start_ptraced_child(void) static int start_ptraced_child(void **stack_out)
{ {
void *stack;
unsigned long sp;
int pid, n, status; int pid, n, status;
pid = fork(); stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
if(pid == 0) MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ptrace_child(); if(stack == MAP_FAILED)
panic("check_ptrace : mmap failed, errno = %d", errno);
sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
if(pid < 0) if(pid < 0)
panic("check_ptrace : fork failed, errno = %d", errno); panic("check_ptrace : clone failed, errno = %d", errno);
CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
if(n < 0) if(n < 0)
panic("check_ptrace : wait failed, errno = %d", errno); panic("check_ptrace : wait failed, errno = %d", errno);
...@@ -177,6 +181,7 @@ static int start_ptraced_child(void) ...@@ -177,6 +181,7 @@ static int start_ptraced_child(void)
panic("check_ptrace : expected SIGSTOP, got status = %d", panic("check_ptrace : expected SIGSTOP, got status = %d",
status); status);
*stack_out = stack;
return(pid); return(pid);
} }
...@@ -184,12 +189,12 @@ static int start_ptraced_child(void) ...@@ -184,12 +189,12 @@ static int start_ptraced_child(void)
* just avoid using sysemu, not panic, but only if SYSEMU features are broken. * just avoid using sysemu, not panic, but only if SYSEMU features are broken.
* So only for SYSEMU features we test mustpanic, while normal host features * So only for SYSEMU features we test mustpanic, while normal host features
* must work anyway!*/ * must work anyway!*/
static int stop_ptraced_child(int pid, int exitcode, int mustexit) static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic)
{ {
int status, n, ret = 0; int status, n, ret = 0;
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
panic("stop_ptraced_child : ptrace failed, errno = %d", errno); panic("check_ptrace : ptrace failed, errno = %d", errno);
CATCH_EINTR(n = waitpid(pid, &status, 0)); CATCH_EINTR(n = waitpid(pid, &status, 0));
if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
int exit_with = WEXITSTATUS(status); int exit_with = WEXITSTATUS(status);
...@@ -200,13 +205,15 @@ static int stop_ptraced_child(int pid, int exitcode, int mustexit) ...@@ -200,13 +205,15 @@ static int stop_ptraced_child(int pid, int exitcode, int mustexit)
printk("check_ptrace : child exited with exitcode %d, while " printk("check_ptrace : child exited with exitcode %d, while "
"expecting %d; status 0x%x", exit_with, "expecting %d; status 0x%x", exit_with,
exitcode, status); exitcode, status);
if (mustexit) if (mustpanic)
panic("\n"); panic("\n");
else else
printk("\n"); printk("\n");
ret = -1; ret = -1;
} }
if(munmap(stack, PAGE_SIZE) < 0)
panic("check_ptrace : munmap failed, errno = %d", errno);
return ret; return ret;
} }
...@@ -242,11 +249,12 @@ __uml_setup("nosysemu", nosysemu_cmd_param, ...@@ -242,11 +249,12 @@ __uml_setup("nosysemu", nosysemu_cmd_param,
static void __init check_sysemu(void) static void __init check_sysemu(void)
{ {
void *stack;
int pid, syscall, n, status, count=0; int pid, syscall, n, status, count=0;
printk("Checking syscall emulation patch for ptrace..."); printk("Checking syscall emulation patch for ptrace...");
sysemu_supported = 0; sysemu_supported = 0;
pid = start_ptraced_child(); pid = start_ptraced_child(&stack);
if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0) if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
goto fail; goto fail;
...@@ -264,7 +272,7 @@ static void __init check_sysemu(void) ...@@ -264,7 +272,7 @@ static void __init check_sysemu(void)
panic("check_sysemu : failed to modify system " panic("check_sysemu : failed to modify system "
"call return, errno = %d", errno); "call return, errno = %d", errno);
if (stop_ptraced_child(pid, 0, 0) < 0) if (stop_ptraced_child(pid, stack, 0, 0) < 0)
goto fail_stopped; goto fail_stopped;
sysemu_supported = 1; sysemu_supported = 1;
...@@ -272,7 +280,7 @@ static void __init check_sysemu(void) ...@@ -272,7 +280,7 @@ static void __init check_sysemu(void)
set_using_sysemu(!force_sysemu_disabled); set_using_sysemu(!force_sysemu_disabled);
printk("Checking advanced syscall emulation patch for ptrace..."); printk("Checking advanced syscall emulation patch for ptrace...");
pid = start_ptraced_child(); pid = start_ptraced_child(&stack);
while(1){ while(1){
count++; count++;
if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0) if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
...@@ -297,7 +305,7 @@ static void __init check_sysemu(void) ...@@ -297,7 +305,7 @@ static void __init check_sysemu(void)
break; break;
} }
} }
if (stop_ptraced_child(pid, 0, 0) < 0) if (stop_ptraced_child(pid, stack, 0, 0) < 0)
goto fail_stopped; goto fail_stopped;
sysemu_supported = 2; sysemu_supported = 2;
...@@ -308,17 +316,18 @@ static void __init check_sysemu(void) ...@@ -308,17 +316,18 @@ static void __init check_sysemu(void)
return; return;
fail: fail:
stop_ptraced_child(pid, 1, 0); stop_ptraced_child(pid, stack, 1, 0);
fail_stopped: fail_stopped:
printk("missing\n"); printk("missing\n");
} }
void __init check_ptrace(void) void __init check_ptrace(void)
{ {
void *stack;
int pid, syscall, n, status; int pid, syscall, n, status;
printk("Checking that ptrace can change system call numbers..."); printk("Checking that ptrace can change system call numbers...");
pid = start_ptraced_child(); pid = start_ptraced_child(&stack);
if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno); panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno);
...@@ -345,7 +354,7 @@ void __init check_ptrace(void) ...@@ -345,7 +354,7 @@ void __init check_ptrace(void)
break; break;
} }
} }
stop_ptraced_child(pid, 0, 1); stop_ptraced_child(pid, stack, 0, 1);
printk("OK\n"); printk("OK\n");
check_sysemu(); check_sysemu();
} }
...@@ -380,10 +389,11 @@ extern void *__syscall_stub_start, __syscall_stub_end; ...@@ -380,10 +389,11 @@ extern void *__syscall_stub_start, __syscall_stub_end;
static inline void check_skas3_ptrace_support(void) static inline void check_skas3_ptrace_support(void)
{ {
struct ptrace_faultinfo fi; struct ptrace_faultinfo fi;
void *stack;
int pid, n; int pid, n;
printf("Checking for the skas3 patch in the host..."); printf("Checking for the skas3 patch in the host...");
pid = start_ptraced_child(); pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
if (n < 0) { if (n < 0) {
...@@ -402,7 +412,7 @@ static inline void check_skas3_ptrace_support(void) ...@@ -402,7 +412,7 @@ static inline void check_skas3_ptrace_support(void)
} }
init_registers(pid); init_registers(pid);
stop_ptraced_child(pid, 1, 1); stop_ptraced_child(pid, stack, 1, 1);
} }
int can_do_skas(void) int can_do_skas(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment