public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] vDSO fixes
@ 2004-02-26 17:26 Jakub Jelinek
  2004-02-26 20:08 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-02-26 17:26 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers, mingo

Hi!

This patch fixes 3 problems with vDSOs:
1) assertion failure if AT_SYSINFO_EHDR is passed to ld.so and
   one runs e.g. elf/ld.so ./libc.so
   (the code needs to take into account the vDSO which is in the
   dl_loaded chain, yet not in the search list
2) if AT_SYSINFO has been passed to the app, IMHO ld.so should honor it,
   not unconditionally overwrite it with e_entry of the vDSO pointed
   by AT_SYSINFO_EHDR
3) ld.so did not handle randomized vDSO properly (although there is code
   which handles relocation of .dynamic in such cases,
   a) e_entry for GL(dl_sysinfo) has not been adjusted
   b) l_addr and l_map_end have not been computed properly
   c) there was an assertion that l_addr is 0)

To test this (don't have a kernel with randomized vDSO yet), I added
open/mmap/close of vsyscall.so into dl-sysdep.c and tweaked
GL(dl_sysinfo_dso) and GL(dl_sysinfo) accordingly (on AMD64 for 32-bit app,
and syscall insn doesn't need fixed return address, so I did not need
kernel changes).

2004-02-26  Jakub Jelinek  <jakub@redhat.com>

	* elf/rtld.c (dl_main): Correctly set up l_map_end and l_addr
	in vDSO's link_map, don't assume l_addr == 0.  Set GL(dl_sysinfo)
	from e_entry only if AT_SYSINFO not present and adjust by l_addr.
	Take vDSO into account when inserting rtld into _dl_loaded chain.

--- libc/elf/rtld.c	20 Feb 2004 05:40:40 -0000	1.313
+++ libc/elf/rtld.c	26 Feb 2004 17:02:38 -0000
@@ -1211,11 +1211,9 @@ ERROR: ld.so: object '%s' from %s cannot
     }
 
 #ifdef NEED_DL_SYSINFO
+  struct link_map *sysinfo_map = NULL;
   if (GL(dl_sysinfo_dso) != NULL)
     {
-      /* We have a prelinked DSO preloaded by the system.  */
-      GL(dl_sysinfo) = GL(dl_sysinfo_dso)->e_entry;
-
       /* Do an abridged version of the work _dl_map_object_from_fd would do
 	 to map in the object.  It's already mapped and prelinked (and
 	 better be, since it's read-only and so we couldn't relocate it).
@@ -1225,9 +1223,6 @@ ERROR: ld.so: object '%s' from %s cannot
       if (__builtin_expect (l != NULL, 1))
 	{
 	  static ElfW(Dyn) dyn_temp[DL_RO_DYN_TEMP_CNT];
-#ifndef NDEBUG
-	  uint_fast16_t pt_load_num = 0;
-#endif
 
 	  l->l_phdr = ((const void *) GL(dl_sysinfo_dso)
 		       + GL(dl_sysinfo_dso)->e_phoff);
@@ -1239,21 +1234,21 @@ ERROR: ld.so: object '%s' from %s cannot
 		{
 		  l->l_ld = (void *) ph->p_vaddr;
 		  l->l_ldnum = ph->p_memsz / sizeof (ElfW(Dyn));
-		  break;
 		}
-#ifndef NDEBUG
-	      if (ph->p_type == PT_LOAD)
+	      else if (ph->p_type == PT_LOAD)
 		{
-		  assert (pt_load_num
-			  || (void *) ph->p_vaddr == GL(dl_sysinfo_dso));
-		  pt_load_num++;
+		  if (! l->l_addr)
+		    l->l_addr = ph->p_vaddr;
+		  else if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
+		    l->l_map_end = ph->p_vaddr + ph->p_memsz;
 		}
-#endif
 	    }
+	  l->l_map_start = (ElfW(Addr)) GL(dl_sysinfo_dso);
+	  l->l_addr = l->l_map_start - l->l_addr;
+	  l->l_map_end += l->l_addr;
 	  elf_get_dynamic_info (l, dyn_temp);
 	  _dl_setup_hash (l);
 	  l->l_relocated = 1;
-	  l->l_map_start = (ElfW(Addr)) GL(dl_sysinfo_dso);
 
 	  /* Now that we have the info handy, use the DSO image's soname
 	     so this object can be looked up by name.  Note that we do not
@@ -1271,6 +1266,11 @@ ERROR: ld.so: object '%s' from %s cannot
 		_dl_fatal_printf ("out of memory\n");
 	      l->l_libname->name = memcpy (copy, dsoname, len);
 	    }
+
+	  /* We have a prelinked DSO preloaded by the system.  */
+	  if (GL(dl_sysinfo) == DL_SYSINFO_DEFAULT)
+	    GL(dl_sysinfo) = GL(dl_sysinfo_dso)->e_entry + l->l_addr;
+	  sysinfo_map = l;
 	}
     }
 #endif
@@ -1316,9 +1316,17 @@ ERROR: ld.so: object '%s' from %s cannot
 	++i;
       GL(dl_rtld_map).l_prev = GL(dl_loaded)->l_searchlist.r_list[i - 1];
       if (__builtin_expect (mode, normal) == normal)
-	GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist
-				  ? GL(dl_loaded)->l_searchlist.r_list[i + 1]
-				  : NULL);
+	{
+	  GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist
+				    ? GL(dl_loaded)->l_searchlist.r_list[i + 1]
+				    : NULL);
+#ifdef NEED_DL_SYSINFO
+	  if (sysinfo_map != NULL
+	      && GL(dl_rtld_map).l_prev->l_next == sysinfo_map
+	      && GL(dl_rtld_map).l_next != sysinfo_map)
+	    GL(dl_rtld_map).l_prev = sysinfo_map;
+#endif
+	}
       else
 	/* In trace mode there might be an invisible object (which we
 	   could not find) after the previous one in the search list.

	Jakub

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

* Re: [PATCH] vDSO fixes
  2004-02-26 17:26 [PATCH] vDSO fixes Jakub Jelinek
@ 2004-02-26 20:08 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-02-26 20:08 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers, mingo

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

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

end of thread, other threads:[~2004-02-26 20:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-26 17:26 [PATCH] vDSO fixes Jakub Jelinek
2004-02-26 20:08 ` Ulrich Drepper

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).