elf: Do not copy vDSO soname when setting up link map

Message ID 871rdli4ce.fsf@oldenburg.str.redhat.com
State Committed
Commit ebcf45a16ca981c8515f88db94e757cfc6fe4b35
Headers
Series elf: Do not copy vDSO soname when setting up link map |

Commit Message

Florian Weimer Feb. 12, 2021, 5:27 p.m. UTC
  The kernel does not put the vDSO at special addresses, so writev can
write the name directly.  Also remove the incorrect comment about not
setting l_name.

Andy Lutomirski confirmed in
<https://lore.kernel.org/linux-api/442A16C0-AE5A-4A44-B261-FE6F817EAF3C@amacapital.net/>
that this copy is not necessary.

---
 elf/setup-vdso.h | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
  

Comments

Adhemerval Zanella Netto Feb. 12, 2021, 5:29 p.m. UTC | #1
On 12/02/2021 14:27, Florian Weimer via Libc-alpha wrote:
> The kernel does not put the vDSO at special addresses, so writev can
> write the name directly.  Also remove the incorrect comment about not
> setting l_name.
> 
> Andy Lutomirski confirmed in
> <https://lore.kernel.org/linux-api/442A16C0-AE5A-4A44-B261-FE6F817EAF3C@amacapital.net/>
> that this copy is not necessary.
> 

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  elf/setup-vdso.h | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
> index ece840df38..86c491e49c 100644
> --- a/elf/setup-vdso.h
> +++ b/elf/setup-vdso.h
> @@ -80,20 +80,13 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
>        l->l_local_scope[0]->r_list = &l->l_real;
>  
>        /* 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
> -	 set l_name here.  That field gives the file name of the DSO,
> -	 and this DSO is not associated with any file.  */
> +	 so this object can be looked up by name.  */
>        if (l->l_info[DT_SONAME] != NULL)
>  	{
> -	  /* Work around a kernel problem.  The kernel cannot handle
> -	     addresses in the vsyscall DSO pages in writev() calls.  */
> -	  const char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
> -				 + l->l_info[DT_SONAME]->d_un.d_val);
> -	  size_t len = strlen (dsoname) + 1;
> -	  char *copy = malloc (len);
> -	  if (copy == NULL)
> -	    _dl_fatal_printf ("out of memory\n");
> -	  l->l_libname->name = l->l_name = memcpy (copy, dsoname, len);
> +	  char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
> +			   + l->l_info[DT_SONAME]->d_un.d_val);
> +	  l->l_libname->name = dsoname;
> +	  l->l_name = dsoname;
>  	}
>  
>        /* Add the vDSO to the object list.  */
>
  

Patch

diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
index ece840df38..86c491e49c 100644
--- a/elf/setup-vdso.h
+++ b/elf/setup-vdso.h
@@ -80,20 +80,13 @@  setup_vdso (struct link_map *main_map __attribute__ ((unused)),
       l->l_local_scope[0]->r_list = &l->l_real;
 
       /* 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
-	 set l_name here.  That field gives the file name of the DSO,
-	 and this DSO is not associated with any file.  */
+	 so this object can be looked up by name.  */
       if (l->l_info[DT_SONAME] != NULL)
 	{
-	  /* Work around a kernel problem.  The kernel cannot handle
-	     addresses in the vsyscall DSO pages in writev() calls.  */
-	  const char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
-				 + l->l_info[DT_SONAME]->d_un.d_val);
-	  size_t len = strlen (dsoname) + 1;
-	  char *copy = malloc (len);
-	  if (copy == NULL)
-	    _dl_fatal_printf ("out of memory\n");
-	  l->l_libname->name = l->l_name = memcpy (copy, dsoname, len);
+	  char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
+			   + l->l_info[DT_SONAME]->d_un.d_val);
+	  l->l_libname->name = dsoname;
+	  l->l_name = dsoname;
 	}
 
       /* Add the vDSO to the object list.  */