summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorZhixiong Chi <zhixiong.chi@windriver.com>2017-09-05 12:29:44 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-09-11 17:30:28 +0100
commitee9db1a9152e8757ce4d831ff9f4472ff5a57dad (patch)
tree2d5bc5aec235bd160556c5455352674d36a7bcac /meta
parentf6f6b3e5d5a77010d5716b2cb980b271ee5dc8e8 (diff)
downloadpoky-ee9db1a9152e8757ce4d831ff9f4472ff5a57dad.tar.gz
glibc: add ld.so locks in _libc_fork
The patch in this Bugzilla entry was requested by a customer: https://sourceware.org/bugzilla/show_bug.cgi?id=4578 https://www.sourceware.org/bugzilla/show_bug.cgi?id=19282 If a thread happens to hold dl_load_lock and have r_state set to RT_ADD or RT_DELETE at the time another thread calls fork(), then the child exit code from fork (in nptl/sysdeps/unix/sysv/linux/fork.c in our case) re-initializes dl_load_lock but does not restore r_state to RT_CONSISTENT. If the child subsequently requires ld.so functionality before calling exec(), then the assertion will fire. The patch acquires dl_load_lock on entry to fork() and releases it on exit from the parent path. The child path is initialized as currently done. This is essentially pthreads_atfork, but forced to be first because the acquisition of dl_load_lock must happen before malloc_atfork is active to avoid a deadlock. The __libc_fork() code reset dl_load_lock, but it also needed to reset dl_load_write_lock. (From OE-Core rev: f2e586ebf59a9b7d5b216fc92aeb892069a4b0c1) Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-core/glibc/glibc/0027-glibc-reset-dl-load-write-lock-after-forking.patch37
-rw-r--r--meta/recipes-core/glibc/glibc/0028-Bug-4578-add-ld.so-lock-while-fork.patch57
-rw-r--r--meta/recipes-core/glibc/glibc_2.26.bb2
3 files changed, 96 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0027-glibc-reset-dl-load-write-lock-after-forking.patch b/meta/recipes-core/glibc/glibc/0027-glibc-reset-dl-load-write-lock-after-forking.patch
new file mode 100644
index 0000000000..777b253405
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0027-glibc-reset-dl-load-write-lock-after-forking.patch
@@ -0,0 +1,37 @@
1From a6bb73d1cfd20a73fbbe6076008376fb87879d1b Mon Sep 17 00:00:00 2001
2From: Yuanjie Huang <yuanjie.huang@windriver.com>
3Date: Thu, 18 Aug 2016 17:59:13 +0800
4Subject: [PATCH] reset dl_load_write_lock after forking
5
6The patch in this Bugzilla entry was requested by a customer:
7
8 https://www.sourceware.org/bugzilla/show_bug.cgi?id=19282
9
10The __libc_fork() code reset dl_load_lock, but it also needed to reset
11dl_load_write_lock. The patch has not yet been integrated upstream.
12
13Upstream-Status: Pending [ Not Author See bugzilla]
14
15Signed-off-by: Damodar Sonone <damodar.sonone@kpit.com>
16Signed-off-by: Yuanjie Huang <yuanjie.huang@windriver.com>
17---
18 sysdeps/nptl/fork.c | 3 ++-
19 1 file changed, 2 insertions(+), 1 deletion(-)
20
21diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
22index 2b9ae4b..3d0b8da 100644
23--- a/sysdeps/nptl/fork.c
24+++ b/sysdeps/nptl/fork.c
25@@ -174,8 +174,9 @@ __libc_fork (void)
26 /* Reset locks in the I/O code. */
27 _IO_list_resetlock ();
28
29- /* Reset the lock the dynamic loader uses to protect its data. */
30+ /* Reset the locks the dynamic loader uses to protect its data. */
31 __rtld_lock_initialize (GL(dl_load_lock));
32+ __rtld_lock_initialize (GL(dl_load_write_lock));
33
34 /* Run the handlers registered for the child. */
35 while (allp != NULL)
36--
371.9.1
diff --git a/meta/recipes-core/glibc/glibc/0028-Bug-4578-add-ld.so-lock-while-fork.patch b/meta/recipes-core/glibc/glibc/0028-Bug-4578-add-ld.so-lock-while-fork.patch
new file mode 100644
index 0000000000..f76237a46e
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0028-Bug-4578-add-ld.so-lock-while-fork.patch
@@ -0,0 +1,57 @@
1The patch in this Bugzilla entry was requested by a customer:
2 https://sourceware.org/bugzilla/show_bug.cgi?id=4578
3
4If a thread happens to hold dl_load_lock and have r_state set to RT_ADD or
5RT_DELETE at the time another thread calls fork(), then the child exit code
6from fork (in nptl/sysdeps/unix/sysv/linux/fork.c in our case) re-initializes
7dl_load_lock but does not restore r_state to RT_CONSISTENT. If the child
8subsequently requires ld.so functionality before calling exec(), then the
9assertion will fire.
10
11The patch acquires dl_load_lock on entry to fork() and releases it on exit
12from the parent path. The child path is initialized as currently done.
13This is essentially pthreads_atfork, but forced to be first because the
14acquisition of dl_load_lock must happen before malloc_atfork is active
15to avoid a deadlock.
16The patch has not yet been integrated upstream.
17
18Upstream-Status: Pending [ Not Author See bugzilla]
19
20Signed-off-by: Raghunath Lolur <Raghunath.Lolur@kpit.com>
21Signed-off-by: Yuanjie Huang <yuanjie.huang@windriver.com>
22Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
23
24Index: git/sysdeps/nptl/fork.c
25===================================================================
26--- git.orig/sysdeps/nptl/fork.c 2017-08-03 16:02:15.674704080 +0800
27+++ git/sysdeps/nptl/fork.c 2017-08-04 18:15:02.463362015 +0800
28@@ -25,6 +25,7 @@
29 #include <tls.h>
30 #include <hp-timing.h>
31 #include <ldsodefs.h>
32+#include <libc-lock.h>
33 #include <stdio-lock.h>
34 #include <atomic.h>
35 #include <nptl/pthreadP.h>
36@@ -60,6 +61,10 @@
37 but our current fork implementation is not. */
38 bool multiple_threads = THREAD_GETMEM (THREAD_SELF, header.multiple_threads);
39
40+ /* grab ld.so lock BEFORE switching to malloc_atfork */
41+ __rtld_lock_lock_recursive (GL(dl_load_lock));
42+ __rtld_lock_lock_recursive (GL(dl_load_write_lock));
43+
44 /* Run all the registered preparation handlers. In reverse order.
45 While doing this we build up a list of all the entries. */
46 struct fork_handler *runp;
47@@ -247,6 +252,10 @@
48
49 allp = allp->next;
50 }
51+
52+ /* unlock ld.so last, because we locked it first */
53+ __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
54+ __rtld_lock_unlock_recursive (GL(dl_load_lock));
55 }
56
57 return pid;
diff --git a/meta/recipes-core/glibc/glibc_2.26.bb b/meta/recipes-core/glibc/glibc_2.26.bb
index d453d8f9bf..135ec4fb16 100644
--- a/meta/recipes-core/glibc/glibc_2.26.bb
+++ b/meta/recipes-core/glibc/glibc_2.26.bb
@@ -41,6 +41,8 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
41 file://0024-elf-dl-deps.c-Make-_dl_build_local_scope-breadth-fir.patch \ 41 file://0024-elf-dl-deps.c-Make-_dl_build_local_scope-breadth-fir.patch \
42 file://0025-locale-fix-hard-coded-reference-to-gcc-E.patch \ 42 file://0025-locale-fix-hard-coded-reference-to-gcc-E.patch \
43 file://0026-assert-Suppress-pedantic-warning-caused-by-statement.patch \ 43 file://0026-assert-Suppress-pedantic-warning-caused-by-statement.patch \
44 file://0027-glibc-reset-dl-load-write-lock-after-forking.patch \
45 file://0028-Bug-4578-add-ld.so-lock-while-fork.patch \
44" 46"
45 47
46NATIVESDKFIXES ?= "" 48NATIVESDKFIXES ?= ""