Minos Galanakis | 7771119 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-sanitizers.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
| 6 | # This file contains test components that are executed by all.sh |
| 7 | |
| 8 | ################################################################ |
| 9 | #### Sanitizer Testing |
| 10 | ################################################################ |
Minos Galanakis | 4a2a351 | 2024-08-01 17:28:37 +0100 | [diff] [blame] | 11 | |
| 12 | skip_suites_without_constant_flow () { |
| 13 | # Skip the test suites that don't have any constant-flow annotations. |
| 14 | # This will need to be adjusted if we ever start declaring things as |
| 15 | # secret from macros or functions inside tests/include or tests/src. |
| 16 | SKIP_TEST_SUITES=$( |
| 17 | git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' | |
| 18 | sed 's/test_suite_//; s/\.function$//' | |
| 19 | tr '\n' ,) |
| 20 | export SKIP_TEST_SUITES |
| 21 | } |
| 22 | |
| 23 | skip_all_except_given_suite () { |
| 24 | # Skip all but the given test suite |
| 25 | SKIP_TEST_SUITES=$( |
| 26 | ls -1 tests/suites/test_suite_*.function | |
| 27 | grep -v $1.function | |
| 28 | sed 's/tests.suites.test_suite_//; s/\.function$//' | |
| 29 | tr '\n' ,) |
| 30 | export SKIP_TEST_SUITES |
| 31 | } |
| 32 | |
| 33 | component_test_memsan_constant_flow () { |
| 34 | # This tests both (1) accesses to undefined memory, and (2) branches or |
| 35 | # memory access depending on secret values. To distinguish between those: |
| 36 | # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist? |
| 37 | # - or alternatively, change the build type to MemSanDbg, which enables |
| 38 | # origin tracking and nicer stack traces (which are useful for debugging |
| 39 | # anyway), and check if the origin was TEST_CF_SECRET() or something else. |
| 40 | msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing" |
| 41 | scripts/config.py full |
| 42 | scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN |
| 43 | scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO |
| 44 | scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm |
Elena Uziunaite | cd2ae32 | 2024-07-01 16:55:19 +0100 | [diff] [blame] | 45 | scripts/config.py unset MBEDTLS_HAVE_ASM |
Minos Galanakis | 4a2a351 | 2024-08-01 17:28:37 +0100 | [diff] [blame] | 46 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . |
| 47 | make |
| 48 | |
| 49 | msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)" |
| 50 | make test |
| 51 | } |
| 52 | |
| 53 | component_test_memsan_constant_flow_psa () { |
| 54 | # This tests both (1) accesses to undefined memory, and (2) branches or |
| 55 | # memory access depending on secret values. To distinguish between those: |
| 56 | # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist? |
| 57 | # - or alternatively, change the build type to MemSanDbg, which enables |
| 58 | # origin tracking and nicer stack traces (which are useful for debugging |
| 59 | # anyway), and check if the origin was TEST_CF_SECRET() or something else. |
| 60 | msg "build: cmake MSan (clang), full config with constant flow testing" |
| 61 | scripts/config.py full |
| 62 | scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN |
| 63 | scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm |
Elena Uziunaite | cd2ae32 | 2024-07-01 16:55:19 +0100 | [diff] [blame] | 64 | scripts/config.py unset MBEDTLS_HAVE_ASM |
Minos Galanakis | 4a2a351 | 2024-08-01 17:28:37 +0100 | [diff] [blame] | 65 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . |
| 66 | make |
| 67 | |
| 68 | msg "test: main suites (Msan + constant flow)" |
| 69 | make test |
| 70 | } |
| 71 | |
| 72 | component_release_test_valgrind_constant_flow () { |
| 73 | # This tests both (1) everything that valgrind's memcheck usually checks |
| 74 | # (heap buffer overflows, use of uninitialized memory, use-after-free, |
| 75 | # etc.) and (2) branches or memory access depending on secret values, |
| 76 | # which will be reported as uninitialized memory. To distinguish between |
| 77 | # secret and actually uninitialized: |
| 78 | # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist? |
| 79 | # - or alternatively, build with debug info and manually run the offending |
| 80 | # test suite with valgrind --track-origins=yes, then check if the origin |
| 81 | # was TEST_CF_SECRET() or something else. |
| 82 | msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing" |
| 83 | scripts/config.py full |
| 84 | scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND |
| 85 | scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO |
| 86 | skip_suites_without_constant_flow |
| 87 | cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 88 | make |
| 89 | |
| 90 | # this only shows a summary of the results (how many of each type) |
| 91 | # details are left in Testing/<date>/DynamicAnalysis.xml |
| 92 | msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)" |
| 93 | make memcheck |
| 94 | |
| 95 | # Test asm path in constant time module - by default, it will test the plain C |
| 96 | # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s) |
| 97 | msg "test: valgrind asm constant_time" |
| 98 | scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM |
| 99 | skip_all_except_given_suite test_suite_constant_time |
| 100 | cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 101 | make clean |
| 102 | make |
| 103 | make memcheck |
| 104 | } |
| 105 | |
| 106 | component_release_test_valgrind_constant_flow_psa () { |
| 107 | # This tests both (1) everything that valgrind's memcheck usually checks |
| 108 | # (heap buffer overflows, use of uninitialized memory, use-after-free, |
| 109 | # etc.) and (2) branches or memory access depending on secret values, |
| 110 | # which will be reported as uninitialized memory. To distinguish between |
| 111 | # secret and actually uninitialized: |
| 112 | # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist? |
| 113 | # - or alternatively, build with debug info and manually run the offending |
| 114 | # test suite with valgrind --track-origins=yes, then check if the origin |
| 115 | # was TEST_CF_SECRET() or something else. |
| 116 | msg "build: cmake release GCC, full config with constant flow testing" |
| 117 | scripts/config.py full |
| 118 | scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND |
| 119 | skip_suites_without_constant_flow |
| 120 | cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 121 | make |
| 122 | |
| 123 | # this only shows a summary of the results (how many of each type) |
| 124 | # details are left in Testing/<date>/DynamicAnalysis.xml |
| 125 | msg "test: some suites (valgrind + constant flow)" |
| 126 | make memcheck |
| 127 | } |
| 128 | |
| 129 | component_test_tsan () { |
| 130 | msg "build: TSan (clang)" |
| 131 | scripts/config.py full |
| 132 | scripts/config.py set MBEDTLS_THREADING_C |
| 133 | scripts/config.py set MBEDTLS_THREADING_PTHREAD |
| 134 | # Self-tests do not currently use multiple threads. |
| 135 | scripts/config.py unset MBEDTLS_SELF_TEST |
| 136 | |
| 137 | # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe. |
| 138 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C |
| 139 | |
| 140 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan . |
| 141 | make |
| 142 | |
| 143 | msg "test: main suites (TSan)" |
| 144 | make test |
| 145 | } |
| 146 | |
| 147 | component_test_memsan () { |
| 148 | msg "build: MSan (clang)" # ~ 1 min 20s |
| 149 | scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm |
Elena Uziunaite | 9af882d | 2024-07-02 10:52:13 +0100 | [diff] [blame^] | 150 | scripts/config.py unset MBEDTLS_HAVE_ASM |
Minos Galanakis | 4a2a351 | 2024-08-01 17:28:37 +0100 | [diff] [blame] | 151 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . |
| 152 | make |
| 153 | |
| 154 | msg "test: main suites (MSan)" # ~ 10s |
| 155 | make test |
| 156 | |
| 157 | msg "test: metatests (MSan)" |
| 158 | tests/scripts/run-metatests.sh any msan |
| 159 | |
| 160 | msg "program demos (MSan)" # ~20s |
| 161 | tests/scripts/run_demos.py |
| 162 | |
| 163 | msg "test: ssl-opt.sh (MSan)" # ~ 1 min |
| 164 | tests/ssl-opt.sh |
| 165 | |
| 166 | # Optional part(s) |
| 167 | |
| 168 | if [ "$MEMORY" -gt 0 ]; then |
| 169 | msg "test: compat.sh (MSan)" # ~ 6 min 20s |
| 170 | tests/compat.sh |
| 171 | fi |
| 172 | } |
| 173 | |
| 174 | component_release_test_valgrind () { |
| 175 | msg "build: Release (clang)" |
| 176 | # default config, in particular without MBEDTLS_USE_PSA_CRYPTO |
| 177 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 178 | make |
| 179 | |
| 180 | msg "test: main suites, Valgrind (default config)" |
| 181 | make memcheck |
| 182 | |
| 183 | # Optional parts (slow; currently broken on OS X because programs don't |
| 184 | # seem to receive signals under valgrind on OS X). |
| 185 | # These optional parts don't run on the CI. |
| 186 | if [ "$MEMORY" -gt 0 ]; then |
| 187 | msg "test: ssl-opt.sh --memcheck (default config)" |
| 188 | tests/ssl-opt.sh --memcheck |
| 189 | fi |
| 190 | |
| 191 | if [ "$MEMORY" -gt 1 ]; then |
| 192 | msg "test: compat.sh --memcheck (default config)" |
| 193 | tests/compat.sh --memcheck |
| 194 | fi |
| 195 | |
| 196 | if [ "$MEMORY" -gt 0 ]; then |
| 197 | msg "test: context-info.sh --memcheck (default config)" |
| 198 | tests/context-info.sh --memcheck |
| 199 | fi |
| 200 | } |
| 201 | |
| 202 | component_release_test_valgrind_psa () { |
| 203 | msg "build: Release, full (clang)" |
| 204 | # full config, in particular with MBEDTLS_USE_PSA_CRYPTO |
| 205 | scripts/config.py full |
| 206 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 207 | make |
| 208 | |
| 209 | msg "test: main suites, Valgrind (full config)" |
| 210 | make memcheck |
| 211 | } |