From d41cec56d5c04d88aa2d06986b692cd1fa279748 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sun, 3 Jan 2016 19:44:54 +0100 Subject: pthread_atfork handlers not removed during dlclose Invoke pthread_atfork handler cleanup when removing the associated DSO... If a program loads a DSO (dlopen) that sets up a pthread_atfork handler(s), and then subsequently closes the DSO, the handler(s) are left in place. If fork() is subsequently called, the handlers are invoked even though the DSO has been removed causing crashes or unpredictable code execution. This is because the code in __cxa_finalize(atexit.c)to invoke the unregister_atfork() routine is ifdef'd out with the comment that it hasn't been "looked into this yet...". Refs.: http://bugs.busybox.net/show_bug.cgi?id=8211 http://sourceware.org/bugzilla/show_bug.cgi?id=13502 Add test-case, enable cleanup for NPTL only. Signed-off-by: John Ata Signed-off-by: Leonid Lisovskiy --- test/nptl/tst-atfork2.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/nptl/tst-atfork2.c (limited to 'test/nptl/tst-atfork2.c') diff --git a/test/nptl/tst-atfork2.c b/test/nptl/tst-atfork2.c new file mode 100644 index 000000000..1c303de63 --- /dev/null +++ b/test/nptl/tst-atfork2.c @@ -0,0 +1,24 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + void *h; + pid_t pid; + + h = dlopen("libatfork.so", RTLD_NOW); + if (!h) + { + printf("Failed to open libatfork.so\n"); + return 1; + } + dlclose(h); + + if ((pid = fork()) < 0) { + printf("Fork failed\n"); + return 1; + } + + return 0; +} -- cgit v1.2.3