Page MenuHomeFreeBSD

rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V
ClosedPublic

Authored by jrtc27 on May 5 2025, 11:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 29, 10:46 AM
Unknown Object (File)
Wed, Oct 29, 10:05 AM
Unknown Object (File)
Sun, Oct 26, 3:08 AM
Unknown Object (File)
Sun, Oct 26, 12:18 AM
Unknown Object (File)
Oct 24 2025, 9:02 PM
Unknown Object (File)
Oct 23 2025, 4:59 PM
Unknown Object (File)
Oct 4 2025, 7:45 AM
Unknown Object (File)
Sep 16 2025, 9:47 PM
Subscribers

Details

Summary

The implementation of dl_iterate_phdr abuses tls_get_addr_slow to get to
the start of the TLS block, inlining the implementation of
tls_get_addr as if the tls_index's ti_offset were 0 (historically it
called
tls_get_addr itself but changed due to locking issues). For
most architectures, tls_index's ti_offset (relocated by DTPOFF/DTPREL
for GOT entries) is just the offset within that module's TLS block.
However, for PowerPC and RISC-V, which have a non-zero TLS_DTV_OFFSET
and thus are designed assuming DTV entries are biased by that value,
ti_offset normally has TLS_DTV_OFFSET pre-subtracted, but it's
__tls_get_addr's responsibility to compensate for that. By using an
offset of zero here, tls_get_addr_slow will return a pointer to the
start of the TLS block itself, so by adding TLS_DTV_OFFSET we will point
TLS_DTV_OFFSET past the module's TLS block.

Fix this by removing the extra bias (the alternative would be to pass
-TLS_DTV_OFFSET and keep the addition, which would more closely follow
what __tls_get_addr does, but this is more direct).

(Note this also applies to MIPS on stable/13)

Fixes: d36d68161517 ("rtld dl_iterate_phdr(): dlpi_tls_data is wrong")
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable