golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.85k stars 17.51k forks source link

runtime: g0 stack.lo is sometimes too low #26061

Open aclements opened 6 years ago

aclements commented 6 years ago

In cgo mode for UNIX platforms, we compute the g0 stack bounds by querying the stack size from pthread_get_stacksize, subtracting that from the current SP in mstart, and adding a 1k buffer. However, on my Linux laptop, over 4k of the stack has already been consumed by the time we reach mstart, so the runtime sets the bottom of the g0 stack to be below the mapped memory. As a result, if we actually overflow the g0 stack, we get a segfault instead of a useful message with a traceback.

We should use pthread_get_stack instead to get both stack bounds.

Discovered when writing a test of overflowing the g0 stack for #21382, which I had assumed would pass on linux/amd64 but didn't.

gopherbot commented 6 years ago

Change https://golang.org/cl/120858 mentions this issue: runtime/cgo: use get pthread stack bounds instead of size

gopherbot commented 6 years ago

Change https://golang.org/cl/122577 mentions this issue: runtime: test g0 stack overflow handling on all OSes

odeke-em commented 4 years ago

Hello Austin, you submitted CL https://go-review.googlesource.com/c/go/+/120858/ please rebase from master and remove the unused variables. Thank you!

gopherbot commented 1 year ago

Change https://go.dev/cl/487355 mentions this issue: runtime: skip TestG0StackOverflow on ios