fix(gosym): prevent 32-bit truncation panic in PCIndex - #5
Open
ladung wants to merge 1 commit into
Open
Conversation
Author
|
@def please help review |
Author
|
hello @def |
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.
Problem
PCIndex.FindIndexguards its lower bound against the full 64-bit address:but the search immediately after truncates it to 32 bits:
The two disagree for any address at or above 2^32, and the outcome depends on the low 32 bits:
i32[0]— the guard passes,BinarySearchreturns(0, false),i--makes it-1, andit.i32[i]panics withruntime error: index out of range [-1]FindIndexreturns it, so the profiler silently attributes samples to the wrong symbolObserved in production as a crash-looping
coroot-node-agent1.35.4 DaemonSet pod:The
i64branch is unaffected — it performs no truncation.Fix
An address above
MaxUint32cannot be covered by a 32-bit index in the first place:Set()only stores intoi32when the value fits in 32 bits, promoting toi64otherwise. So-1is the correct answer here, and callers already expect it —elf.SymbolTable.Resolvechecksif i == -1 { return "" }(symbol_table.go:126).Guarding only the negative index (
if i < 0 { return -1 }before the load) would stop the crash but leave the silent-wrong-symbol case intact. Fixing the comparison closes both, and silent wrong data is the worse of the two failures.Tests
Four tests in
pcindex_panic_test.go:TestFindIndexTruncationPanicindex out of range [-1]panicTestFindIndexTruncationWrongSymboli < 0guard is insufficientTestFindIndexBelowFirstStillReturnsMinusOneTestFindIndexNormalLookupsUnaffectedThe first two fail on
main— the first by panicking, the second by returning0instead of-1. All four pass with the fix, and the rest of thegosympackage is unaffected.Note: merging this does not ship the fix.
coroot-node-agentpins this module by pseudo-version (go.mod:220→v0.0.0-20260804213318-758a0e72af3a, the buggy commit), so itsreplaceneeds bumping and a release cut afterwards. Until then the only workaround isnodeAgent.ebpfProfiler.enabled: false, which is the sole path in node-agent that reachesFindIndex.