Skip to content

Commit 151e0b8

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 71e75a2 commit 151e0b8

3 files changed

Lines changed: 714 additions & 1 deletion

File tree

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=

0 commit comments

Comments
 (0)