Bug 28008 - [Feature request] dlopen_from function
Summary: [Feature request] dlopen_from function
Status: RESOLVED DUPLICATE of bug 25114
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 28927 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-06-23 12:04 UTC by jakobrs100+sourceware
Modified: 2022-02-28 19:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jakobrs100+sourceware 2021-06-23 12:04:28 UTC
The behaviour of certain functions in libdl[^2] like the `dlopen`
function is dependent on where it is called from. This is normally
what you want, but sometimes you may want to specify the caller
address yourself, for example when intercepting/hooking the `dlopen`
function itself. For this reason, Apple has added the `dlopen_from`
function in macOS Big Sur. `dlopen_from` has an extra parameter, `void
*caller`, that specifies the "fake" caller address to be used instead
of `RETURN_ADDRESS(0)`[^3]. Using `dlopen_from` significantly
simplifies intercepting `dlopen` calls (see [here][1] for an example).
So my feature request is to implement `dlopen_from` in glibc too.

[1]: <https://github.com/clementgallet/libTAS/blob/70966f9e1f400dfdd5176bba63c11cb6026d3da6/src/library/dlhook.cpp#L108-L189>
[^2]: The same logic also applies to `dlmopen`, `dlsym`, and `dlvsym`.
[^3]: Header file where `dlopen_from` is declared:
<https://opensource.apple.com/source/dyld/dyld-832.7.3/include/dlfcn_private.h.auto.html>

(From libc-help here: <https://sourceware.org/pipermail/libc-help/2021-June/005910.html>)
Comment 1 Florian Weimer 2022-02-28 19:52:35 UTC
*** Bug 28927 has been marked as a duplicate of this bug. ***
Comment 2 Florian Weimer 2022-02-28 19:53:52 UTC
It turns out we have an even earlier RFE for this.

In the meantime, you might consider using LD_AUDIT.

*** This bug has been marked as a duplicate of bug 25114 ***