Repository navigation
compat/openssl: Remove the use of RTLD_DEEPBIND - #48972
Conversation
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]>
| 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")); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
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:
| // 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). |
Signed-off-by: Ted Poole <[email protected]>
Signed-off-by: Ted Poole <[email protected]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
…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]>
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]>
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]>
…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]>
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]>
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]>
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]>
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]>
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]>
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).