Page MenuHomeFreeBSD

rtld: mask signals for default read locks
ClosedPublic

Authored by kib on Aug 31 2022, 1:11 AM.
Tags
None
Referenced Files
F107541917: D36396.diff
Wed, Jan 15, 4:06 PM
Unknown Object (File)
Mon, Jan 13, 4:13 PM
Unknown Object (File)
Fri, Dec 27, 3:10 PM
Unknown Object (File)
Nov 22 2024, 11:27 PM
Unknown Object (File)
Nov 21 2024, 5:53 AM
Unknown Object (File)
Nov 13 2024, 9:26 PM
Unknown Object (File)
Nov 13 2024, 12:05 AM
Unknown Object (File)
Oct 2 2024, 10:26 PM
Subscribers

Details

Summary
Rtld locks from libthr defer signals delivery, which means that binding
is not possible while a signal handler is executed.

Binding might upgrade read-locked rtld_bind_lock to write-lock, if
symbol resolution requires loading filters.  If a signal would be delivered
while rtld is in read-locked section, and signal handler needs binding
which upgrades the lock, for non-threaded image that uses default rtld
locks, we get the rtld data structures modified under the top-level
active rtld frame.

To correct the problem, Mask signals for read-locking of default locks
in addition to the write-locking.  It is very cheap now with
sigfastblock(2).

Note that the global state is used to track pre-locked state of either
sigfastblock(2) or signal mask (if sigfastblock(2) is administratively
disabled).  It is fine for non-threaded images since there are no other
threads.  But I believe that it is fine for threaded images using libc_r
as well, since masking signals disables preemption (I did not tested
it).

NetBSD PR:      https://gnats.netbsd.org/56979
Reported by:    tmunro

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Aug 31 2022, 1:11 AM
markj added inline comments.
libexec/rtld-elf/rtld_lock.c
148

Is _rel really needed here?

This revision is now accepted and ready to land.Sep 3 2022, 2:20 PM
kib marked an inline comment as done.Sep 3 2022, 2:30 PM
kib added inline comments.
libexec/rtld-elf/rtld_lock.c
148

No. And _add_acq can be further optimized by removing _acq and only doing fence_acq when WAFLAG is not set, but I decided to not bother.

kib marked an inline comment as done.

Remove one _rel

This revision now requires review to proceed.Sep 3 2022, 2:31 PM
This revision is now accepted and ready to land.Sep 3 2022, 2:54 PM