unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Assert that objects are relocated before their constructors run
@ 2019-09-11  9:57 Florian Weimer
  2019-09-11 12:35 ` Carlos O'Donell
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2019-09-11  9:57 UTC (permalink / raw)
  To: libc-alpha

If we try to run constructors before relocation, this is always
a dynamic linker bug.  An assert is easier to notice than a call
via an invalid function pointer (which may not even produce a valid
call stack).

2019-09-11  Florian Weimer  <fweimer@redhat.com>

	* elf/dl-init.c (call_init): Assert that the object has been
	relocated.

diff --git a/elf/dl-init.c b/elf/dl-init.c
index 3721bca81e..a998992544 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <assert.h>
 #include <stddef.h>
 #include <ldsodefs.h>
 
@@ -27,6 +28,11 @@ typedef void (*init_t) (int, char **, char **);
 static void
 call_init (struct link_map *l, int argc, char **argv, char **env)
 {
+  /* If the object has not been relocated, this is a bug.  The
+     function pointers are invalid in this case.  (Executables do not
+     need relocation, and neither do proxy objects.)  */
+  assert (l->l_real->l_relocated || l->l_real->l_type == lt_executable);
+
   if (l->l_init_called)
     /* This object is all done.  */
     return;

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

* Re: [PATCH] elf: Assert that objects are relocated before their constructors run
  2019-09-11  9:57 [PATCH] elf: Assert that objects are relocated before their constructors run Florian Weimer
@ 2019-09-11 12:35 ` Carlos O'Donell
  2020-05-18 13:39   ` Florian Weimer via Libc-alpha
  0 siblings, 1 reply; 3+ messages in thread
From: Carlos O'Donell @ 2019-09-11 12:35 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 9/11/19 5:57 AM, Florian Weimer wrote:
> If we try to run constructors before relocation, this is always
> a dynamic linker bug.  An assert is easier to notice than a call
> via an invalid function pointer (which may not even produce a valid
> call stack).
> 
> 2019-09-11  Florian Weimer  <fweimer@redhat.com>
> 
> 	* elf/dl-init.c (call_init): Assert that the object has been
> 	relocated.

OK for master.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> diff --git a/elf/dl-init.c b/elf/dl-init.c
> index 3721bca81e..a998992544 100644
> --- a/elf/dl-init.c
> +++ b/elf/dl-init.c
> @@ -16,6 +16,7 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#include <assert.h>
>  #include <stddef.h>
>  #include <ldsodefs.h>
>  
> @@ -27,6 +28,11 @@ typedef void (*init_t) (int, char **, char **);
>  static void
>  call_init (struct link_map *l, int argc, char **argv, char **env)
>  {
> +  /* If the object has not been relocated, this is a bug.  The
> +     function pointers are invalid in this case.  (Executables do not
> +     need relocation, and neither do proxy objects.)  */
> +  assert (l->l_real->l_relocated || l->l_real->l_type == lt_executable);

OK. Use l_real for namespace support to work.

> +
>    if (l->l_init_called)
>      /* This object is all done.  */
>      return;
> 


-- 
Cheers,
Carlos.

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

* Re: [PATCH] elf: Assert that objects are relocated before their constructors run
  2019-09-11 12:35 ` Carlos O'Donell
@ 2020-05-18 13:39   ` Florian Weimer via Libc-alpha
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer via Libc-alpha @ 2020-05-18 13:39 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha

* Carlos O'Donell:

> On 9/11/19 5:57 AM, Florian Weimer wrote:
>> If we try to run constructors before relocation, this is always
>> a dynamic linker bug.  An assert is easier to notice than a call
>> via an invalid function pointer (which may not even produce a valid
>> call stack).
>> 
>> 2019-09-11  Florian Weimer  <fweimer@redhat.com>
>> 
>> 	* elf/dl-init.c (call_init): Assert that the object has been
>> 	relocated.
>
> OK for master.
>
> Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Thanks.  I've finally pushed this.

Thanks,
Florian


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

end of thread, other threads:[~2020-05-18 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11  9:57 [PATCH] elf: Assert that objects are relocated before their constructors run Florian Weimer
2019-09-11 12:35 ` Carlos O'Donell
2020-05-18 13:39   ` Florian Weimer via Libc-alpha

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