[PATCH] elf: _dl_find_object may return 1 during early startup (bug 30515)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Jun 6 19:45:23 GMT 2023
On 05/06/23 12:40, Florian Weimer via Libc-alpha wrote:
> Success is reported with a 0 return value, and failure is -1.
> Enhance the kitchen sink test elf/tst-audit28 to cover
> _dl_find_object as well.
>
> Fixes commit 5d28a8962dcb ("elf: Add _dl_find_object function")
> and bug 30515.
>
> Tested on x86_64-linux-gnu.
>
> ---
> elf/dl-find_object.c | 2 +-
> elf/tst-auditmod28.c | 9 +++++++++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/elf/dl-find_object.c b/elf/dl-find_object.c
> index 928eb499cc..c1390ee10f 100644
> --- a/elf/dl-find_object.c
> +++ b/elf/dl-find_object.c
> @@ -46,7 +46,7 @@ _dl_find_object_slow (void *pc, struct dl_find_object *result)
> struct dl_find_object_internal internal;
> _dl_find_object_from_map (l, &internal);
> _dl_find_object_to_external (&internal, result);
> - return 1;
> + return 0;
> }
>
> /* Object not found. */
Ok.
> diff --git a/elf/tst-auditmod28.c b/elf/tst-auditmod28.c
> index f6ab991398..ae9c277f5b 100644
> --- a/elf/tst-auditmod28.c
> +++ b/elf/tst-auditmod28.c
> @@ -71,6 +71,15 @@ la_version (unsigned int current)
> TEST_VERIFY (dladdr1 (&_exit, &info, &extra_info, RTLD_DL_LINKMAP) != 0);
> TEST_VERIFY (extra_info == handle);
>
> + /* Check _dl_find_object. */
> + struct dl_find_object dlfo;
> + TEST_COMPARE (_dl_find_object (__builtin_return_address (0), &dlfo), 0);
> + TEST_COMPARE_STRING (basename (dlfo.dlfo_link_map->l_name), LD_SO);
Unfortunately this fails with --enable-hardcoded-path-in-tests, since the INTERP
will be set to ld.so:
x86_64-linux-gnu$ readelf -p .interp elf/tst-audit28
String dump of section '.interp':
[ 0] [...]/x86_64-linux-gnu/elf/ld.so
x86_64-linux-gnu$ make test t=elf/tst-audit28
[...]
FAIL: elf/tst-audit28
original exit status 1
tst-auditmod28.c:77: error: string comparison failed
left string: 5 bytes
right string: 20 bytes
left (evaluated from basename (dlfo.dlfo_link_map->l_name)):
"ld.so"
6C 64 2E 73 6F
right (evaluated from LD_SO):
"ld-linux-x86-64.so.2"
6C 64 2D 6C 69 6E 75 78 2D 78 38 36 2D 36 34 2E 73 6F 2E 32
[...]
Maybe add a check for either ld.so or LD_SO.
> + TEST_COMPARE (_dl_find_object (dlsym (handle, "environ"), &dlfo), 0);
> + TEST_COMPARE_STRING (basename (dlfo.dlfo_link_map->l_name), LIBC_SO);
> + TEST_COMPARE (_dl_find_object ((void *) 1, &dlfo), -1);
> + TEST_COMPARE (_dl_find_object ((void *) -1, &dlfo), -1);
> +
> /* Verify that dlmopen creates a new namespace. */
> void *dlmopen_handle = xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW);
> TEST_VERIFY (dlmopen_handle != handle);
>
> base-commit: 7f0d9e61f40c669fca3cfd1e342fa8236c7220b7
>
More information about the Libc-alpha
mailing list