[PATCH 1/5] elf: Fix audit regression

Florian Weimer fweimer@redhat.com
Wed Jul 7 20:07:13 GMT 2021


* Florian Weimer:

> * Andreas Schwab:
>
>> On Jul 07 2021, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> @@ -771,7 +771,7 @@ dl_open_worker (void *a)
>>>      {
>>>        struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map;
>>>  #ifdef SHARED
>>> -      bool initial = libc_map->l_ns == LM_ID_BASE;
>>> +      bool initial = libc_map != NULL ? libc_map->l_ns == LM_ID_BASE : false;
>>
>>          bool initial = libc_map != NULL && libc_map->l_ns == LM_ID_BASE;
>
> True … but:
>
> This is only used by dlopen/dlmopen, right?  And even if dlmopen is
> called from an auditor (to load another libc), it is *never* the initial
> libc in the base namespace.
>
> The actual base namespace libc is handled in elf/rtld.c:dl_main:
>
>   /* Relocation is complete.  Perform early libc initialization.  This
>      is the initial libc, even if audit modules have been loaded with
>      other libcs.  */
>   _dl_call_libc_early_init (GL(dl_ns)[LM_ID_BASE].libc_map, true);
>
> And I think the dl_open_worker should mirror that and just do:
>
>   if (!args->libc_already_loaded)
>     /* This is never the initial libc because it has been loaded via
>        dlmopen.  */
>     _dl_call_libc_early_init (libc_map, false);

Eh, or rather:

  if (!args->libc_already_loaded)
    {
      struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map;
      /* This is never the initial libc because it has been loaded via
         dlmopen.  */
      _dl_call_libc_early_init (libc_map, false);
    }

(_dl_call_libc_early_init checks for a null link map.)

Thanks,
Florian



More information about the Libc-alpha mailing list