git: 175595ba6c52 - main - dl_iterate_phdr(3): do not return garbage for objects not using TLS
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 25 Oct 2026 17:34:33 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=175595ba6c5253e395c028e792787dffd2875910
commit 175595ba6c5253e395c028e792787dffd2875910
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-25 15:35:21 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-10-25 17:33:46 +0000
dl_iterate_phdr(3): do not return garbage for objects not using TLS
For objects without a TLS segment, tlsindex is zero. tls_get_addr_slow()
then reads dtv_slots[-1], which is dtv_size, and returns it as the TLS
address. Set dlpi_tls_data to NULL for such objects instead.
Fixes: d36d68161517 ("rtld dl_iterate_phdr(): dlpi_tls_data is wrong")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
---
libexec/rtld-elf/rtld.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 877449296643..7ca5f9ada09f 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -4436,8 +4436,12 @@ rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info)
phdr_info->dlpi_phdr = obj->phdr;
phdr_info->dlpi_phnum = obj->phnum;
phdr_info->dlpi_tls_modid = obj->tlsindex;
- phdr_info->dlpi_tls_data = (char *)tls_get_addr_slow(_tcb_get(),
- obj->tlsindex, 0, true);
+ if (obj->tlsindex != 0) {
+ phdr_info->dlpi_tls_data = tls_get_addr_slow(_tcb_get(),
+ obj->tlsindex, 0, true);
+ } else {
+ phdr_info->dlpi_tls_data = NULL;
+ }
phdr_info->dlpi_adds = obj_loads;
phdr_info->dlpi_subs = obj_loads - obj_count;
}