Skip to content

Commit 24600e8

Browse files
Disable memory_buffer_alloc in the full config
Enabling MBEDTLS_MEMORY_BUFFER_ALLOC_C module together with MBEDTLS_PLATFORM_MEMORY causes the library to use its own malloc replacement. This makes memory management analyzers such as ASan largely ineffective. We now test MBEDTLS_MEMORY_BUFFER_ALLOC_C separately. Disable it in the "full" config. This mirrors a change that was made in Mbed TLS on config.pl and had not been ported to Mbed Crypto yet. With this commit, config.py is aligned in Mbed Crypto and Mbed TLS.
1 parent 9afbfdc commit 24600e8

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

scripts/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def include_in_full(name):
169169
'MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED',
170170
'MBEDTLS_ECP_RESTARTABLE',
171171
'MBEDTLS_HAVE_SSE2',
172+
'MBEDTLS_MEMORY_BACKTRACE',
173+
'MBEDTLS_MEMORY_BUFFER_ALLOC_C',
174+
'MBEDTLS_MEMORY_DEBUG',
172175
'MBEDTLS_NO_64BIT_MULTIPLICATION',
173176
'MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES',
174177
'MBEDTLS_NO_PLATFORM_ENTROPY',
@@ -201,8 +204,6 @@ def keep_in_baremetal(name):
201204
'MBEDTLS_HAVEGE_C',
202205
'MBEDTLS_HAVE_TIME',
203206
'MBEDTLS_HAVE_TIME_DATE',
204-
'MBEDTLS_MEMORY_BACKTRACE',
205-
'MBEDTLS_MEMORY_BUFFER_ALLOC_C',
206207
'MBEDTLS_PLATFORM_FPRINTF_ALT',
207208
'MBEDTLS_PLATFORM_TIME_ALT',
208209
'MBEDTLS_PSA_CRYPTO_SE_C',

tests/scripts/all.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ component_test_everest () {
679679
component_test_psa_collect_statuses () {
680680
msg "build+test: psa_collect_statuses" # ~30s
681681
scripts/config.py full
682-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # slow and irrelevant
683682
record_status tests/scripts/psa_collect_statuses.py
684683
# Check that psa_crypto_init() succeeded at least once
685684
record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
@@ -689,7 +688,6 @@ component_test_psa_collect_statuses () {
689688
component_test_full_cmake_clang () {
690689
msg "build: cmake, full config, clang" # ~ 50s
691690
scripts/config.py full
692-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
693691
CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
694692
make
695693

@@ -703,7 +701,6 @@ component_test_full_cmake_clang () {
703701
component_test_full_make_gcc_o0 () {
704702
msg "build: make, full config, gcc -O0" # ~ 50s
705703
scripts/config.py full
706-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
707704
make CC=gcc CFLAGS='-O0'
708705

709706
msg "test: main suites (full config, gcc -O0)" # ~ 5s
@@ -758,7 +755,6 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
758755
# full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
759756
msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
760757
scripts/config.py full
761-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
762758
scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
763759
scripts/config.py set MBEDTLS_PSA_CRYPTO_C
764760
scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
@@ -776,7 +772,6 @@ component_test_check_params_functionality () {
776772
scripts/config.py full # includes CHECK_PARAMS
777773
# Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
778774
scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
779-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
780775
# Only build and run tests. Do not build sample programs, because
781776
# they don't have a mbedtls_param_failed() function.
782777
make CC=gcc CFLAGS='-Werror -O1' lib test
@@ -786,8 +781,6 @@ component_test_check_params_without_platform () {
786781
msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
787782
scripts/config.py full # includes CHECK_PARAMS
788783
# Keep MBEDTLS_PARAM_FAILED as assert.
789-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
790-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
791784
scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
792785
scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
793786
scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
@@ -802,7 +795,6 @@ component_test_check_params_without_platform () {
802795
component_test_check_params_silent () {
803796
msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
804797
scripts/config.py full # includes CHECK_PARAMS
805-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
806798
# Set MBEDTLS_PARAM_FAILED to nothing.
807799
sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
808800
make CC=gcc CFLAGS='-Werror -O1' all test
@@ -822,7 +814,6 @@ component_test_no_platform () {
822814
scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
823815
scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
824816
scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
825-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
826817
scripts/config.py unset MBEDTLS_FS_IO
827818
scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
828819
scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
@@ -872,7 +863,6 @@ component_test_platform_calloc_macro () {
872863
component_test_malloc_0_null () {
873864
msg "build: malloc(0) returns NULL (ASan+UBSan build)"
874865
scripts/config.py full
875-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
876866
make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
877867

878868
msg "test: malloc(0) returns NULL (ASan+UBSan build)"
@@ -948,7 +938,6 @@ component_test_se_default () {
948938
component_test_se_full () {
949939
msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
950940
scripts/config.py full
951-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
952941
scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
953942
make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
954943

@@ -1001,9 +990,6 @@ component_test_m32_o1 () {
1001990
# Build again with -O1, to compile in the i386 specific inline assembly
1002991
msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1003992
scripts/config.py full
1004-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE
1005-
scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1006-
scripts/config.py unset MBEDTLS_MEMORY_DEBUG
1007993
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
1008994

1009995
msg "test: i386, make, gcc -O1 (ASan build)"
@@ -1076,7 +1062,6 @@ component_test_have_int64 () {
10761062
component_test_no_udbl_division () {
10771063
msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
10781064
scripts/config.py full
1079-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
10801065
scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
10811066
make CFLAGS='-Werror -O1'
10821067

@@ -1087,7 +1072,6 @@ component_test_no_udbl_division () {
10871072
component_test_no_64bit_multiplication () {
10881073
msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
10891074
scripts/config.py full
1090-
scripts/config.py unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
10911075
scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
10921076
make CFLAGS='-Werror -O1'
10931077

0 commit comments

Comments
 (0)