blob: c327b79f317ff3762a8b98ddfd2f51e1923f3911 [file] [log] [blame]
Minos Galanakis77711192024-07-25 14:24:37 +01001# 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 Galanakis4a2a3512024-08-01 17:28:37 +010011
12skip_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
23skip_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
33component_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 Uziunaitecd2ae322024-07-01 16:55:19 +010045 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +010046 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
53component_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 Uziunaitecd2ae322024-07-01 16:55:19 +010064 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +010065 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
72component_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
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100106component_release_test_valgrind_constant_flow_no_asm () {
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 minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM with constant flow testing"
117 scripts/config.py full
118 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
119 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
120 scripts/config.py unset MBEDTLS_AESNI_C
121 scripts/config.py unset MBEDTLS_HAVE_ASM
122 skip_suites_without_constant_flow
123 cmake -D CMAKE_BUILD_TYPE:String=Release .
124 make
125
126 # this only shows a summary of the results (how many of each type)
127 # details are left in Testing/<date>/DynamicAnalysis.xml
128 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
129 make memcheck
130
131 # Test asm path in constant time module - by default, it will test the plain C
132 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
133 msg "test: valgrind asm constant_time"
134 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
135 skip_all_except_given_suite test_suite_constant_time
136 cmake -D CMAKE_BUILD_TYPE:String=Release .
137 make clean
138 make
139 make memcheck
140}
141
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100142component_release_test_valgrind_constant_flow_psa () {
143 # This tests both (1) everything that valgrind's memcheck usually checks
144 # (heap buffer overflows, use of uninitialized memory, use-after-free,
145 # etc.) and (2) branches or memory access depending on secret values,
146 # which will be reported as uninitialized memory. To distinguish between
147 # secret and actually uninitialized:
148 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
149 # - or alternatively, build with debug info and manually run the offending
150 # test suite with valgrind --track-origins=yes, then check if the origin
151 # was TEST_CF_SECRET() or something else.
152 msg "build: cmake release GCC, full config with constant flow testing"
153 scripts/config.py full
154 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
155 skip_suites_without_constant_flow
156 cmake -D CMAKE_BUILD_TYPE:String=Release .
157 make
158
159 # this only shows a summary of the results (how many of each type)
160 # details are left in Testing/<date>/DynamicAnalysis.xml
161 msg "test: some suites (valgrind + constant flow)"
162 make memcheck
163}
164
Elena Uziunaitef0871be2024-07-02 15:52:03 +0100165component_release_test_valgrind_constant_flow_psa_no_asm () {
166 # This tests both (1) everything that valgrind's memcheck usually checks
167 # (heap buffer overflows, use of uninitialized memory, use-after-free,
168 # etc.) and (2) branches or memory access depending on secret values,
169 # which will be reported as uninitialized memory. To distinguish between
170 # secret and actually uninitialized:
171 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
172 # - or alternatively, build with debug info and manually run the offending
173 # test suite with valgrind --track-origins=yes, then check if the origin
174 # was TEST_CF_SECRET() or something else.
175 msg "build: cmake release GCC, full config minus MBEDTLS_HAVE_ASM with constant flow testing"
176 scripts/config.py full
177 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
178 scripts/config.py unset MBEDTLS_AESNI_C
179 scripts/config.py unset MBEDTLS_HAVE_ASM
180 skip_suites_without_constant_flow
181 cmake -D CMAKE_BUILD_TYPE:String=Release .
182 make
183
184 # this only shows a summary of the results (how many of each type)
185 # details are left in Testing/<date>/DynamicAnalysis.xml
186 msg "test: some suites (full minus MBEDTLS_HAVE_ASM, valgrind + constant flow)"
187 make memcheck
188}
189
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100190component_test_tsan () {
191 msg "build: TSan (clang)"
192 scripts/config.py full
193 scripts/config.py set MBEDTLS_THREADING_C
194 scripts/config.py set MBEDTLS_THREADING_PTHREAD
195 # Self-tests do not currently use multiple threads.
196 scripts/config.py unset MBEDTLS_SELF_TEST
197
198 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
199 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
200
201 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
202 make
203
204 msg "test: main suites (TSan)"
205 make test
206}
207
208component_test_memsan () {
209 msg "build: MSan (clang)" # ~ 1 min 20s
210 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Elena Uziunaite9af882d2024-07-02 10:52:13 +0100211 scripts/config.py unset MBEDTLS_HAVE_ASM
Minos Galanakis4a2a3512024-08-01 17:28:37 +0100212 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
213 make
214
215 msg "test: main suites (MSan)" # ~ 10s
216 make test
217
218 msg "test: metatests (MSan)"
219 tests/scripts/run-metatests.sh any msan
220
221 msg "program demos (MSan)" # ~20s
222 tests/scripts/run_demos.py
223
224 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
225 tests/ssl-opt.sh
226
227 # Optional part(s)
228
229 if [ "$MEMORY" -gt 0 ]; then
230 msg "test: compat.sh (MSan)" # ~ 6 min 20s
231 tests/compat.sh
232 fi
233}
234
235component_release_test_valgrind () {
236 msg "build: Release (clang)"
237 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
238 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
239 make
240
241 msg "test: main suites, Valgrind (default config)"
242 make memcheck
243
244 # Optional parts (slow; currently broken on OS X because programs don't
245 # seem to receive signals under valgrind on OS X).
246 # These optional parts don't run on the CI.
247 if [ "$MEMORY" -gt 0 ]; then
248 msg "test: ssl-opt.sh --memcheck (default config)"
249 tests/ssl-opt.sh --memcheck
250 fi
251
252 if [ "$MEMORY" -gt 1 ]; then
253 msg "test: compat.sh --memcheck (default config)"
254 tests/compat.sh --memcheck
255 fi
256
257 if [ "$MEMORY" -gt 0 ]; then
258 msg "test: context-info.sh --memcheck (default config)"
259 tests/context-info.sh --memcheck
260 fi
261}
262
263component_release_test_valgrind_psa () {
264 msg "build: Release, full (clang)"
265 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
266 scripts/config.py full
267 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
268 make
269
270 msg "test: main suites, Valgrind (full config)"
271 make memcheck
272}