Page MenuHomeFreeBSD

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

Authored by jrtc27 on Mon, May 5, 11:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 20, 2:14 AM
Unknown Object (File)
Mon, May 19, 7:51 PM
Unknown Object (File)
Sat, May 17, 4:57 PM
Unknown Object (File)
Sat, May 17, 4:57 PM
Unknown Object (File)
Fri, May 16, 8:23 AM
Unknown Object (File)
Sun, May 11, 7:00 AM
Unknown Object (File)
Sun, May 11, 4:58 AM
Unknown Object (File)
Thu, May 8, 9:02 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
OSZAR »