Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around dlopen not working properly under sanitizer instrumentation #46255

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

Keno
Copy link
Member

@Keno Keno commented Aug 4, 2022

dlopen has a mis-feature where it looks at the return address to determine
the calling object to look at it's RUNPATH. Because asan intercepts dlopen,
the calling object check finds asan rather than julia, causing an incorrect
RUNPATH (and other flags to be used). Arguably, this is mostly a libc problem,
because there isn't really a way to directly specify the resolution scope.
I have sent a proposal to libc-coord [1] to fix this, but of course, we can't
wait for that to percolate down to us. Instead, this takes advantage of the
fact that almost all of our dlopen calls go through a single entrypoint in
jl_dlopen, so we can insert additional logic here to make this work. This
doesn't catch uses of dlopen in jlls (which is a problem for things like
plugin loading in various jlls), but it at least makes base julia work.
We can punt the jll question to another day - either with a patched libc
in PkgEval or by patching the jll source with an analogous patch.

Regardless, with this, Julia bootstraps properly under asan, without any
special LD_LIBRARY_PATH hacks.

[1] https://www.openwall.com/lists/libc-coord/2022/08/04/1

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 5, 2022

`dlopen` has a mis-feature where it looks at the return address to determine
the calling object to look at it's RUNPATH. Because asan intercepts `dlopen`,
the calling object check finds asan rather than julia, causing an incorrect
RUNPATH (and other flags to be used). Arguably, this is mostly a libc problem,
because there isn't really a way to directly specify the resolution scope.
I have sent a proposal to libc-coord [1] to fix this, but of course, we can't
wait for that to percolate down to us. Instead, this takes advantage of the
fact that almost all of our dlopen calls go through a single entrypoint in
jl_dlopen, so we can insert additional logic here to make this work. This
doesn't catch uses of `dlopen` in jlls (which is a problem for things like
plugin loading in various jlls), but it at least makes base julia work.
We can punt the jll question to another day - either with a patched libc
in PkgEval or by patching the jll source with an analogous patch.

Regardless, with this, Julia bootstraps properly under asan, without any
special LD_LIBRARY_PATH hacks.

[1] https://www.openwall.com/lists/libc-coord/2022/08/04/1
@Keno Keno merged commit 0e3e00d into master Aug 12, 2022
@Keno Keno deleted the kf/dlopenasan branch August 12, 2022 22:18
pcjentsch pushed a commit to pcjentsch/julia that referenced this pull request Aug 18, 2022
…on (JuliaLang#46255)

`dlopen` has a mis-feature where it looks at the return address to determine
the calling object to look at it's RUNPATH. Because asan intercepts `dlopen`,
the calling object check finds asan rather than julia, causing an incorrect
RUNPATH (and other flags to be used). Arguably, this is mostly a libc problem,
because there isn't really a way to directly specify the resolution scope.
I have sent a proposal to libc-coord [1] to fix this, but of course, we can't
wait for that to percolate down to us. Instead, this takes advantage of the
fact that almost all of our dlopen calls go through a single entrypoint in
jl_dlopen, so we can insert additional logic here to make this work. This
doesn't catch uses of `dlopen` in jlls (which is a problem for things like
plugin loading in various jlls), but it at least makes base julia work.
We can punt the jll question to another day - either with a patched libc
in PkgEval or by patching the jll source with an analogous patch.

Regardless, with this, Julia bootstraps properly under asan, without any
special LD_LIBRARY_PATH hacks.

[1] https://www.openwall.com/lists/libc-coord/2022/08/04/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants