Repository navigation
Add ASan redzones between zone allocations (C) - #1195
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 msgpack_zone_clear(). 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]>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## c_master #1195 +/- ##
============================================
+ Coverage 57.47% 58.19% +0.72%
============================================
Files 10 10
Lines 1124 1141 +17
Branches 129 139 +10
============================================
+ Hits 646 664 +18
+ Misses 478 477 -1 🚀 New features to boost your workflow:
|
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 the unpacker's array/map element buffers out of onemalloc()ed chunk. An overflow from one 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 (manual allocator poisoning; see Trail of Bits, https://blog.trailofbits.com/2024/09/10/sanitize-your-c-containers-asan-annotations-step-by-step/).-DMSGPACK_ZONE_NO_ASAN_ANNOTATIONSopts out. Becausemsgpack_zone_malloc*are inline inzone.h, build the library and its users the same way.msgpack_zone_malloc/_no_alignplace each object on an 8-byte granule with a poisoned redzone after it. Chunks of the configured size are poisoned when created and re-poisoned bymsgpack_zone_clear(). Oversized chunks aren't pre-poisoned.msgpack_zone_malloc_expand()keeps its contract: the bytes it hands out are usable.Validation: unpacking
[[1],[2]]and writing one element past the first inner array is silent on stock and reportsuse-after-poisonwith the patch. All 6 tests pass under ASan with annotations on and off. The OSS-Fuzz public corpus plus about 16M executions of an unpack/pack harness show no reports. ASan overhead is about +4% time with unchanged peak memory on a corpus benchmark.Companion PR for the C++ zone on
cpp_master: #1194.🤖 Generated with Claude Code