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)
Sat, Oct 4, 7:45 AM
Unknown Object (File)
Sep 16 2025, 9:47 PM
Unknown Object (File)
Sep 9 2025, 5:17 AM
Unknown Object (File)
Aug 31 2025, 10:11 AM
Unknown Object (File)
Aug 19 2025, 1:02 AM
Unknown Object (File)
Aug 11 2025, 3:58 PM
Unknown Object (File)
Jul 29 2025, 9:46 AM
Unknown Object (File)
Jul 28 2025, 10:56 AM
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