Skip to content

Commit b2db219

Browse files
richardweinbergertorvalds
authored andcommitted
um: fix abort
os_dump_core() uses abort() to terminate UML in case of an fatal error. glibc's abort() calls raise(SIGABRT) which makes use of tgkill(). tgkill() has no effect within UML's kernel threads because they are not pthreads. As fallback abort() executes an invalid instruction to terminate the process. Therefore UML gets killed by SIGSEGV and leaves a ugly log entry in the host's kernel ring buffer. To get rid of this we use our own abort routine. Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d6c438b commit b2db219

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎arch/um/os-Linux/util.c‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdio.h>
77
#include <stdlib.h>
8+
#include <unistd.h>
89
#include <errno.h>
910
#include <signal.h>
1011
#include <string.h>
@@ -75,6 +76,26 @@ void setup_hostinfo(char *buf, int len)
7576
host.release, host.version, host.machine);
7677
}
7778

79+
/*
80+
* We cannot use glibc's abort(). It makes use of tgkill() which
81+
* has no effect within UML's kernel threads.
82+
* After that glibc would execute an invalid instruction to kill
83+
* the calling process and UML crashes with SIGSEGV.
84+
*/
85+
static inline void __attribute__ ((noreturn)) uml_abort(void)
86+
{
87+
sigset_t sig;
88+
89+
fflush(NULL);
90+
91+
if (!sigemptyset(&sig) && !sigaddset(&sig, SIGABRT))
92+
sigprocmask(SIG_UNBLOCK, &sig, 0);
93+
94+
for (;;)
95+
if (kill(getpid(), SIGABRT) < 0)
96+
exit(127);
97+
}
98+
7899
void os_dump_core(void)
79100
{
80101
int pid;
@@ -116,5 +137,5 @@ void os_dump_core(void)
116137
while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0)
117138
os_kill_ptraced_process(pid, 0);
118139

119-
abort();
140+
uml_abort();
120141
}

0 commit comments

Comments
 (0)