Repository navigation
Add ASan redzones between zone allocations - #1194
Open
0xalpharush wants to merge 1 commit into
Open
0xalpharush wants to merge 1 commit into
0xalpharush wants to merge 1 commit into
Conversation
The zone carves many objects out of one malloc()ed chunk, so an overflow from one zone-allocated object into its neighbour stays inside a live heap block and AddressSanitizer cannot see it. When building with ASan, follow every allocation with a poisoned redzone, keep chunks of the configured size poisoned until handed out, and re-poison on clear() and undo_allocate(). Oversized chunks are not pre-poisoned, so a huge allocation costs no shadow updates proportional to its size. Builds without ASan are unchanged. Define MSGPACK_ZONE_NO_ASAN_ANNOTATIONS to opt out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
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.
msgpack::zonecarves many objects out of onemalloc()ed chunk. An overflow from one zone-allocated object into its neighbour stays inside a live heap block, so AddressSanitizer stays silent. This is detector hardening, not a bug fix, and the technique isn't new: it's the manual allocator poisoning described in Trail of Bits' "Sanitize your C++ containers: ASan annotations step-by-step" (https://blog.trailofbits.com/2024/09/10/sanitize-your-c-containers-asan-annotations-step-by-step/). zstd'sZSTD_CWKSP_ASAN_REDZONE_SIZEis a similar precedent.__SANITIZE_ADDRESS__/__has_feature(address_sanitizer)). Non-ASan builds are unchanged; with-DNDEBUGthe objects are byte-identical (gcc/clang, C++03/11/17).-DMSGPACK_ZONE_NO_ASAN_ANNOTATIONSopts out, e.g. when instrumented and uninstrumented code share a zone. At runtime,ASAN_OPTIONS=allow_user_poisoning=0also disables it.MSGPACK_ZONE_ASAN_REDZONE_SIZE, default 16). Chunks of the configured size stay poisoned until handed out, andclear()/undo_allocate()re-poison. Oversized chunks aren't pre-poisoned, so one huge allocation costs nothing proportional to its size.cpp03_zone.hppand its.erbtemplate get the same change.test/zone.cpp: under ASan,allocate_no_alignchecks for the redzone instead of contiguity.Validation: unpacking
92 91 01 91 02and writing one element past the first inner array silently corrupts the neighbour on stock. With this patch it reportsuse-after-poison, and it is silent again with-DMSGPACK_ZONE_NO_ASAN_ANNOTATIONS. All tests pass under ASan (clang-18 C++11/17/20, gcc-13 C++17), with annotations on and off. The OSS-Fuzz public corpus plus about 46Munpack_pack_fuzzerexecutions show no reports. ASan overhead is about +14% time and +7% peak memory on a corpus unpack/pack/clone benchmark; non-ASan builds are unaffected.Scope: only overflows between separately allocated zone objects. Indexing inside a single allocation is not covered, nor are reads into the unused tail of an oversized chunk.
Companion PR for the C zone on
c_master: #1195.🤖 Generated with Claude Code