fix(native): clamp module count#1770
Open
jpnurmi wants to merge 2 commits into
Open
Conversation
Clamp module_count from shared crash context before indexing the fixed module array while enriching frames and debug metadata.
4d90deb to
e020cd7
Compare
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.
Clamp module_count from shared crash context before indexing the fixed module array while enriching frames and debug metadata.
Unvalidated module_count from shared memory causes out-of-bounds array access
Details
In build_native_crash_event, ctx->module_count from shared memory crash context is used as a loop bound to index into ctx->modules[], a fixed-size array of SENTRY_CRASH_MAX_MODULES (512) elements. No validation ensures module_count <= 512 before the loop. The same unbounded iteration exists in enrich_frame_with_module_info at line 499. The crash context is shared memory filled by a crashing process's signal handler — memory corruption is precisely the scenario where this code runs. The developers recognized this risk and added a defensive bounds check in the minidump writer (sentry_minidump_macos.c:758-760 with comment 'Bounds check to prevent out-of-bounds access on corrupted crash context'), but did not apply the same protection to build_native_crash_event.
Location
src/backends/native/sentry_crash_daemon.c:2046
Impact
Crash daemon reads past fixed-size array from corrupted shared memory
Reproduction steps
Recommended fix
module_count must be clamped to SENTRY_CRASH_MAX_MODULES before use as a loop bound, matching the defensive check already present in the minidump writer.
Severity: MEDIUM
Status: Open
Category: Buffer overflow
Repository: getsentry/sentry-native
Branch: master