Date: Mon, 15 Dec 2025 18:18:51 +0000 From: Jessica Clarke <jrtc27@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: c9793e87025e - stable/13 - rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V Message-ID: <6940510b.25540.698474df@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=c9793e87025e0495bad680e0a1ad6fc174c508c6 commit c9793e87025e0495bad680e0a1ad6fc174c508c6 Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-05-06 22:14:51 +0000 Commit: Jessica Clarke <jrtc27@FreeBSD.org> CommitDate: 2025-12-15 17:56:36 +0000 rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V 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) Reviewed by: kib Fixes: d36d68161517 ("rtld dl_iterate_phdr(): dlpi_tls_data is wrong") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50184 (cherry picked from commit c02aaba1b4549c1c3b1481f7c935f6cc80b98e8d) --- libexec/rtld-elf/rtld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index a43c6e3c7cda..1cab00bb1c59 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4263,7 +4263,7 @@ rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info) phdr_info->dlpi_tls_modid = obj->tlsindex; dtvp = &_tcb_get()->tcb_dtv; phdr_info->dlpi_tls_data = (char *)tls_get_addr_slow(dtvp, - obj->tlsindex, 0, true) + TLS_DTV_OFFSET; + obj->tlsindex, 0, true); phdr_info->dlpi_adds = obj_loads; phdr_info->dlpi_subs = obj_loads - obj_count; }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6940510b.25540.698474df>
