Page MenuHomeFreeBSD

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

Authored by jrtc27 on May 5 2025, 11:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jul 12, 1:16 AM
Unknown Object (File)
Sat, Jul 5, 3:04 PM
Unknown Object (File)
Wed, Jun 25, 12:57 PM
Unknown Object (File)
Sat, Jun 21, 1:20 PM
Unknown Object (File)
Sat, Jun 21, 11:07 AM
Unknown Object (File)
Thu, Jun 19, 11:36 AM
Unknown Object (File)
Jun 10 2025, 6:44 PM
Unknown Object (File)
Jun 1 2025, 2:58 PM
Subscribers

Details

Summary

The implementation of dl_iterate_phdr for statically-linked binaries
abuses tls_get_addr to get to the start of the TLS block. 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. By using an offset of zero
here we end up getting a pointer TLS_DTV_OFFSET past what
tls_get_addr
would return for the first TLS variable.

Fix this by using -TLS_DTV_OFFSET to mirror what the General Dynamic GOT
entry for the first TLS variable would be.

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

Fixes: dbd2053026a6 ("libc 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