This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/3] elf: Allow dlopen of filter object to work [BZ #16272]
- From: David Kilroy <David dot Kilroy at arm dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, nd <nd at arm dot com>
- Date: Fri, 18 Oct 2019 15:09:10 +0000
- Subject: Re: [PATCH 1/3] elf: Allow dlopen of filter object to work [BZ #16272]
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1kSiBzVLkHpDL1gGTkVFFI02JqvfpCvj3uwozRKY04Q=; b=L6cDnE7kDLveD9alrQ1OaPNCkQ4jLvKP6xSYKN5KF2pHKTw/HCSF8sAh+Po0lFVYIB1/VDtIAgoraz7pNNJQk77DlsDW3B5SUG0vxCICqgBrMF+VlhFlq69XHSPWzPQLVNIA5uGp4kaX1QB8tkgfjX74oQh51pYVjKDE2XFZNQS5K0KbK4sFxGzMtPWdfhP4xMzM60ltez4JROWRHjrqhn1ZagwmEEoLpQ3/Czm89hINImw433H2uCe4aY10grdGXqSms6nBzdqmNhtr2IXrREGv8sSZT+tQlH0C/7zYNPSJV7LmTzjFFXHJ+Zh87FBgAzlv6uM4XoL/fJ1g8Snk3A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZF7JOBiQawMPkjr7Dxktyvoi/+04eoDsrajlHOAtWjdRrUInKEcgvDqlyFERkFBK4Jc9GxXL3H25PDcqKhKL+uIpaRd/LjVaDe+ykyIDdXBL3k0CdiJBTCY5qmP1s520wst0cQw6VBsKsK2iuIuaRSh+rbVjyAY1cwt9ZNArSCKmpCnW4Xzohl08R7AnoGYMX8kNMibqXZ57drBrSKj8tyJ4RkkkNasEQlmVmpndfdRlC11g6xVxEfv3PiFaOSBD+gZixKaq4wCwzX+yTjPAZmkS1hofsmjzPvFFfcLJSd2ydtGHg+oVohvs/8NgeBFlnyTl4UVi7pZyfRwSY7A9bg==
- Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=David dot Kilroy at arm dot com;
- References: <cover.1571301957.git.david.kilroy@arm.com> <4eae391688a6e42b0b75467de265c122e6402668.1571301957.git.david.kilroy@arm.com>,<87r23ath25.fsf@oldenburg2.str.redhat.com>
Hi Florian,
Thanks for the detailed review. Apologies for the various formatting issues,
I haven't got used the GNU style yet. I'll attempt to correct this in the
next submission.
From: Florian Weimer <fweimer@redhat.com>
>* David Kilroy:
>
>> diff --git a/elf/Makefile b/elf/Makefile
>> index 8f96299..55bed87 100644
>> --- a/elf/Makefile
>> +++ b/elf/Makefile
>> @@ -279,7 +280,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
>> tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \
>> tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib \
>> tst-audit13mod1 tst-sonamemove-linkmod1 \
>> - tst-sonamemove-runmod1 tst-sonamemove-runmod2
>> + tst-sonamemove-runmod1 tst-sonamemove-runmod2 \
>> + tst-filterobj-flt tst-filterobj-lib
>
>This needs rebasing to current master. Unfortunately, I've got various
>patches in flight which conflict.
Will do. I think the main conflicts are in the Makefile where we are both
adding tests. I've seen that you're also touching dl_open_worker, but
so far it looks like the changes are in different areas.
>> +LDFLAGS-tst-filterobj-flt.so=-Wl,--filter=$(objpfx)tst-filterobj-lib.so
>> +CFLAGS-tst-filterobj-dlopen.c += -DPFX=\"$(objpfx)\"
>> +$(objpfx)tst-filterobj: $(objpfx)tst-filterobj-flt.so | $(objpfx)tst-filterobj-lib.so
>> +$(objpfx)tst-filterobj-dlopen: $(libdl) | $(objpfx)tst-filterobj-lib.so
>
>Please use spaces around operators. To add a run-time dependency to
>tst-filterobj-dlopen, use something like this, please:
>
>$(objpfx)tst-filterobj-dlopen.out : $(objpfx)tst-filterobj-lib.so
>
>This way, the test is re-run if tst-filterobj-lib.so changed.
Well, spotted! Will do.
>> diff --git a/elf/dl-deps.c b/elf/dl-deps.c
>> index c29b988..c177cef 100644
>> --- a/elf/dl-deps.c
>> +++ b/elf/dl-deps.c
>These changes look reasonable to me.
That's good to know. I tried a few different things before I realised I needed
to fix up the relocations as well.
>But please use spaces around operators.
>
>(Not sure if you want to commit this yourself; if not, I can clean up
>such things for you prior to committing.)
I doubt I have commit access (this is my first submission), but I will attempt
to fix all formatting issues.
>> diff --git a/elf/dl-open.c b/elf/dl-open.c
>> index a9fd4cb..7fcfdc0 100644
>> --- a/elf/dl-open.c
>> +++ b/elf/dl-open.c
>> @@ -305,22 +305,25 @@ dl_open_worker (void *a)
>> allows IFUNC relocations to work and it also means copy
>> relocation of dependencies are if necessary overwritten. */
>> unsigned int nmaps = 0;
>> - struct link_map *l = new;
>> + unsigned int j = 0;
>> + struct link_map *l = new->l_initfini[0];
>> do
>> {
>> if (! l->l_real->l_relocated)
>> ++nmaps;
>> - l = l->l_next;
>> + l = new->l_initfini[++j];
>> }
>> while (l != NULL);
>> + /* Stack allocation is limited by the number of loaded objects. */
>> struct link_map *maps[nmaps];
>> nmaps = 0;
>> - l = new;
>> + j = 0;
>> + l = new->l_initfini[0];
>> do
>> {
>> if (! l->l_real->l_relocated)
>> maps[nmaps++] = l;
>> - l = l->l_next;
>> + l = new->l_initfini[++j];
>> }
>> while (l != NULL);
>> _dl_sort_maps (maps, nmaps, NULL, false);
>
>I have much more trouble ascertaining whether this change is correct.
>Are we certain that new->l_initfini is not a subset of the maps that
>have been loaded?
That is something I'm not sure about (yet). I'll look into this further. My
reasoning for switching to using l_initfini was that the filtee's constructors
were crashing, and clearly anything that needed initialisation ought to be
relocated first. If I can't confirm whether l_initfini is a subset, there are a
couple alternatives here:
* I can verify that the filter is in l->l_prev, and walk that before
constructing map via l->l_next.
* after relocating via l->l_next, check l_initfini for any un-relocated
objects.
Both of these would invalidate the following patches.
>> diff --git a/elf/tst-filterobj-dlopen.c b/elf/tst-filterobj-dlopen.c
>> new file mode 100644
>> index 0000000..7c24a1d
>> --- /dev/null
>> +++ b/elf/tst-filterobj-dlopen.c
>> +int main (int argc, const char**argv)
>> +{
>> + void *lib = dlopen (PFX "tst-filterobj-flt.so", RTLD_LAZY);
>
>I think you should use xasprintf and support_objdir_root from
><support/support.h> to construct the path. Alternatively, you can drop
>this completely because it will be on the library search path set up by
>the test framework.
So PFX ($(objpfx) in the makefile) is just a path that will be on the
library search path? I assumed it might be a file prefix too. This is
something I copied from an existing dlopen test (I don't have the code
to hand to double check this).
>> + printf ("%s\n", text);
>> +
>> + /* Verify the text matches what we expect from the filtee */
>> + result = strcmp (text, "Hello from filtee (PASS)") != 0;
>> + }
>> + else
>> + {
>> + fprintf (stderr, "No function\n");
>
>Please use the test framework (<support/test-driver.c>,
><support/check.h>, <support/xdlfcn.h>) and TEST_COMPARE_STRING.
>Tests should write to standard output only.
Will do.
Regards,
Dave.