public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: elf: Use RW permissions for l_ld when needed
@ 2022-10-27 13:58 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:58 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c3e46aa5d253c23ca3828538127aee15efbabfc0

commit c3e46aa5d253c23ca3828538127aee15efbabfc0
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Fri Sep 2 14:07:06 2022 +0100

    cheri: elf: Use RW permissions for l_ld when needed
    
    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.)

Diff:
---
 elf/dl-load.c | 4 +++-
 elf/rtld.c    | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 7d74214626..b25ddaec05 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 1dac96c94b..41ffb297e5 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1175,8 +1175,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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [glibc/arm/morello/main] cheri: elf: Use RW permissions for l_ld when needed
@ 2022-11-23 14:48 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:48 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=681ddc91e1f9cb33cf3b1370bd36ab9296f9be38

commit 681ddc91e1f9cb33cf3b1370bd36ab9296f9be38
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Fri Sep 2 14:07:06 2022 +0100

    cheri: elf: Use RW permissions for l_ld when needed
    
    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.)

Diff:
---
 elf/dl-load.c | 4 +++-
 elf/rtld.c    | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 7d74214626..b25ddaec05 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 1dac96c94b..41ffb297e5 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1175,8 +1175,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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [glibc/arm/morello/main] cheri: elf: Use RW permissions for l_ld when needed
@ 2022-10-26 15:20 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:20 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c3fa4c960ae942f6fdbe59cd2006accefa06f426

commit c3fa4c960ae942f6fdbe59cd2006accefa06f426
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Fri Sep 2 14:07:06 2022 +0100

    cheri: elf: Use RW permissions for l_ld when needed
    
    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.)

Diff:
---
 elf/dl-load.c | 4 +++-
 elf/rtld.c    | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 7d74214626..b25ddaec05 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 1dac96c94b..41ffb297e5 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1175,8 +1175,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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [glibc/arm/morello/main] cheri: elf: Use RW permissions for l_ld when needed
@ 2022-10-12 14:17 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-12 14:17 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e841326457b09c3d6af9634fe918a47d61113b04

commit e841326457b09c3d6af9634fe918a47d61113b04
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Fri Sep 2 14:07:06 2022 +0100

    cheri: elf: Use RW permissions for l_ld when needed
    
    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.)

Diff:
---
 elf/dl-load.c | 4 +++-
 elf/rtld.c    | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 367b8cdab1..192ad4f7c9 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 007e938b90..fcb8b9e888 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-23 14:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 13:58 [glibc/arm/morello/main] cheri: elf: Use RW permissions for l_ld when needed Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2022-11-23 14:48 Szabolcs Nagy
2022-10-26 15:20 Szabolcs Nagy
2022-10-12 14:17 Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).