Skip to content

Commit

Permalink
zdtm: use pthread_create to create a thread
Browse files Browse the repository at this point in the history
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: Andrew Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
avagin authored and xemul committed Sep 10, 2015
1 parent 46f9285 commit a99d47e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions test/zdtm/live/static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ inotify_system_nodel: override CFLAGS += -DNODEL
pthread00: override LDLIBS += -pthread
pthread01: override LDLIBS += -pthread
pthread02: override LDLIBS += -pthread
different_creds: override LDLIBS += -pthread
sigpending: override LDLIBS += -pthread
sigaltstack: override LDLIBS += -pthread
shm: override CFLAGS += -DNEW_IPC_NS
Expand Down
26 changes: 12 additions & 14 deletions test/zdtm/live/static/different_creds.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
#include <sched.h>
#include <sys/capability.h>
#include <linux/limits.h>
#include <pthread.h>
#include <syscall.h>

#include "zdtmtst.h"

const char *test_doc = "Check that threads with different creds aren't checkpointed";
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;
int *pipe = arg;

caps = cap_get_proc();
if (!caps) {
err("cap_get_proc");
return 1;
return NULL;
}

if (cap_clear_flag(caps, CAP_EFFECTIVE) < 0) {
Expand All @@ -39,18 +44,14 @@ int drop_caps_and_wait(void *arg)
sleep(1000);
die:
cap_free(caps);
return 1;
return NULL;
}

int main(int argc, char ** argv)
{
pid_t pid;
int ret, pipefd[2];
long clone_flags = CLONE_VM | CLONE_FILES | CLONE_SIGHAND |
CLONE_THREAD | CLONE_SYSVSEM;
pthread_t thr;

size_t stack_size = sysconf(_SC_PAGESIZE);
void *stack = alloca(stack_size);
char buf;

test_init(argc, argv);
Expand All @@ -60,12 +61,10 @@ int main(int argc, char ** argv)
return -1;
}

pid = clone(drop_caps_and_wait, stack + stack_size, clone_flags, pipefd);
if (pid < 0) {
err("fork");
if (pthread_create(&thr, NULL, drop_caps_and_wait, pipefd)) {
err("Unable to create thread");
return -1;
}

close(pipefd[1]);

/*
Expand All @@ -83,6 +82,5 @@ int main(int argc, char ** argv)

fail("shouldn't dump successfully");

kill(pid, SIGKILL);
return ret;
exit_group(ret);
}

0 comments on commit a99d47e

Please sign in to comment.