]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.21] runtime: clear g0 stack bounds in dropm
authorMichael Pratt <mpratt@google.com>
Wed, 25 Oct 2023 15:40:56 +0000 (11:40 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 10 Jan 2024 19:40:22 +0000 (19:40 +0000)
commit7e34c4308f1f48f3d817779797729c75b695f492
treed7d7704757a7f229f82b81977dcae4d52614427d
parent491c1e7e951bd6fc6ba37ef91be45ca14654eb05
[release-branch.go1.21] runtime: clear g0 stack bounds in dropm

After CL 527715, needm uses callbackUpdateSystemStack to set the stack
bounds for g0 on an M from the extra M list. Since
callbackUpdateSystemStack is also used for recursive cgocallback, it
does nothing if the stack is already in bounds.

Currently, the stack bounds in an extra M may contain stale bounds from
a previous thread that used this M and then returned it to the extra
list in dropm.

Typically a new thread will not have an overlapping stack with an old
thread, but because the old thread has exited there is a small chance
that the C memory allocator will allocate the new thread's stack
partially or fully overlapping with the old thread's stack.

If this occurs, then callbackUpdateSystemStack will not update the stack
bounds. If in addition, the overlap is partial such that SP on
cgocallback is close to the recorded stack lower bound, then Go may
quickly "overflow" the stack and crash with "morestack on g0".

Fix this by clearing the stack bounds in dropm, which ensures that
callbackUpdateSystemStack will unconditionally update the bounds in
needm.

For #62440.
Fixes #63209.

Change-Id: Ic9e2052c2090dd679ed716d1a23a86d66cbcada7
Reviewed-on: https://go-review.googlesource.com/c/go/+/537695
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Bypass: Michael Pratt <mpratt@google.com>
(cherry picked from commit 1af424c196584cd0b05e559c2740f046d1f32042)
Reviewed-on: https://go-review.googlesource.com/c/go/+/549495
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/runtime/proc.go
src/runtime/testdata/testprogcgo/stackswitch.c