From e29e7eb36c173deb8d05367de9efd9b5ae697b2f Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 26 Feb 2019 13:50:21 +0000 Subject: [PATCH 01/13] Check dependencies of MBEDTLS_MEMORY_BACKTRACE in check_config.h --- include/mbedtls/check_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/mbedtls/check_config.h b/include/mbedtls/check_config.h index 6eabcc874..12b3349d4 100644 --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h @@ -281,6 +281,10 @@ #error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_MEMORY_BACKTRACE) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) +#error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequesites" +#endif + #if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM) #error "MBEDTLS_PADLOCK_C defined, but not all prerequisites" #endif From 307dfcd439feed6c051263a2721e0b9eadf8ba88 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 26 Feb 2019 13:51:00 +0000 Subject: [PATCH 02/13] Disable memory buffer allocator in full config This commit modifies `config.pl` to not set MBEDTLS_MEMORY_BUFFER_ALLOC with the `full` option. --- scripts/config.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/config.pl b/scripts/config.pl index 42ec6f81b..c81cb9201 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -26,6 +26,8 @@ # MBEDTLS_ECP_DP_M221_ENABLED # MBEDTLS_ECP_DP_M383_ENABLED # MBEDTLS_ECP_DP_M511_ENABLED +# MBEDTLS_MEMORY_BACKTRACE +# MBEDTLS_MEMORY_BUFFER_ALLOC_C # MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES # MBEDTLS_NO_PLATFORM_ENTROPY # MBEDTLS_REMOVE_ARC4_CIPHERSUITES @@ -86,6 +88,8 @@ MBEDTLS_PLATFORM_NO_STD_FUNCTIONS MBEDTLS_ECP_DP_M221_ENABLED MBEDTLS_ECP_DP_M383_ENABLED MBEDTLS_ECP_DP_M511_ENABLED +MBEDTLS_MEMORY_BACKTRACE +MBEDTLS_MEMORY_BUFFER_ALLOC_C MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES MBEDTLS_NO_PLATFORM_ENTROPY MBEDTLS_RSA_NO_CRT From a9c2a3b244c399a1743c6549f690e6080564b562 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Mon, 9 Sep 2019 05:22:39 -0400 Subject: [PATCH 03/13] Adapt all.sh to removal of buffer allocator from full config Previously, numerous all.sh tests manually disabled the buffer allocator or memory backtracting after setting a full config as the starting point. With the removal of MBEDTLS_MEMORY_BACKTRACE and MBEDTLS_MEMORY_BUFFER_ALLOC_C from full configs, this is no longer necessary. --- tests/scripts/all.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 3678cc4b1..1f9211b38 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -744,7 +744,6 @@ component_test_small_mbedtls_ssl_dtls_max_buffering () { component_test_full_cmake_clang () { msg "build: cmake, full config, clang" # ~ 50s scripts/config.pl full - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On . make @@ -826,8 +825,6 @@ component_test_check_params_without_platform () { msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C" scripts/config.pl full # includes CHECK_PARAMS # Keep MBEDTLS_PARAM_FAILED as assert. - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests - scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT @@ -842,7 +839,6 @@ component_test_check_params_without_platform () { component_test_check_params_silent () { msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()" scripts/config.pl full # includes CHECK_PARAMS - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests # Set MBEDTLS_PARAM_FAILED to nothing. sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H" make CC=gcc CFLAGS='-Werror -O1' all test @@ -863,7 +859,6 @@ component_test_no_platform () { scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED - scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl unset MBEDTLS_FS_IO # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19, # to re-enable platform integration features otherwise disabled in C99 builds @@ -1027,10 +1022,7 @@ component_test_m32_o1 () { # Build again with -O1, to compile in the i386 specific inline assembly msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s scripts/config.pl full - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE - scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C - scripts/config.pl unset MBEDTLS_MEMORY_DEBUG - make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32' + make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address' msg "test: i386, make, gcc -O1 (ASan build)" make test From 8762101c013ebe2c8aad50137af3744e1f616e9c Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Mon, 9 Sep 2019 05:25:05 -0400 Subject: [PATCH 04/13] Update documentation of exceptions for `config.pl full` --- scripts/config.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/config.pl b/scripts/config.pl index c81cb9201..0aa5deffd 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -39,6 +39,8 @@ # - this could be enabled if the respective tests were adapted # MBEDTLS_ZLIB_SUPPORT # MBEDTLS_PKCS11_C +# MBEDTLS_NO_UDBL_DIVISION +# MBEDTLS_NO_64BIT_MULTIPLICATION # and any symbol beginning _ALT # From 74b5e34d1baadae6708e52b7c2d8c4eb1a9e6636 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 26 Feb 2019 14:34:13 +0000 Subject: [PATCH 05/13] Add all.sh run with MBEDTLS_MEMORY_BUFFER_ALLOC_C enabled With the removal of MBEDTLS_MEMORY_BUFFER_ALLOC_C from the full config, there are no tests for it remaining in all.sh. This commit adds a build as well as runs of `make test` and `ssl-opt.sh` with MBEDTLS_MEMORY_BUFFER_ALLOC_C enabled to all.sh. --- tests/scripts/all.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 1f9211b38..e2f51d63b 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -899,6 +899,20 @@ component_build_no_sockets () { make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib } +component_test_memory_buffer_allocator () { + msg "build: default config with memory buffer allocator enabled" + scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C + scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE + CC=gcc cmake . + make + + msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C" + make test + + msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C" + if_build_succeeded tests/ssl-opt.sh +} + component_test_no_max_fragment_length () { # Run max fragment length tests with MFL disabled msg "build: default config except MFL extension (ASan build)" # ~ 30s From f8799e8b84ee44fc13fb0567690cf5da7a9417e2 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Tue, 26 Feb 2019 14:27:09 +0000 Subject: [PATCH 06/13] Add all.sh run with full config and ASan enabled --- tests/scripts/all.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index e2f51d63b..8e8a5cd0e 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -633,6 +633,22 @@ component_test_default_cmake_gcc_asan () { if_build_succeeded tests/compat.sh } +component_test_full_cmake_gcc_asan () { + msg "build: full config, cmake, gcc, ASan" + scripts/config.pl full + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make + + msg "test: main suites (inc. selftests) (full config, ASan build)" + make test + + msg "test: ssl-opt.sh (full config, ASan build)" + if_build_succeeded tests/ssl-opt.sh + + msg "test: compat.sh (full config, ASan build)" + if_build_succeeded tests/compat.sh +} + component_test_ref_configs () { msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . From 9ae9da93d83dcfce0b355ddc526038c1ae638c46 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Mon, 3 Jun 2019 16:31:32 +0100 Subject: [PATCH 07/13] Add cfg dep MBEDTLS_MEMORY_DEBUG->MBEDTLS_MEMORY_BUFFER_ALLOC_C --- include/mbedtls/check_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/mbedtls/check_config.h b/include/mbedtls/check_config.h index 12b3349d4..d076c2352 100644 --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h @@ -285,6 +285,10 @@ #error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequesites" #endif +#if defined(MBEDTLS_MEMORY_DEBUG) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) +#error "MBEDTLS_MEMORY_DEBUG defined, but not all prerequesites" +#endif + #if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM) #error "MBEDTLS_PADLOCK_C defined, but not all prerequisites" #endif From dfc974412c556af6bb7673d473a163c2dadc0b8a Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Mon, 3 Jun 2019 16:33:18 +0100 Subject: [PATCH 08/13] Don't set MBEDTLS_MEMORY_DEBUG through `scripts/config.pl full` --- scripts/config.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/config.pl b/scripts/config.pl index 0aa5deffd..7afc89875 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -90,6 +90,7 @@ MBEDTLS_PLATFORM_NO_STD_FUNCTIONS MBEDTLS_ECP_DP_M221_ENABLED MBEDTLS_ECP_DP_M383_ENABLED MBEDTLS_ECP_DP_M511_ENABLED +MBEDTLS_MEMORY_DEBUG MBEDTLS_MEMORY_BACKTRACE MBEDTLS_MEMORY_BUFFER_ALLOC_C MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES From d130b98c68c4e7c6f68e75cbe9aa9b965cac4544 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Mon, 3 Jun 2019 16:35:02 +0100 Subject: [PATCH 09/13] Add missing dependency in memory buffer alloc set in all.sh --- tests/scripts/all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 8e8a5cd0e..3fabd8fc5 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -919,6 +919,7 @@ component_test_memory_buffer_allocator () { msg "build: default config with memory buffer allocator enabled" scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE + scripts/config.pl set MBEDTLS_PLATFORM_MEMORY CC=gcc cmake . make From 1d0708215b6505c96884b311d3346effee0bdee7 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Thu, 5 Sep 2019 09:27:47 -0400 Subject: [PATCH 10/13] all.sh: restructure memory allocator tests Run basic tests and ssl-opt with memory backtrace disabled, then run basic tests only with it enabled. --- tests/scripts/all.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 3fabd8fc5..77f5188c5 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -915,10 +915,21 @@ component_build_no_sockets () { make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib } -component_test_memory_buffer_allocator () { - msg "build: default config with memory buffer allocator enabled" +component_test_memory_buffer_allocator_backtrace () { + msg "build: default config with memory buffer allocator and backtrace enabled" scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C + scripts/config.pl set MBEDTLS_PLATFORM_MEMORY scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE + CC=gcc cmake . + make + + msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE" + make test +} + +component_test_memory_buffer_allocator () { + msg "build: default config with memory buffer allocator" + scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl set MBEDTLS_PLATFORM_MEMORY CC=gcc cmake . make From 1f5a596fe246f96fb5df78502e99f20cf775786c Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Thu, 5 Sep 2019 10:09:37 -0400 Subject: [PATCH 11/13] Disable DTLS proxy tests for MEMORY_BUFFER_ALLOC test --- tests/scripts/all.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 77f5188c5..2ff0ebf82 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -938,7 +938,8 @@ component_test_memory_buffer_allocator () { make test msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C" - if_build_succeeded tests/ssl-opt.sh + # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out. + if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy' } component_test_no_max_fragment_length () { From c73f857217f189f12493da304d3dfc229790214b Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Tue, 10 Sep 2019 03:07:29 -0400 Subject: [PATCH 12/13] Remove unnecessary memory buffer alloc and memory backtrace unsets Also unify the sanitization LDFLAGS with development --- tests/scripts/all.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 2ff0ebf82..39631cdae 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -831,7 +831,6 @@ component_test_check_params_functionality () { scripts/config.pl full # includes CHECK_PARAMS # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed(). scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT - scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # Only build and run tests. Do not build sample programs, because # they don't have a mbedtls_param_failed() function. make CC=gcc CFLAGS='-Werror -O1' lib test @@ -1049,7 +1048,7 @@ component_test_m32_o0 () { # Build once with -O0, to compile out the i386 specific inline assembly msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s scripts/config.pl full - make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32' + make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address' msg "test: i386, make, gcc -O0 (ASan build)" make test @@ -1127,7 +1126,6 @@ component_test_have_int64 () { component_test_no_udbl_division () { msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s scripts/config.pl full - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION make CFLAGS='-Werror -O1' @@ -1138,7 +1136,6 @@ component_test_no_udbl_division () { component_test_no_64bit_multiplication () { msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s scripts/config.pl full - scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION make CFLAGS='-Werror -O1' From 60ebd98a5092df9d222bba3a33fc6e4b354a967a Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Tue, 10 Sep 2019 02:58:34 -0400 Subject: [PATCH 13/13] Enable MBEDTLS_MEMORY_DEBUG in memory buffer alloc test in all.sh --- tests/scripts/all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 39631cdae..3c4681afb 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -919,6 +919,7 @@ component_test_memory_buffer_allocator_backtrace () { scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl set MBEDTLS_PLATFORM_MEMORY scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE + scripts/config.pl set MBEDTLS_MEMORY_DEBUG CC=gcc cmake . make