From 76ef31116b4b102734fa1678cd6598206204f1e3 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 8ea1c1572..a45ba8294 100644 --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h @@ -260,6 +260,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 26c333ac0149f0088b8a12191c0591aca27484d2 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 ab4322bab..e18402a30 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 c7f97f1c8dcb71bbf0633c020248ad5474df9509 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Mon, 9 Sep 2019 07:10: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 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 44eee7a2e..2279f1e2e 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -699,7 +699,6 @@ component_test_rsa_no_crt () { 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 @@ -771,7 +770,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 @@ -894,10 +892,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 e1c62e664137adbdf7426728da376b85e4b95d60 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Mon, 9 Sep 2019 07:12:31 -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 e18402a30..2145be80e 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 f5baaaaf89dbe473883f684a53c1f896be28f306 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 2279f1e2e..01fb368bf 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -810,6 +810,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 () { msg "build: default config except MFL extension (ASan build)" # ~ 30s scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH From 167ae4385235c43e2f40270bdd8df61670905ec8 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 01fb368bf..ed79cf4f3 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -644,6 +644,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 8561115cb8b8c9ee6f14a128bba98f860e81b025 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 a45ba8294..65862148d 100644 --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h @@ -264,6 +264,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 19aa89ad47c257c6cd873055030e24f48903379c 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 2145be80e..3de8093fe 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 7aad93c9daf6e83235c13de9bdce334f73300aa1 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 ed79cf4f3..5573e007a 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -830,6 +830,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 9a461a1cd728c100ff4331d86cb7044f66fb983b 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 5573e007a..b77ddd218 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -826,10 +826,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 6addfdd19031b5480ff2e62c81f421c3e4a12261 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 b77ddd218..284aa5f65 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -849,7 +849,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 7eb7f8db8ba98f5b951390d8ef5a0ebaf2e94e93 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Mon, 9 Sep 2019 07:32:48 -0400 Subject: [PATCH 12/13] Remove unnecessary memory buffer alloc unsets This define is turned off by default --- tests/scripts/all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 284aa5f65..71c369b42 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -919,7 +919,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 From 9b1c2482094b94170d377d63eb713b3558e93798 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 71c369b42..870797fc9 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -831,6 +831,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