feat: add a leanchecker-paranoid binary with mimalloc mitigations - #14884
Open
Kha wants to merge 1 commit into
Open
feat: add a leanchecker-paranoid binary with mimalloc mitigations#14884Kha wants to merge 1 commit into
leanchecker-paranoid binary with mimalloc mitigations#14884Kha wants to merge 1 commit into
Conversation
This PR adds `leanchecker-paranoid`, a variant of `leanchecker` whose allocator is built with mimalloc's memory-safety mitigations at `MI_SECURE=3`. It is not built by default; release CI builds it explicitly so it ships alongside the ordinary binary, which is unaffected. Level 3 enables encoded free lists and the padding they imply. Encoding is the part that matters for Lean: `lean_object.m_rc` sits at offset 0, exactly where mimalloc keeps a freed block's free-list link, so a reference-count operation through a stale pointer writes into allocator metadata rather than into dead payload. Over 40 runs of a probe modelling that, level 3 eliminates uncontrolled crashes entirely and converts them into a checked abort raised before a bad block is handed out. Padding additionally catches out-of-bounds constructor and array writes. The cost is roughly +26% wall and +17.5% of the live heap, paid by no other binary. The binary has to be linked statically: `leanshared` owns the allocator of every dynamically linked binary and is linked `-Bsymbolic`, so its internal `mi_*` calls cannot be redirected from an executable. Only mimalloc's own translation unit depends on `MI_SECURE`, so `add_mimalloc_variant` compiles it once per (mitigation level, TLS model) the build needs and each runtime archive consumes the matching object. Those flags cannot live on the shared source instead, because source properties are directory-scoped and CMake emits them after target options, so a per-target override would silently lose. `-rdynamic` is dropped here through the new `CMAKE_DYN_EXE_LINKER_FLAGS`, which collects the flags only dynamically linked binaries want; it exists for the interpreter, and on a static binary it defeats `--gc-sections` and inflates the symbol tables. With it gone and the binary stripped, the result is 78 MB on disk and about 19 MiB compressed. Finally, the hardened mimalloc wins only because its archive precedes `-lleanrt`. A disturbed order would link successfully with no mitigations and no diagnostic, so the link rule asserts the property on the finished binary and fails the build if it is missing.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
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.
This PR adds
bin/leanchecker-paranoid, a variant ofleancheckerbuilt with allocator hardening.leanchecker-paranoidis built with mimalloc's memory-safety mitigations atMI_SECURE=3. Level 3 enables encoded free lists and the padding they imply. Encoding is the part that matters for Lean:lean_object.m_rcsits at offset 0, exactly where mimalloc keeps a freed block's free-list link, so a reference-count operation through a stale pointer writes into allocator metadata rather than into dead payload. Over 40 runs of a probe modelling that, level 3 eliminates uncontrolled crashes entirely and converts them into a checked abort raised before a bad block is handed out. Padding additionally catches out-of-bounds constructor and array writes. The cost is roughly +26% wall-clock and +17.5% heap size.The binary is not exposed by
elan; instead, it will be directly integrated into upcoming checker workflows.