Commit a99d47e0 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

zdtm: use pthread_create to create a thread

If you call clone directly you are responsible for setting up the TLS area yourself.

$ abrt-cli ls  | grep different_creds | wc -l
39
$ gdb -c /var/spool/abrt/ccpp-2015-07-24-10\:21\:14-8014/coredump  different_creds
 Core was generated by `./different_creds --pidfile=different_creds.pid --outfile=different_creds.out'.
 Program terminated with signal SIGILL, Illegal instruction.
 #0  0x00007f86e2d8c7d9 in _dl_x86_64_restore_sse () from /lib64/ld-linux-x86-64.so.2
 Missing separate debuginfos, use: dnf debuginfo-install glibc-2.21-7.fc22.x86_64 libattr-2.4.47-9.fc22.x86_64 libcap-2.24-7.fc22.x86_64
 (gdb) bt
 #0  0x00007f86e2d8c7d9 in _dl_x86_64_restore_sse () from /lib64/ld-linux-x86-64.so.2
 #1  0x00007f86e2d84add in _dl_fixup () from /lib64/ld-linux-x86-64.so.2
 #2  0x00007f86e2d8bbc0 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
 #3  0x0000000000402da3 in sys_futex (val3=0, uaddr2=0x0, timeout=0x0, val=0, op=0, uaddr=0x6063f0 <sig_received>) at lock.h:29
 #4  futex_wait_while (f=0x6063f0 <sig_received>, v=0) at lock.h:121
 #5  test_waitsig () at test.c:367
 #6  0x0000000000401c4b in main (argc=<optimized out>, argv=0x7ffce16432f8) at different_creds.c:82

Reported-by: Mr Jenkins
Cc: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 46f9285e
...@@ -317,6 +317,7 @@ inotify_system_nodel: override CFLAGS += -DNODEL ...@@ -317,6 +317,7 @@ inotify_system_nodel: override CFLAGS += -DNODEL
pthread00: override LDLIBS += -pthread pthread00: override LDLIBS += -pthread
pthread01: override LDLIBS += -pthread pthread01: override LDLIBS += -pthread
pthread02: override LDLIBS += -pthread pthread02: override LDLIBS += -pthread
different_creds: override LDLIBS += -pthread
sigpending: override LDLIBS += -pthread sigpending: override LDLIBS += -pthread
sigaltstack: override LDLIBS += -pthread sigaltstack: override LDLIBS += -pthread
shm: override CFLAGS += -DNEW_IPC_NS shm: override CFLAGS += -DNEW_IPC_NS
......
...@@ -6,13 +6,18 @@ ...@@ -6,13 +6,18 @@
#include <sched.h> #include <sched.h>
#include <sys/capability.h> #include <sys/capability.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <pthread.h>
#include <syscall.h>
#include "zdtmtst.h" #include "zdtmtst.h"
const char *test_doc = "Check that threads with different creds aren't checkpointed"; const char *test_doc = "Check that threads with different creds aren't checkpointed";
const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>";
int drop_caps_and_wait(void *arg) #define exit_group(code) \
syscall(__NR_exit_group, code)
void *drop_caps_and_wait(void *arg)
{ {
cap_t caps; cap_t caps;
int *pipe = arg; int *pipe = arg;
...@@ -20,7 +25,7 @@ int drop_caps_and_wait(void *arg) ...@@ -20,7 +25,7 @@ int drop_caps_and_wait(void *arg)
caps = cap_get_proc(); caps = cap_get_proc();
if (!caps) { if (!caps) {
err("cap_get_proc"); err("cap_get_proc");
return 1; return NULL;
} }
if (cap_clear_flag(caps, CAP_EFFECTIVE) < 0) { if (cap_clear_flag(caps, CAP_EFFECTIVE) < 0) {
...@@ -39,18 +44,14 @@ int drop_caps_and_wait(void *arg) ...@@ -39,18 +44,14 @@ int drop_caps_and_wait(void *arg)
sleep(1000); sleep(1000);
die: die:
cap_free(caps); cap_free(caps);
return 1; return NULL;
} }
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
pid_t pid;
int ret, pipefd[2]; int ret, pipefd[2];
long clone_flags = CLONE_VM | CLONE_FILES | CLONE_SIGHAND | pthread_t thr;
CLONE_THREAD | CLONE_SYSVSEM;
size_t stack_size = sysconf(_SC_PAGESIZE);
void *stack = alloca(stack_size);
char buf; char buf;
test_init(argc, argv); test_init(argc, argv);
...@@ -60,12 +61,10 @@ int main(int argc, char ** argv) ...@@ -60,12 +61,10 @@ int main(int argc, char ** argv)
return -1; return -1;
} }
pid = clone(drop_caps_and_wait, stack + stack_size, clone_flags, pipefd); if (pthread_create(&thr, NULL, drop_caps_and_wait, pipefd)) {
if (pid < 0) { err("Unable to create thread");
err("fork");
return -1; return -1;
} }
close(pipefd[1]); close(pipefd[1]);
/* /*
...@@ -83,6 +82,5 @@ int main(int argc, char ** argv) ...@@ -83,6 +82,5 @@ int main(int argc, char ** argv)
fail("shouldn't dump successfully"); fail("shouldn't dump successfully");
kill(pid, SIGKILL); exit_group(ret);
return ret;
} }
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