chore(cli): build mimalloc in secure mode - #1356
Merged
Merged
Conversation
Moving off musl's mallocng lost a diagnostic property: mallocng validates
a check byte on every allocation, so heap corruption aborted the process
by itself. That is what produced the a_crash/enframe abort we used to
identify the intermittent lint segfault as heap corruption. A default
mimalloc build performs no equivalent check, so the same corruption would
now pass unnoticed and surface later as an unrelated failure.
Build mimalloc with its secure feature (MI_SECURE=4): guard pages around
metadata, encoded free lists, randomized placement, and double-free
detection. Verified the detectors are present in the musl release binary
("corrupted free list entry", "double free detected", "corrupted
meta-data in thread-free list").
Detection is silent unless mimalloc is told to report: show_errors and
abort_on_error are read from the environment at process start, so a run
that wants the diagnostic must be launched with MIMALLOC_SHOW_ERRORS=1
MIMALLOC_ABORT_ON_ERROR=1. Documented on the allocator item; setting them
from inside main does not work, as mimalloc reads its options before main
runs.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 676b4683ac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
✨ Aspect Workflows Tasks📅 Wed Jul 29 02:24:53 UTC 2026 🔄 1 in progress task
❌ 1 failed task
|
mimalloc has no abort_on_error option — the earlier instruction to set MIMALLOC_ABORT_ON_ERROR was wrong and would have been silently ignored. mimalloc's default handler aborts only on EFAULT (corrupted metadata, corrupted thread-free list, and under the secure build a detected buffer overflow); a double free (EAGAIN) or a free of an invalid pointer (EINVAL) is reported and then execution continues. Register an error handler that aborts on every corruption code, so a detection is fatal at the point it happens rather than letting a corrupted heap run on and fail somewhere unrelated. The SIGABRT is caught by the crash handler, which reports it with a resolvable address. Adds a double-free trigger to the internal crash-test hook and an end-to-end test asserting the allocator reports it and the process dies by SIGABRT — the case that was previously silent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Follow-up to #1355 (mimalloc). Builds mimalloc with its
securefeature and makes detected heap corruption fatal.Moving off musl's mallocng loses a diagnostic property we were relying on. mallocng validates a check byte on every allocation, so heap corruption aborted the process by itself — that is exactly what produced the
a_crash/enframeabort used to identify the intermittent lint segfault as heap corruption in the first place. A default mimalloc build performs no equivalent check, so the same corruption would now pass unnoticed and resurface later as an unrelated failure.Secure build.
MI_SECURE=4gives guard pages around metadata, encoded free lists, randomized placement, and double-free detection. Verified present in the builtx86_64-unknown-linux-muslrelease binary:corrupted free list entry of size %zub at %p,double free detected of block %p with size %zu, andcorrupted meta-data in thread-free list.Abort on detection. Detection alone is not enough: mimalloc's default handler aborts only on
EFAULT(corrupted metadata, corrupted thread-free list, and — undersecure— a detected buffer overflow), while a double free (EAGAIN) or a free of an invalid pointer (EINVAL) is reported and then execution continues. Continuing on a corrupted heap is what makes this class of bug so hard to trace: the eventual crash lands somewhere unrelated, long after the write that caused it. This registers an error handler viami_register_errorthat aborts on every corruption code, so a detection is fatal where it happens. The SIGABRT is caught by the crash handler, which reports it with a resolvable address.Setting
MIMALLOC_SHOW_ERRORS=1on a diagnostic run additionally prints the message saying what was detected (show_errorsdefaults off in a release build). The abort happens either way.Changes are visible to end-users: yes
Searched for relevant documentation and updated as needed: no (behavior is documented on the allocator item in
main.rs)Breaking change (forces users to change their own code or config): no
Suggested release notes appear below: yes
chore: the allocator is now built in secure mode and aborts when it detects heap corruption (a smashed free list, a double free, corrupted metadata) rather than continuing on a corrupted heap. Set
MIMALLOC_SHOW_ERRORS=1to also print what was detected.Test plan
double free detected) and the process dies by SIGABRT with a crash report — the path that was previously silent.x86_64-unknown-linux-muslrelease target builds via--config=release;mi_register_errorand all three secure detectors are linked into the binary, and it runs normally (aspect --version).Note on cost
MI_SECURE=4adds guard pages and free-list encoding, which is not free. If the perf hit is material we can land this as a diagnostic-only release and revert, the same way #1352 was scoped.