-
Notifications
You must be signed in to change notification settings - Fork 724
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
v1.5.10 memory leak regression when used with libcurl #5044
Comments
Hello Sam, Thanks for providing all those context. I have pull downed your |
So far I don't know why the leak started to occur. However it seems that the try-compile feature S2N_LIBCRYPTO_SUPPORTS_ENGINE evaluates to true in the repro. Which means that our custom randomness code is trying to be instantiated/cleaned up. Maybe it was turned off for this platform previously. I'm going to hazard a guess that the libcrypto being used here is Openssl 1.0.2. |
Leak goes away if you re-order the init/cleanup code:
I suspect curl is wiping our randomness engine, maybe replacing it with their own. Therefore our engine pointer memory gets leaked since its being wiped. |
yeah I noticed that too, and I would re-order if I could, but the order of initialization happens at several layers of indirection for us. we initialize the CRT, which initializes s2n, then initialize the http client. we cannot move the crt initialization after the http client as the http client is dependent on CRT stuff. I know that doesnt have to do with s2n, but re-ordering the call order isn't as trivial for us as it would be in this example.
looking at the libcrypto it finds in the image might not be
|
Hmmm wow that is an old version of Openssl. Okay here's my guess about why this started to cause issues. Before the PR, we were gating our custom randomness engine with Anyways it seems like our code is working as intended, replacing the randomness engine when s2n-tls is built with older libcryptos. There's obviously some sort of incompatibility with our engine code and how curl works. Not sure what we can do about that yet. |
It is! but its also what comes with amazon linux 2 by default, so it is something that has to be in compatibility matrix. |
ok so updating
to
Will result in the memory leak going away. however this seems like a breaking change to require customers to use a newer version of openssl-devel on AL2. If we do want to say "thats not supported" that will impact a non-zero amount of our customers using the RPM on AL2, so we shouldn't do this lightly. |
ok was able to reproduce with 1.0.2, attaching the dockerfile here # Using offical Amazon Linux 2 image from public ECR
FROM public.ecr.aws/amazonlinux/amazonlinux:2
RUN yum groupinstall "Development Tools" -y
RUN yum install -y curl-devel ninja-build cmake3 libasan wget
# lets get openssl 1.0.2
RUN wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_0_2/openssl-1.0.2.tar.gz &&\
tar -xvzf openssl-1.0.2.tar.gz &&\
cd openssl-1.0.2 &&\
./config &&\
make &&\
make install
# v1.5.9 works
#RUN git clone -b v1.5.9 https://github.com/aws/s2n-tls.git &&\
# cd s2n-tls &&\
# mkdir build &&\
# cd build &&\
# cmake3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="/usr/local/ssl/" -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_INSTALL_PREFIX="/s2n-install" .. && \
# cmake3 --build . &&\
# cmake3 --install .
# v1.5.10/main has a memory leak
RUN git clone -b v1.5.10 https://github.com/aws/s2n-tls.git &&\
cd s2n-tls &&\
mkdir build &&\
cd build &&\
cmake3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="/usr/local/ssl/" -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_INSTALL_PREFIX="/s2n-install" .. && \
cmake3 --build . &&\
cmake3 --install .
# # Create test application
RUN mkdir test
# # Create CMakeLists.txt
RUN touch /test/CMakeLists.txt &&\
echo "cmake_minimum_required(VERSION 3.13)" >> /test/CMakeLists.txt &&\
echo "project(test_s2n_init)" >> /test/CMakeLists.txt &&\
echo "set(CMAKE_CXX_STANDARD 20)" >> /test/CMakeLists.txt &&\
echo "find_package(CURL REQUIRED)" >> /test/CMakeLists.txt &&\
echo "find_package(s2n REQUIRED)" >> /test/CMakeLists.txt &&\
echo "add_executable(\${PROJECT_NAME} "main.cpp")" >> /test/CMakeLists.txt &&\
echo "target_include_directories(\${PROJECT_NAME} PRIVATE \${CURL_INCLUDE_DIRS})" >> /test/CMakeLists.txt &&\
echo "target_link_libraries(\${PROJECT_NAME} PRIVATE \${CURL_LIBRARIES} AWS::s2n)" >> /test/CMakeLists.txt
# # Create simple test file
RUN touch /test/main.cpp &&\
echo "#include <curl/curl.h>" >> /test/main.cpp &&\
echo "#include <s2n.h>" >> /test/main.cpp &&\
echo "" >> /test/main.cpp &&\
echo "auto main() -> int {" >> /test/main.cpp &&\
echo " s2n_init();" >> /test/main.cpp &&\
echo " curl_global_init(CURL_GLOBAL_ALL);" >> /test/main.cpp &&\
echo " curl_global_cleanup();" >> /test/main.cpp &&\
echo " s2n_cleanup();" >> /test/main.cpp &&\
echo " s2n_cleanup_final();" >> /test/main.cpp &&\
echo " return 0;" >> /test/main.cpp &&\
echo "}" >> /test/main.cpp
# # Build test
RUN cd test &&\
mkdir build &&\
cd build &&\
cmake3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="/s2n-install;/usr/local/ssl/" .. &&\
cmake3 --build .
We should probably chase down why such a old RPM is in AL2, but looks like even if they were to update to 1.0.2 the issue would be present. |
Hello @sbiscigl we have merged changes to address this issue. Please confirm the fix, and feel free to reopen if it persists. Thank you! |
I dont have permissions to re-open, can you please re-open this? the docker file i provided above still replicates the issue on mainline FROM public.ecr.aws/amazonlinux/amazonlinux:2
RUN yum groupinstall "Development Tools" -y
RUN yum install -y curl-devel ninja-build cmake3 libasan wget
# lets get openssl 1.0.2
RUN wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_0_2/openssl-1.0.2.tar.gz &&\
tar -xvzf openssl-1.0.2.tar.gz &&\
cd openssl-1.0.2 &&\
./config &&\
make &&\
make install
# main has a memory leak
RUN git clone https://github.com/aws/s2n-tls.git &&\
cd s2n-tls &&\
mkdir build &&\
cd build &&\
cmake3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="/usr/local/ssl/" -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_INSTALL_PREFIX="/s2n-install" .. && \
cmake3 --build . &&\
cmake3 --install .
# # Create test application
RUN mkdir test
# # Create CMakeLists.txt
RUN touch /test/CMakeLists.txt &&\
echo "cmake_minimum_required(VERSION 3.13)" >> /test/CMakeLists.txt &&\
echo "project(test_s2n_init)" >> /test/CMakeLists.txt &&\
echo "set(CMAKE_CXX_STANDARD 20)" >> /test/CMakeLists.txt &&\
echo "find_package(CURL REQUIRED)" >> /test/CMakeLists.txt &&\
echo "find_package(s2n REQUIRED)" >> /test/CMakeLists.txt &&\
echo "add_executable(\${PROJECT_NAME} "main.cpp")" >> /test/CMakeLists.txt &&\
echo "target_include_directories(\${PROJECT_NAME} PRIVATE \${CURL_INCLUDE_DIRS})" >> /test/CMakeLists.txt &&\
echo "target_link_libraries(\${PROJECT_NAME} PRIVATE \${CURL_LIBRARIES} AWS::s2n)" >> /test/CMakeLists.txt
# # Create simple test file
RUN touch /test/main.cpp &&\
echo "#include <curl/curl.h>" >> /test/main.cpp &&\
echo "#include <s2n.h>" >> /test/main.cpp &&\
echo "" >> /test/main.cpp &&\
echo "auto main() -> int {" >> /test/main.cpp &&\
echo " s2n_init();" >> /test/main.cpp &&\
echo " curl_global_init(CURL_GLOBAL_ALL);" >> /test/main.cpp &&\
echo " curl_global_cleanup();" >> /test/main.cpp &&\
echo " s2n_cleanup();" >> /test/main.cpp &&\
echo " s2n_cleanup_final();" >> /test/main.cpp &&\
echo " return 0;" >> /test/main.cpp &&\
echo "}" >> /test/main.cpp
# # Build test
RUN cd test &&\
mkdir build &&\
cd build &&\
cmake3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="/s2n-install;/usr/local/ssl/" .. &&\
cmake3 --build . and as before you can replicate with
can we use fixing this example as a baseline of what needs to be fixed. |
We have discussed this offline. This fix works for openssl1-0-2-fips. Please let us know if you have other concerns. |
Hey from the aws cpp sdk, and we're trying to update our submodule dependencies and we noticed a regression/memory leak when using s2n in conjuction with libcurl and its blocking us from updating our dependencies.
Created a small reproduction
Dockerfile that can reproduce it:
can build and run this to replicate with
docker build -t test-image . docker run --name test-image test-image /test/build/test_s2n_init
but you should see the stack trace
which is indicative of this change being the cultprit of it.
would guess this is a issue with static state being shared between s2n and libcurl in some way.
The text was updated successfully, but these errors were encountered: