Summary: | [libexec] [patch] rtld is thread-unsafe. fixes for dlopen mt behavior | ||
---|---|---|---|
Product: | Base System | Reporter: | Kostik Belousov <kostikbel> |
Component: | bin | Assignee: | Konstantin Belousov <kib> |
Status: | Closed FIXED | ||
Severity: | Affects Only Me | CC: | ararslan, emaste, markj |
Priority: | Normal | ||
Version: | Unspecified | ||
Hardware: | Any | ||
OS: | Any |
Description
Kostik Belousov
2006-04-05 08:50:13 UTC
----- Forwarded message from Oleg Dolgov <agile@sunbay.com> ----- Hi, I'am able to reproduce this bug even with patched files (rtld.c, rev 1.124, rtld.h, rev 1.38) ... dlopen: /usr/lib/libm.so is running finalizers now dlopen: (null) dlopen: (null) dlopen: (null) dlopen: (null) dlopen: (null) dlopen: (null) dlopen: /usr/lib/libm.so is running finalizers now Segmentation fault (core dumped) deimos# gdb test2 test2.core GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"... Core was generated by `test2'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib/libthr.so.3...done. Loaded symbols for /lib/libthr.so.3 Reading symbols from /lib/libc.so.7...done. Loaded symbols for /lib/libc.so.7 Reading symbols from /usr/lib/libm.so...done. Loaded symbols for /usr/lib/libm.so Reading symbols from /libexec/ld-elf.so.1...done. Loaded symbols for /libexec/ld-elf.so.1 #0 0x0000000800509abb in _rtld_thread_init () from /libexec/ld-elf.so.1 [New Thread 0x800a01f80 (LWP 100202)] [New Thread 0x800a01e10 (LWP 100201)] [New Thread 0x800a01ca0 (LWP 100200)] [New Thread 0x800a01b30 (LWP 100199)] [New Thread 0x800a019c0 (LWP 100198)] [New Thread 0x800a01850 (LWP 100197)] [New Thread 0x800a016e0 (LWP 100196)] [New Thread 0x800a01570 (LWP 100194)] [New Thread 0x800a01400 (LWP 100160)] [New Thread 0x800a01290 (LWP 100150)] [New Thread 0x800a01120 (LWP 100184)] (gdb) info threads 11 Thread 0x800a01120 (LWP 100184) 0x000000080080ac5c in nanosleep () from /lib/libc.so.7 10 Thread 0x800a01290 (LWP 100150) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 9 Thread 0x800a01400 (LWP 100160) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 * 8 Thread 0x800a01570 (LWP 100194) 0x0000000800509abb in _rtld_thread_init () from /libexec/ld-elf.so.1 7 Thread 0x800a016e0 (LWP 100196) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 6 Thread 0x800a01850 (LWP 100197) 0x000000080050ac0c in _rtld_thread_init () from /libexec/ld-elf.so.1 5 Thread 0x800a019c0 (LWP 100198) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 4 Thread 0x800a01b30 (LWP 100199) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 3 Thread 0x800a01ca0 (LWP 100200) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 2 Thread 0x800a01e10 (LWP 100201) 0x0000000800825e4c in write () from /lib/libc.so.7 1 Thread 0x800a01f80 (LWP 100202) 0x0000000800798e5c in _umtx_op () from /lib/libc.so.7 (gdb) bt #0 0x0000000800509abb in _rtld_thread_init () from /libexec/ld-elf.so.1 #1 0x0000000800519f39 in _rtld_thread_init () from /libexec/ld-elf.so.1 #2 0x0000000800509e09 in _rtld_thread_init () from /libexec/ld-elf.so.1 #3 0x000000080050731c in dlsym () from /libexec/ld-elf.so.1 #4 0x0000000800507c76 in dlopen () from /libexec/ld-elf.so.1 #5 0x00000000004008c3 in func () #6 0x000000080063ab98 in pthread_getprio () from /lib/libthr.so.3 #7 0x0000000000000000 in ?? () Cannot access memory at address 0x7fffff7fd000 (gdb) t 6 [Switching to thread 6 (Thread 0x800a01850 (LWP 100197))]#0 0x000000080050ac0c in _rtld_thread_init () from /libexec/ld-elf.so.1 (gdb) bt #0 0x000000080050ac0c in _rtld_thread_init () from /libexec/ld-elf.so.1 #1 0x0000000800504c6c in dl_iterate_phdr () from /libexec/ld-elf.so.1 #2 0x00000008005075ac in dlclose () from /libexec/ld-elf.so.1 #3 0x00000000004008f7 in func () #4 0x000000080063ab98 in pthread_getprio () from /lib/libthr.so.3 #5 0x0000000000000000 in ?? () Cannot access memory at address 0x7fffff3fb000 p.s. seems that bug (bin/123932: amd(8) core dumps while load high) related to this. p.p.s. FreeBSD 7.0-RELEASE (SCHED_ULE, SMP), amd64, 2xcpu 4-core, 6 Gb RAM. ----- End forwarded message ----- My investigation shows that patch is correct, there other place which also thread-unsafe, see kern/126950 (rtld malloc is thread-unsafe). For bugs matching the following conditions: - Status == In Progress - Assignee == "bugs@FreeBSD.org" - Last Modified Year <= 2017 Do - Set Status to "Open" I believe all the issues around thread safety in rtld have been addressed over time. Any issues encountered in 2018 certainly deserve a new PR. It seems that issues persist in `dlerror` in the presence of threads. See https://github.com/JuliaLang/julia/issues/39582 where this was encountered with Julia on FreeBSD 11. (In reply to Alex Arslan from comment #5) It would be better to create a new PR if only for tracking. The preliminary version of the fix for the issue as I understand it, is available at https://reviews.freebsd.org/D29633 A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4d9128da54f8f8e2a29190ffb18880c4f116a205 commit 4d9128da54f8f8e2a29190ffb18880c4f116a205 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-04-07 22:02:33 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-04-10 14:33:34 +0000 rtld: make dlerror() thread-local PR: 95339 Discussed with: arichardson Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29633 lib/libthr/thread/thr_private.h | 4 ++++ lib/libthr/thread/thr_rtld.c | 21 +++++++++++++++++++++ libexec/rtld-elf/rtld.c | 38 ++++++++++++++++++++------------------ libexec/rtld-elf/rtld_lock.c | 33 +++++++++++++++++++++++++++++++++ libexec/rtld-elf/rtld_lock.h | 7 ++++++- 5 files changed, 84 insertions(+), 19 deletions(-) |