Summary: | fork() can deadlock on rtld_phdr_lock | ||
---|---|---|---|
Product: | Base System | Reporter: | Tavian Barnes <tavianator> |
Component: | threads | Assignee: | freebsd-threads (Nobody) <threads> |
Status: | New --- | ||
Severity: | Affects Only Me | CC: | kib |
Priority: | --- | ||
Version: | 14.1-RELEASE | ||
Hardware: | Any | ||
OS: | Any |
Description
Tavian Barnes
2024-07-16 20:43:51 UTC
This is expected: we lock phdr lock over the whole dl_iterate_phdr, including the callback. To make dl_iterate_phdr() functional after the fork, pre-fork code also locks the phdr lock. See ef2c2a692b75d644549827b3aaa9f1736940fe85 for some references about the need of the phdr lock. Since your example blocks in the callback, it is blocked owning the phdr lock, and fork cannot proceed. In principle, dl_iterate_phdr() is not required to be useful after fork(). I can add a knob to select the behavior, but I do not see how could it be made both. A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=860c4d94ac46cee35a678cf3c9cdbd437dfed75e commit 860c4d94ac46cee35a678cf3c9cdbd437dfed75e Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-07-17 04:05:33 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-07-29 23:57:33 +0000 rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var which makes threaded fork ignore the phdr rtld lock, in particular allowing the dl_iterate_phdr() to block in callback. The cost is that the image started in this mode cannot use dl_iterate_phdr() after fork. PR: 280318 Sponsored by: The FreeBSD Foundation MFC after: 1 week libexec/rtld-elf/rtld.1 | 10 +++++++++- libexec/rtld-elf/rtld.c | 1 + libexec/rtld-elf/rtld.h | 1 + libexec/rtld-elf/rtld_lock.c | 7 +++++-- 4 files changed, 16 insertions(+), 3 deletions(-) A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=279e543dc707ee19b28cee8a00deafea1f8b8d8e commit 279e543dc707ee19b28cee8a00deafea1f8b8d8e Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-07-17 04:05:33 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-08-05 00:32:11 +0000 rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var PR: 280318 (cherry picked from commit 860c4d94ac46cee35a678cf3c9cdbd437dfed75e) libexec/rtld-elf/rtld.1 | 10 +++++++++- libexec/rtld-elf/rtld.c | 1 + libexec/rtld-elf/rtld.h | 1 + libexec/rtld-elf/rtld_lock.c | 7 +++++-- 4 files changed, 16 insertions(+), 3 deletions(-) |