Skip to content

Commit f03a619

Browse files
committed
CBMC: Use instrumented malloc/free for MLD_ALLOC/MLD_FREE
The default implementation of MLD_ALLOC and MLD_FREE uses stack allocation, which the compiler can assume not to fail. This means that CBMC does not exercise the cleanup paths which handle fallible dynamic allocation -- a significant proof gap. This commit changes the configuration uses for the CBMC proofs to use the (instrumented) calls to malloc/free for MLD_ALLOC/MLD_FREE. Importantly, we set --malloc-may-fail to model allocation as fallible, and --malloc-fail-null to return NULL in case of allocation failure. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 64ae351 commit f03a619

File tree

10 files changed

+734
-3
lines changed

10 files changed

+734
-3
lines changed

BIBLIOGRAPHY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ source code and documentation.
3838
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
3939
- [mldsa/mldsa_native_config.h](mldsa/mldsa_native_config.h)
4040
- [mldsa/src/sign.c](mldsa/src/sign.c)
41+
- [proofs/cbmc/mldsa_native_config_cbmc.h](proofs/cbmc/mldsa_native_config_cbmc.h)
4142
- [test/break_pct_config.h](test/break_pct_config.h)
4243
- [test/custom_heap_alloc_config.h](test/custom_heap_alloc_config.h)
4344
- [test/custom_memcpy_config.h](test/custom_memcpy_config.h)
@@ -91,6 +92,7 @@ source code and documentation.
9192
- [mldsa/src/rounding.h](mldsa/src/rounding.h)
9293
- [mldsa/src/sign.c](mldsa/src/sign.c)
9394
- [mldsa/src/sign.h](mldsa/src/sign.h)
95+
- [proofs/cbmc/mldsa_native_config_cbmc.h](proofs/cbmc/mldsa_native_config_cbmc.h)
9496
- [test/break_pct_config.h](test/break_pct_config.h)
9597
- [test/custom_memcpy_config.h](test/custom_memcpy_config.h)
9698
- [test/custom_memset_config.h](test/custom_memset_config.h)

proofs/cbmc/H/H_harness.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ void mld_H(uint8_t *out, size_t outlen, const uint8_t *in1, size_t in1len,
99

1010
void harness(void)
1111
{
12+
{
13+
/* Dummy use of `free` to work around CBMC issue #8814. */
14+
free(NULL);
15+
}
16+
1217
uint8_t *out;
1318
size_t outlen;
1419
const uint8_t *in1;

proofs/cbmc/Makefile.common

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ endif
247247
# * an entire project when added to Makefile-project-defines
248248
# * a specific proof when added to the harness Makefile
249249

250-
CBMC_FLAG_MALLOC_MAY_FAIL ?= --malloc-fail-assert
250+
CBMC_FLAG_MALLOC_MAY_FAIL ?= --malloc-may-fail --malloc-fail-null # alloc may fail with returning NULL
251251
CBMC_FLAG_BOUNDS_CHECK ?= # set to --no-bounds-check to disable
252252
CBMC_FLAG_CONVERSION_CHECK ?= --conversion-check
253253
CBMC_FLAG_DIV_BY_ZERO_CHECK ?= # set to --no-div-by-zero-check to disable
@@ -555,6 +555,7 @@ ifndef MLD_CONFIG_PARAMETER_SET
555555
$(error MLD_CONFIG_PARAMETER_SET not set)
556556
endif
557557

558+
DEFINES += -DMLD_CONFIG_FILE="\"mldsa_native_config_cbmc.h\""
558559
DEFINES += -DMLD_CONFIG_PARAMETER_SET=$(MLD_CONFIG_PARAMETER_SET)
559560
# Give visibility to all static functions
560561
DEFINES += -Dstatic=

proofs/cbmc/check_pct/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ HARNESS_FILE = check_pct_harness
1010
# Litani dashboard. It can be human-readable and contain spaces if you wish.
1111
PROOF_UID = mld_check_pct
1212

13-
DEFINES += -DMLD_CONFIG_KEYGEN_PCT
13+
DEFINES +=
1414
INCLUDES +=
1515

1616
REMOVE_FUNCTION_BODY +=

proofs/cbmc/crypto_sign_signature_internal/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FUNCTION_NAME = crypto_sign_signature_internal
4646
# EXPENSIVE = true
4747

4848
# This function is large enough to need...
49-
CBMC_OBJECT_BITS = 8
49+
CBMC_OBJECT_BITS = 9
5050

5151
# If you require access to a file-local ("static") function or object to conduct
5252
# your proof, set the following (and do not include the original source file

0 commit comments

Comments
 (0)