CBMC: Use instrumented malloc/free for MLD_ALLOC/MLD_FREE#814
Draft
hanno-becker wants to merge 3 commits into
Draft
CBMC: Use instrumented malloc/free for MLD_ALLOC/MLD_FREE#814hanno-becker wants to merge 3 commits into
hanno-becker wants to merge 3 commits into
Conversation
hanno-becker
force-pushed
the
alloc_cbmc
branch
4 times, most recently
from
December 24, 2025 07:21
20a9d4e to
f03a619
Compare
mkannwischer
left a comment
Contributor
There was a problem hiding this comment.
Thanks @hanno-becker. The changes itself look good to me, but CBMC fails due to timeouts. Marking as draft until we can resolve that.
mkannwischer
marked this pull request as draft
December 29, 2025 02:40
hanno-becker
force-pushed
the
alloc_cbmc
branch
2 times, most recently
from
January 2, 2026 04:46
428a719 to
9ad59c8
Compare
Contributor
CBMC Results (ML-DSA-87)
Full Results (209 proofs)
|
Contributor
CBMC Results (ML-DSA-65)
Full Results (209 proofs)
|
Contributor
CBMC Results (ML-DSA-87, REDUCE-RAM)
Full Results (209 proofs)
|
Contributor
CBMC Results (ML-DSA-65, REDUCE-RAM)
Full Results (209 proofs)
|
Contributor
CBMC Results (ML-DSA-44)
Full Results (209 proofs)
|
Contributor
CBMC Results (ML-DSA-44, REDUCE-RAM)
Full Results (209 proofs)
|
Contributor
Author
|
This would be good to have for v1. Marking v1 so at least we're forced to make a deliberate decision about it. |
hanno-becker
force-pushed
the
alloc_cbmc
branch
3 times, most recently
from
July 16, 2026 11:06
baac927 to
ac4b3fc
Compare
Leaves CC set as "clang" for compilation and testing on macOS. Always use gcc for pre-processing with goto-cc to get consistent C header files on all platforms, including macOS/Darwin. Ported from mlkem-native (pq-code-package/mlkem-native#1780, commit b828ccdb28db111695837efdbb3a85338b5ef112). Signed-off-by: Rod Chapman <rodchap@amazon.com> Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
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>
With fallible malloc instrumentation, the sign_signature_internal proof at CBMC_OBJECT_BITS=9 became dramatically slower, timing out in CI for ML-DSA-65 with MLD_CONFIG_REDUCE_RAM (>1800s) and coming close to the timeout for ML-DSA-87 (1362s). Raising CBMC_OBJECT_BITS to 12 -- matching the other allocating top-level proofs such as mld_attempt_signature_generation and sign_pk_from_sk -- speeds the proof up by more than an order of magnitude. Local timings (Apple Silicon, z3): parameter set object-bits 9 object-bits 12 44 56s 50s 44 (REDUCE_RAM) n/a 12s 65 101s 87s 65 (REDUCE_RAM) 368s 17s 87 n/a 129s 87 (REDUCE_RAM) n/a 9s The object-bits setting determines how many bits of a pointer CBMC reserves for the object identifier. At 9 bits the pointer encoding is at capacity for this harness, forcing the SMT solver to reason about near-aliasing pointer encodings; at 12 bits object IDs are sparse and aliasing is cheaply refuted. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
Contributor
|
Quite a peformance hit, but probably tolerable at least temporarily. @hanno-becker, is this ready for review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.