s: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dVRBw1z8MzCkm for ; Mon, 15 Dec 2025 17:00:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e873 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 17:00:24 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 79b0a953ada4 - stable/14 - rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 79b0a953ada4c516c43f163c51d3f083da666d59 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 17:00:24 +0000 Message-Id: <69403ea8.e873.327df7d5@gitrepo.freebsd.org> The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=79b0a953ada4c516c43f163c51d3f083da666d59 commit 79b0a953ada4c516c43f163c51d3f083da666d59 Author: Jessica Clarke AuthorDate: 2025-05-06 22:14:51 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 16:58:44 +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 00e805c5c4c9..a44a5e303dcc 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4269,7 +4269,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; }