Skip to content

compat/openssl: Remove the use of RTLD_DEEPBIND - #48972

Merged
jwendell merged 3 commits into
envoyproxy:mainfrom
tedjpoole:remove-rtld_deepbind
Nov 4, 2026
Merged

jwendell merged 3 commits into
envoyproxy:mainfrom
tedjpoole:remove-rtld_deepbind

Conversation

@tedjpoole

Copy link
Copy Markdown
Contributor

This commit removes the use of the RTLD_DEEPBIND option when the compat layer loads the OpenSSL shared libraries. As a replacement, the compat layer is now built with the -fvisibility=hidden option instead. This has the same effect of preventing OpenSSL code linking against the compat layer symbols instead of it's own. This change has been made, in preparation for adding an ASAN build of the compat layer, because the dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND option.

Also added a test to confirm that compat layer symbols are not dynamically visible (preventing the subtle misresolution bugs that RTLD_DEEPBIND was originally introduced to solve).

This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN buid of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a new test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

Signed-off-by: Ted Poole <[email protected]>
Comment thread compat/openssl/test/test_misc.cc Outdated
Comment on lines +20 to +23
TEST(MiscTest, OpenSSLSymbolsNotVisible) {
EXPECT_EQ(nullptr, dlsym(RTLD_DEFAULT, "SSL_new"));
EXPECT_EQ(nullptr, dlsym(RTLD_DEFAULT, "SSL_read"));
EXPECT_EQ(nullptr, dlsym(RTLD_DEFAULT, "SSL_write"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test can fail as written. bssl-compat is linked statically into the test executable, and the test isn't linked with -rdynamic/--export-dynamic. So SSL_new/SSL_read/SSL_write never make it into the executable's dynamic symbol table, and dlsym(RTLD_DEFAULT, ...) returns nullptr even without -fvisibility=hidden (e.g. on main).

To make it a real regression test, could you add linkopts = ["-rdynamic"] to the utests-bssl-compat target in compat/openssl/test/BUILD? Then dropping -fvisibility=hidden from compat/openssl/BUILD should make this test fail. Worth checking that it does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, plus I think adding more flags to the utests-bssl-compat compilation, just to make the test valid, is not really testing what really needs testing.

Therefore, I've removed this utest from utests-bssl-compat, and in it's place I've added a runtime check into the compat layer's startup code (in ossl_dopen()) i.e. the check is now done at runtime in every executable, whether it's a test or the real envoy.

Comment on lines 133 to 137
// Tell OpenSSL to use the tcmalloc malloc/realloc/free functions from the
// main executable. Without this, RTLD_DEEPBIND causes OpenSSL's allocations
// to resolve to glibc's malloc/realloc/free instead, resulting in OpenSSL
// using a completely separate heap. This defeats tcmalloc's performance
// benefits on the TLS hot path, and also makes all OpenSSL allocations
// main executable. OpenSSL uses its own allocator wrappers internally, so
// without this, OpenSSL allocations bypass tcmalloc, defeating its
// performance benefits on the TLS hot path and making OpenSSL allocations
// invisible to tcmalloc's heap dumps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without RTLD_DEEPBIND, libcrypto's default CRYPTO_malloc/free should already resolve malloc/free through global scope to the executable's tcmalloc. So the "bypass tcmalloc" reason no longer really holds, and this call is now a safeguard. Maybe reword:

Suggested change
// Tell OpenSSL to use the tcmalloc malloc/realloc/free functions from the
// main executable. Without this, RTLD_DEEPBIND causes OpenSSL's allocations
// to resolve to glibc's malloc/realloc/free instead, resulting in OpenSSL
// using a completely separate heap. This defeats tcmalloc's performance
// benefits on the TLS hot path, and also makes all OpenSSL allocations
// main executable. OpenSSL uses its own allocator wrappers internally, so
// without this, OpenSSL allocations bypass tcmalloc, defeating its
// performance benefits on the TLS hot path and making OpenSSL allocations
// invisible to tcmalloc's heap dumps.
// Tell OpenSSL to use the tcmalloc malloc/realloc/free functions from the
// main executable. Without RTLD_DEEPBIND, OpenSSL's default allocators
// should already resolve to the executable's malloc via global scope, but
// setting them explicitly guarantees OpenSSL uses tcmalloc regardless of
// how symbol resolution behaves (e.g. under sanitizer interceptors).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jwendell
jwendell merged commit 8d2521b into envoyproxy:main Nov 4, 2026
27 checks passed
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 11, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 11, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 11, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
Signed-off-by: Ryan Northey <[email protected]>
jwendell pushed a commit that referenced this pull request Nov 11, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 13, 2026
Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 13, 2026
Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 13, 2026
Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 13, 2026
Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
…49173)

Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

(cherry picked from commit 02bc21e)

Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit to phlax/envoy that referenced this pull request Nov 17, 2026
…49173)

Backport of envoyproxy#49173 and envoyproxy#49150, and the `openssl.asan` target of envoyproxy#49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in envoyproxy#48972.

(cherry picked from commit 02bc21e)

Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
phlax added a commit that referenced this pull request Nov 17, 2026
Backport of #49173 and #49150, and the `openssl.asan` target of #49007,
so that this branch runs the same OpenSSL jobs as main and
release/v1.40: `openssl.build` and `openssl.test_affected` for pull
requests, and `openssl.build` and `openssl.test` for everything else.

CI's workflows run from main, and set the OpenSSL jobs from the
`check-build-openssl-*` run flags in this branch's `.github/config.yml`,
so only the config and `ci/do_ci.sh` are ported. As before on this
branch, the OpenSSL builds set up the clang toolchain and leave the
quiche tests out, and `WORKSPACE` is treated as a build-wide change.

The post-merge ASAN job is not turned on: the compat layer on this
branch still loads OpenSSL with `RTLD_DEEPBIND`, which ASAN does not
support. Main stopped using it in #48972.

(cherry picked from commit 02bc21e)

Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
This commit removes the use of the RTLD_DEEPBIND option when the compat
layer loads the OpenSSL shared libraries. As a replacement, the compat
layer is now built with the -fvisibility=hidden option instead. This has
the same effect of preventing OpenSSL code linking against the compat
layer symbols instead of it's own. This change has been made, in
preparation for adding an ASAN build of the compat layer, because the
dlopen() wrapper that ASAN injects, does not work with the RTLD_DEEPBIND
option.

Also added a test to confirm that compat layer symbols are not
dynamically visible (preventing the subtle misresolution bugs that
RTLD_DEEPBIND was originally introduced to solve).

---------

Signed-off-by: Ted Poole <[email protected]>
(cherry picked from commit 8d2521b)
Signed-off-by: Ryan Northey <[email protected]>
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