Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aclements opened this issue Jun 26, 2018 · 4 comments
Open

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

aclements opened this issue Jun 26, 2018 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aclements
Copy link
Member

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.

@aclements aclements added this to the Go1.11 milestone Jun 26, 2018
@gopherbot
Copy link

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

@FiloSottile FiloSottile added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 26, 2018
@gopherbot
Copy link

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

@aclements aclements modified the milestones: Go1.11, Go1.12 Jul 24, 2018
@aclements aclements modified the milestones: Go1.12, Go1.13 Jan 8, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@odeke-em
Copy link
Member

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
Copy link

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

gopherbot pushed a commit that referenced this issue Apr 21, 2023
This test fails when run on ios. (Although ios does not normally
support "exec", in the corellium environment it does.)

For #26061.

Change-Id: Idfdc53758aaabf0cb87ae50f9a4666deebf57fd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/487355
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: Triage Backlog
Development

No branches or pull requests

6 participants