This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Constructor of external lib called too early
- From: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: vogt at linux dot vnet dot ibm dot com, libc-help <libc-help at sourceware dot org>
- Date: Mon, 29 Jul 2013 19:34:19 +0530
- Subject: Re: Constructor of external lib called too early
- References: <20130729125543 dot GA24620 at linux dot vnet dot ibm dot com> <CAAHN_R2MMfomN9u=KnEWXUo=GpJP33WJEkrSX9AQj-Nsmna4tQ at mail dot gmail dot com> <51F671CC dot 4070808 at redhat dot com>
On 29 July 2013 19:14, Florian Weimer <fweimer@redhat.com> wrote:
> On 07/29/2013 03:16 PM, Siddhesh Poyarekar wrote:
>
>> The constructors are usually called like this from the linker:
>>
>> if (l->l_info[DT_INIT] != NULL)
>> {
>> init_t init = (init_t) DL_DT_INIT_ADDRESS
>> (l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr);
>>
>> /* Call the function. */
>> init (argc, argv, env);
>> }
>>
>> So if your constructor accepts argc, argv and envp, you might be able
>> to get the environment from its argument. This is a NULL terminated
>> array, so you will have to do your own traversal and matching. I
>> don't know if this is documented anywhere, so I don't know if it is
>> the canonical way to do this.
>>
>> You also have to make sure you don't traverse the environment if the
>> executed binary is suid.
>
>
> Will getauxval(AT_SECURE) work at this point? Is there some other way to
> access the auxiliary vector (besides parsing /proc)?
getauxval won't work since its internal structures are only
initialized a little before calling program main. You could traverse
to the end of envp and access the auxv drectly though.
Siddhesh
--
http://siddhesh.in