]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: elf: make sure dlpi_phdr covers the load segments
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 14 Sep 2022 13:04:18 +0000 (14:04 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:54 +0000 (14:46 +0100)
In dl_iterate_phdr phdr is the only capability passed to the callback
that may be used to derive pointers of the elf module, so ensure it
has wide bounds.

elf/dl-iteratephdr.c

index 146850b88a7ac9e7e5c06b568358115395d18e9f..bd2588fae84ab5fdc845f7200397c97e9b6d85b9 100644 (file)
@@ -69,7 +69,12 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
       info.dlpi_addr = l->l_real->l_addr;
 #endif
       info.dlpi_name = l->l_real->l_name;
+#ifdef __CHERI_PURE_CAPABILITY__
+      ElfW(Addr) phdr = (ElfW(Addr)) l->l_real->l_phdr - l->l_real->l_addr;
+      info.dlpi_phdr = (const void *) dl_rx_ptr (l->l_real, phdr);
+#else
       info.dlpi_phdr = l->l_real->l_phdr;
+#endif
       info.dlpi_phnum = l->l_real->l_phnum;
       info.dlpi_adds = GL(dl_load_adds);
       info.dlpi_subs = GL(dl_load_adds) - nloaded;