]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: elf: Use RW permissions for l_ld when needed
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 2 Sep 2022 13:07:06 +0000 (14:07 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 12 Oct 2022 13:22:03 +0000 (14:22 +0100)
The dynamic section of an executable needs to be written to set the
DT_DEBUG entry for debuggers (unless the target has some other place
to store r_debug). For this reason we make l_ld writable whenever
the dynamic section is writable.

The ld.so l_ld is kept RX, since it does not have DT_DEBUG.
(Note: relocating the dynamic section is not allowed on cheri and
that's the only other reason glibc would write to it.)

elf/dl-load.c
elf/rtld.c

index 367b8cdab12cb2ec5c4ee3d46a9c53549c4b96ef..192ad4f7c9305dfd2b09b18995a681966e27a764 100644 (file)
@@ -1276,7 +1276,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
   }
 
   if (l->l_ld != 0)
-    l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
+    l->l_ld = (ElfW(Dyn) *) (l->l_ld_readonly
+                            ? dl_rx_ptr (l, (elfptr_t) l->l_ld)
+                            : dl_rw_ptr (l, (elfptr_t) l->l_ld));
 
   elf_get_dynamic_info (l, false, false);
 
index 007e938b904f6eacf6bced453f26d6d8a213ec17..fcb8b9e888f72843e0f452e2cd7ca8c57b0734bc 100644 (file)
@@ -1181,8 +1181,10 @@ rtld_setup_main_map (struct link_map *main_map)
       case PT_DYNAMIC:
        /* This tells us where to find the dynamic section,
           which tells us everything we need to do.  */
-       main_map->l_ld = (void *) main_map->l_addr + ph->p_vaddr;
        main_map->l_ld_readonly = (ph->p_flags & PF_W) == 0;
+       main_map->l_ld = (void *) (main_map->l_ld_readonly
+                                  ? dl_rx_ptr (main_map, ph->p_vaddr)
+                                  : dl_rw_ptr (main_map, ph->p_vaddr));
        break;
       case PT_INTERP:
        /* This "interpreter segment" was used by the program loader to