Do not use RTLD_DEEPBIND if dlmopen is available #18612
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request disables usage of RTLD_DEEPBIND if dlmopen is available.
Context:
After careful consideration, I believe this is the best approach, after considering the following alternatives:
php_embed_init
; this is still SAPI-dependent behavior, which will still cause the same segfaults if jemalloc is used with the embed SAPI.I opted for the much cleaner approach of completely disabling RTLD_DEEPBIND if dlmopen with LM_ID_NEWLM is available, leaving to users the resposibility of isolating libphp.so when including it by using
dlmopen(LM_ID_NEWLM, "libphp.so", RTLD_LAZY);
instead ofdlopen("libphp.so", RTLD_LAZY|RTLD_DEEPBIND);
.dlmopen
provides full recursive isolation for all symbols both in the opened library, and in libraries opened by that library, avoiding symbol conflict issues even more effectively thanRTLD_DEEPBIND
, which is not recursive.Per #10670 (comment), to archieve full real isolation, real-world apache usecases still need to patch apache (libapr) to enable RTLD_DEEPBIND when dlopening libphp.so, as dso_load does not allow passing the
RTLD_DEEPBIND
flag, so it would not change much for usecases which currently use isolation, just a tweak to the patch that currently adds theRTLD_DEEPBIND
flag to libapr to usedlmopen(LM_ID_NEWLM, ...);
, instead.On platforms where GNU extensions aren't available (and dlmopen thus isn't available),
RTLD_DEEPBIND
is left enabled; if equivalent namespace isolation methods are available on other platforms, they can be added with later pull requests if needed.