diff mbox series

[v3,1/2] elf: Do not run constructors for proxy objects

Message ID ca9c2cfd0f0d09eb65e8dffe971cc62511d32d60.1692701787.git.fweimer@redhat.com
State New
Headers show
Series Predictable ELF destructor ordering (bug 30785) | expand

Commit Message

Florian Weimer Aug. 22, 2023, 10:58 a.m. UTC
Otherwise, the ld.so constructor runs for each audit namespace
and each dlmopen namespace.
---
 elf/dl-init.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Andreas Schwab Aug. 22, 2023, 11:14 a.m. UTC | #1
On Aug 22 2023, Florian Weimer via Libc-alpha wrote:

> diff --git a/elf/dl-init.c b/elf/dl-init.c
> index 5b0732590f..fefd471851 100644
> --- a/elf/dl-init.c
> +++ b/elf/dl-init.c
> @@ -25,6 +25,10 @@
>  static void
>  call_init (struct link_map *l, int argc, char **argv, char **env)
>  {
> +  /* Do not run constructors for proxy objects.  */
> +  if (l != l->l_real)
> +    return;
> +
>    /* 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.)  */

Now that we know that l == l->l_real, the following assertion does not
need to indirect through l_real any more.
Florian Weimer Aug. 22, 2023, 11:25 a.m. UTC | #2
* Andreas Schwab:

> On Aug 22 2023, Florian Weimer via Libc-alpha wrote:
>
>> diff --git a/elf/dl-init.c b/elf/dl-init.c
>> index 5b0732590f..fefd471851 100644
>> --- a/elf/dl-init.c
>> +++ b/elf/dl-init.c
>> @@ -25,6 +25,10 @@
>>  static void
>>  call_init (struct link_map *l, int argc, char **argv, char **env)
>>  {
>> +  /* Do not run constructors for proxy objects.  */
>> +  if (l != l->l_real)
>> +    return;
>> +
>>    /* 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.)  */
>
> Now that we know that l == l->l_real, the following assertion does not
> need to indirect through l_real any more.

Thanks, makes sense.  Okay to push with that change?

@@ -25,10 +25,14 @@
 static void
 call_init (struct link_map *l, int argc, char **argv, char **env)
 {
+  /* Do not run constructors for proxy objects.  */
+  if (l != l->l_real)
+    return;
+
   /* 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);
+  assert (l->l_relocated || l->l_type == lt_executable);
 
   if (l->l_init_called)
     /* This object is all done.  */

Florian
Andreas Schwab Aug. 22, 2023, 11:50 a.m. UTC | #3
On Aug 22 2023, Florian Weimer wrote:

> @@ -25,10 +25,14 @@
>  static void
>  call_init (struct link_map *l, int argc, char **argv, char **env)
>  {
> +  /* Do not run constructors for proxy objects.  */
> +  if (l != l->l_real)
> +    return;
> +
>    /* 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);
> +  assert (l->l_relocated || l->l_type == lt_executable);

The reference to proxy objects in the second comment is obsolete as
well.  Ok with that change.
diff mbox series

Patch

diff --git a/elf/dl-init.c b/elf/dl-init.c
index 5b0732590f..fefd471851 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -25,6 +25,10 @@ 
 static void
 call_init (struct link_map *l, int argc, char **argv, char **env)
 {
+  /* Do not run constructors for proxy objects.  */
+  if (l != l->l_real)
+    return;
+
   /* 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.)  */