]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: add context to short stack panic
authorMichael Pratt <mpratt@google.com>
Tue, 1 Oct 2024 17:12:39 +0000 (13:12 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 1 Oct 2024 17:34:53 +0000 (17:34 +0000)
Over the years we've had various bugs in pprof stack handling resulting
in appendLocsForStack crashing because stk is too short for a cached
location. i.e., the cached location claims several inlined frames. Those
should always appear together in stk. If some frames are missing from
stk, appendLocsForStack.

If we find this case, replace the slice out of bounds panic with an
explicit panic that contains more context.

Change-Id: I52725a689baf42b8db627ce3e1bc6c654ef245d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/617135
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/pprof/proto.go

index 5214374bd9b087c4b6c272d3908de23d4eb5a9f6..b01f541375b1b26198d13245e9ecd462ad3efcb3 100644 (file)
@@ -404,6 +404,7 @@ func (b *profileBuilder) appendLocsForStack(locs []uint64, stk []uintptr) (newLo
        b.deck.reset()
 
        // The last frame might be truncated. Recover lost inline frames.
+       origStk := stk
        stk = runtime_expandFinalInlineFrame(stk)
 
        for len(stk) > 0 {
@@ -440,6 +441,9 @@ func (b *profileBuilder) appendLocsForStack(locs []uint64, stk []uintptr) (newLo
                        // Even if stk was truncated due to the stack depth
                        // limit, expandFinalInlineFrame above has already
                        // fixed the truncation, ensuring it is long enough.
+                       if len(l.pcs) > len(stk) {
+                               panic(fmt.Sprintf("stack too short to match cached location; stk = %#x, l.pcs = %#x, original stk = %#x", stk, l.pcs, origStk))
+                       }
                        stk = stk[len(l.pcs):]
                        continue
                }