Compute the attribution pc with integer arithmetic - #835
Merged
Merged
Conversation
attributionPC() subtracted 1 from a char pointer. During an optimistic unwind the pc can be garbage read from a return-address slot; for 0 or 0x1 that offsets a pointer to or from null, which is undefined behavior and is reported by UBSan's pointer-overflow check from walkVM's native frame resolution. Do the subtraction on uintptr_t instead, where wrap-around is defined; the resulting address still matches no library and no FDE, so attribution is unchanged. Add a gtest that feeds 0 and 0x1 through attributionPC(), which aborts under the asan config's -fsanitize=pointer-overflow before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 of 3 tasks
Contributor
Contributor
CI Test ResultsRun: #37041712180 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-10-03 07:04:29 UTC |
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.
What does this PR do?:
Makes
attributionPC()subtract 1 from the return address withuintptr_tarithmetic instead ofconst char*arithmetic.Motivation:
During an optimistic unwind,
walkVMcan read garbage such as0or0x1from a return-address slot and hand it toresolveNativeFrameForWalkVM()→attributionPC(). Offsetting a pointer to or from null is undefined behavior, and UBSan'spointer-overflowcheck reports it:main(2026-09-30 onward):stackWalker.inline.h:64:65: runtime error: applying non-zero offset 18446744073709551615 to null pointer(pc == nullptr), about 30 reports per run.applying non-zero offset to non-null pointer 0x000000000001 produced null pointer(pc == 0x1), from both the wall-clock and CPU signal handlers.In the sanitized test config (
halt_on_error=0,log_path=/tmp/asan.log) these don't fail a test. Instead the test JVM exits with code 1 at shutdown, and the report only appears in theasan-logs-*artifact.Unsigned wrap-around is well defined, and the resulting address (
UINTPTR_MAXor0) still matches no library and no FDE, so attribution output is unchanged. This also covers the0x1case, which apc != nullptrguard does not.I checked the other address arithmetic added by the return-address attribution changes (#786, #813, #830, #831). The remaining sites already use integer arithmetic (
pc() -= 1onuintptr_t&,pc_offsetonuintptr_t) or operate on addresses already validated to lie inside a library (theDW_PC_OFFSETrecovered pc indwarfStep.inline.h), soattributionPC()is the only place that needed changing.How to test the change?:
New gtest
ReturnAddressAttributionCharacterizationTest.AttributionPcOfGarbageNearNullIsDefinedfeeds0and0x1throughattributionPC().gtestAsan_returnAddressAttribution_ut(glibc aarch64 container): aborts with the UBSan report without the fix and passes with it.gtestDebug_returnAddressAttribution_ut(macOS): passes.For Datadog employees:
🤖 Generated with Claude Code